solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long n, l, x, y, i; cin >> n >> l >> x >> y; long long f1 = 0, f2 = 0; map<long long, long long> mp; vector<long long> v; for (i = 0; i < n; i++) { long long temp; cin >> temp; if (mp.find(temp - x) != mp.end()) f1 = 1; if (mp.find(temp - y) != mp.end()) f2 = 1; mp[temp] = 1; v.push_back(temp); } if (f1 == 1 and f2 == 1) cout << 0; else if (f1 == 1 and f2 == 0) { cout << 1 << '\n'; cout << y; } else if (f1 == 0 and f2 == 1) { cout << 1 << '\n'; cout << x; } else { for (i = 0; i < n; i++) { long long p = v[i] + max(x, y); if (mp.find(p - min(x, y)) != mp.end() and p <= l) { cout << 1 << '\n' << p; return 0; } if (mp.find(p + min(x, y)) != mp.end() and p <= l) { cout << 1 << '\n' << p; return 0; } } for (i = n - 1; i >= 0; i--) { long long p = v[i] - max(x, y); if (mp.find(p + min(x, y)) != mp.end() and p >= 0) { cout << 1 << '\n' << p; return 0; } if (mp.find(p - min(x, y)) != mp.end() and p >= 0) { cout << 1 << '\n' << p; return 0; } } cout << 2 << '\n' << x << " " << y; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[100005], n, l, x, y, p, q; int bse(int a[], int l, int r, int k) { if (l == r && a[l] != k) return 0; int t = a[(l + r) / 2]; if (t == k) return (l + r) / 2; else if (t < k) return bse(a, (l + r) / 2 + 1, r, k); else return bse(a, l, (l + r) / 2, k); } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); p = 0; q = 0; for (int i = 1; i <= n; i++) if (bse(a, 1, n, x + a[i])) { p++; break; } for (int i = 1; i <= n; i++) if (bse(a, 1, n, y + a[i])) { q++; break; } if (p && q) { printf("0\n"); return 0; } for (int i = 1; i <= n; i++) if (bse(a, 1, n, x - y + a[i]) && x + a[i] <= l) { printf("1\n%d\n", x + a[i]); return 0; } for (int i = 1; i <= n; i++) if (bse(a, 1, n, a[i] + x + y) && a[i] + x <= l) { printf("1\n%d\n", x + a[i]); return 0; } for (int i = 1; i <= n; i++) if (bse(a, 1, n, a[i] - x - y) && a[i] - x >= 0) { printf("1\n%d\n", a[i] - x); return 0; } for (int i = 1; i <= n; i++) if (bse(a, 1, n, a[i] - x + y) && a[i] - x >= 0) { printf("1\n%d\n", a[i] - x); return 0; } if (p) printf("1\n%d\n", y); else if (q) printf("1\n%d\n", x); else { for (int i = 1; i <= n; i++) if (a[i] == x + y) { p = 1; break; } if (p) printf("1\n%d\n", x); else printf("2\n%d %d\n", x, y); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100000; int a[N]; int main() { int n, l, x, y; scanf("%d%d%d%d", &n, &l, &x, &y); set<int> as; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); as.insert(a[i]); } bool xReq = true; bool yReq = true; for (int i = 0; i < n; i++) { if (as.count(a[i] - x) || as.count(a[i] + x)) xReq = false; if (as.count(a[i] - y) || as.count(a[i] + y)) yReq = false; } if (!(xReq || yReq)) { printf("0\n"); return 0; } if (!xReq) { printf("1\n"); printf("%d\n", y); return 0; } if (!yReq) { printf("1\n"); printf("%d\n", x); return 0; } set<int> xs; bool done = false; for (int i = 0; i < n; i++) { if (a[i] - x >= 0) xs.insert(a[i] - x); if (a[i] + x <= l) xs.insert(a[i] + x); } for (int i = 0; i < n; i++) { if (xs.count(a[i] - y)) { printf("1\n%d\n", a[i] - y); return 0; } if (xs.count(a[i] + y)) { printf("1\n%d\n", a[i] + y); return 0; } } printf("2\n%d %d\n", x, y); }
8
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const long long INF = 1000000000000000000; const int N = 100005; int n, l, x, y; int a[N]; int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } int flag_x = 0; int flag_y = 0; for (int i = 0; i < n; ++i) { if (binary_search(a, a + n, a[i] + x)) flag_x = 1; if (binary_search(a, a + n, a[i] + y)) flag_y = 1; } if (flag_x == 1 && flag_y == 1) { cout << 0 << endl; cout << endl; } else if (flag_x == 1 || (x == y)) { cout << 1 << endl; cout << y << endl; } else if (flag_y == 1) { cout << 1 << endl; cout << x << endl; } else { for (int i = 0; i < n; ++i) { if (binary_search(a, a + n, a[i] + x + y)) { cout << 1 << endl; cout << a[i] + x << endl; return 0; } if (binary_search(a, a + n, a[i] + abs(x - y))) { if (a[i] + max(x, y) <= l) { cout << 1 << endl; cout << a[i] + max(x, y) << endl; return 0; } if (a[i] - min(x, y) >= 0) { cout << 1 << endl; cout << a[i] - min(x, y) << endl; return 0; } } } cout << 2 << endl; cout << x << " " << y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> const int MAX = 1e5 + 11; using namespace std; int N, L, X, Y, A[MAX]; set<int> all; static bool can(int v) { for (int i = 0; i < (N); ++i) { if (all.count(v + A[i])) { return true; } } return all.count(v) > 0; } int main() { scanf("%d%d%d%d", &(N), &(L), &(X), &(Y)); for (int i = 0; i < (N); ++i) { scanf("%d", &(A[i])); all.insert(A[i]); } if (can(X) && can(Y)) { printf("0"); return 0; } if (can(X)) { printf("1\n%d", Y); return 0; } if (can(Y)) { printf("1\n%d", X); return 0; } set<int> xx, yy; for (int i = 0; i < (N); ++i) { if (X + A[i] < L) xx.insert(X + A[i]); if (Y + A[i] < L) yy.insert(Y + A[i]); } for (auto u : xx) { if (yy.count(u)) { printf("1\n%d", u); return 0; } } xx = set<int>(), yy = set<int>(); for (int i = 0; i < (N); ++i) { if (A[i] - X >= 0) xx.insert(A[i] - X); if (A[i] - Y >= 0) yy.insert(A[i] - Y); } for (auto u : xx) { if (yy.count(u)) { printf("1\n%d", u); return 0; } } xx = set<int>(), yy = set<int>(); for (int i = 0; i < (N); ++i) { if (A[i] - X >= 0) xx.insert(A[i] - X); if (A[i] + Y >= 0) yy.insert(A[i] + Y); } for (auto u : xx) { if (yy.count(u)) { printf("1\n%d", u); return 0; } } xx = set<int>(), yy = set<int>(); for (int i = 0; i < (N); ++i) { if (A[i] + X >= 0) xx.insert(A[i] + X); if (A[i] - Y >= 0) yy.insert(A[i] - Y); } for (auto u : xx) { if (yy.count(u)) { printf("1\n%d", u); return 0; } } A[N++] = X; if (can(Y)) { printf("1\n%d", X); return 0; } A[N - 1] = Y; if (can(X)) { printf("1%d\n", Y); return 0; } printf("2\n%d %d", X, Y); return 0; }
8
CPP
from collections import defaultdict class LongJumps(): def __init__(self, n, l, x, y, a): self.n, self.l, self.x, self.y, self.a = n,l,x,y,a def get_markers(self): st = defaultdict(set) req_pts = [self.x,self.y] exist_check = defaultdict(bool) value_check = defaultdict(bool) for v in self.a: exist_check[v] = True for v in self.a: for i in range(len(req_pts)): if v - req_pts[i] >= 0: st[v - req_pts[i]].add(i) if exist_check[v - req_pts[i]]: value_check[i] = True if v + req_pts[i] <= l: st[v+req_pts[i]].add(i) if exist_check[v + req_pts[i]]: value_check[i] = True if value_check[0] and value_check[1]: print(0) return sol_status = 2 status1_marker = None for v in st: if len(st[v]) == 2: sol_status = 1 status1_marker = v elif len(st[v]) == 1: if exist_check[v]: sol_status = 1 status1_marker = req_pts[1-st[v].pop()] if sol_status == 1: print(1) print(status1_marker) return else: print(2) print(x, y) n, l, x, y = list(map(int,input().strip(' ').split(' '))) a = list(map(int,input().strip(' ').split(' '))) lj = LongJumps(n,l,x,y,a) lj.get_markers()
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1000000; bool can[2]; int a[N]; int main() { ios::sync_with_stdio(false); int n, x, y, l; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; } set<int> q; for (int i = 0; i < n; i++) { q.insert(a[i]); } for (int i = 0; i < n; i++) { if (q.find(-x + a[i]) != q.end()) can[0] = 1; if (q.find(-y + a[i]) != q.end()) can[1] = 1; } if (!can[0] && !can[1]) { for (int i = 0; i < n; i++) { if (q.find(a[i] - x - y) != q.end()) { cout << "1\n" << a[i] - x << "\n"; return 0; } if (q.find(a[i] + x - y) != q.end()) { if (0 <= a[i] + x && a[i] + x <= l) cout << "1\n" << a[i] + x << "\n"; else if (0 <= a[i] - y && a[i] - y <= l) cout << "1\n" << a[i] - y << "\n"; else continue; return 0; } } } vector<int> ans; if (!can[0]) ans.push_back(x); if (!can[1]) ans.push_back(y); cout << ans.size() << "\n"; while (ans.size()) { cout << ans.back() << " "; ans.pop_back(); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long a[100100], n, l, x, y; int main() { while (cin >> n >> l >> x >> y) { set<long long> st; for (int i = 1; i <= n; i++) { cin >> a[i]; st.insert(a[i]); } int flag1 = 0, flag2 = 0; for (int i = 1; i <= n; i++) { if (st.find(a[i] + x) != st.end()) flag1 = 1; if (st.find(a[i] + y) != st.end()) flag2 = 1; } if (flag1 && flag2) { puts("0"); continue; } if (flag1 && flag2 == 0) { cout << 1 << endl; cout << y << endl; continue; } if (flag1 == 0 && flag2) { cout << 1 << endl; cout << x << endl; continue; } long long flag = -1; for (int i = 1; i <= n; i++) { long long p = a[i] + x; if (p <= l) { if (st.find(p + y) != st.end() || st.find(p - y) != st.end()) flag = p; } p = a[i] + y; if (p <= l) { if (st.find(p + x) != st.end() || st.find(p - x) != st.end()) flag = p; } p = a[i] - x; if (p >= 0) { if (st.find(p + y) != st.end() || st.find(p - y) != st.end()) flag = p; } p = a[i] - y; if (p >= 0) { if (st.find(p + x) != st.end() || st.find(p - x) != st.end()) flag = p; } } if (flag != -1) { cout << 1 << endl; cout << flag << endl; continue; } cout << 2 << endl; cout << x << " " << y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y; int d[101000]; int girl, boy; int fin(int x) { int low = 0, high = n - 1; while (low < high) { int mid = (low + high) / 2; if (d[mid] == x) { low = high = mid; } else if (d[mid] < x) { low = mid + 1; } else { high = mid - 1; } } if (d[low] == x) return 1; return 0; } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; ++i) scanf("%d", d + i); for (int i = 0; i < n; ++i) { if (fin(d[i] + x)) girl = 1; if (fin(d[i] + y)) boy = 1; } if (girl && boy) { printf("0\n"); return 0; } if (girl) { printf("%d\n%d\n", 1, y); return 0; } if (boy) { printf("%d\n%d\n", 1, x); return 0; } for (int i = 0; i < n; ++i) { if (fin(d[i] + x + y)) { printf("1\n"); printf("%d\n", d[i] + x); return 0; } } for (int i = 0; i < n; ++i) { if (fin(d[i] + y - x)) { if (d[i] >= x) { printf("1\n"); printf("%d\n", d[i] - x); return 0; } if (d[i] + y <= l) { printf("1\n"); printf("%d\n", d[i] + y); return 0; } } } printf("2\n"); printf("%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 100; set<int> st; set<int>::iterator it; int main() { int n, l, x, y; st.clear(); cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { int k; scanf("%d", &k); st.insert(k); } bool ax = false, ay = false; for (it = st.begin(); it != st.end(); it++) { int tmp = *it; if (st.find(tmp + x) != st.end()) ax = true; if (st.find(tmp + y) != st.end()) ay = true; } int ans = 0, a[10]; if (ax == false) a[ans++] = x; if (ay == false) a[ans++] = y; if (ans == 2) { for (it = st.begin(); it != st.end(); it++) { if (st.find(*it + x + y) != st.end()) { ans = 1; a[0] = *it + x; break; } if (st.find(*it + y - x) != st.end()) { int tmp = 0; if (*it + y < l) tmp = *it + y; if (*it - x > 0) tmp = *it - x; if (!tmp) continue; ans = 1; a[0] = tmp; break; } } } printf("%d\n", ans); ; for (int i = 0; i < ans; i++) { if (i) printf(" "); printf("%d", a[i]); } if (ans) printf("\n"); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<int> v; int n, l, x, y; bool f(int x) { for (int i = 0; i < n - 1; i++) { if (binary_search(v.begin(), v.end(), v[i] + x)) { return true; } } return false; } int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { int w; scanf("%d", &w); v.push_back(w); } sort(v.begin(), v.end()); if (f(x)) { if (f(y)) { printf("0\n"); } else { printf("1\n%d\n", y); } return 0; } if (f(y)) { printf("1\n%d\n", x); return 0; } for (int i = 0; i < n; i++) { if (v[i] + x > l) { continue; } if (binary_search(v.begin(), v.end(), v[i] + x + y)) { printf("1\n%d\n", v[i] + x); return 0; } if (binary_search(v.begin(), v.end(), v[i] + x - y)) { printf("1\n%d\n", v[i] + x); return 0; } } for (int i = 0; i < n; i++) { if (v[i] - x < 0) { continue; } if (binary_search(v.begin(), v.end(), v[i] - x + y)) { printf("1\n%d\n", v[i] - x); return 0; } if (binary_search(v.begin(), v.end(), v[i] - x - y)) { printf("1\n%d\n", v[i] - x); return 0; } } printf("2\n%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 123456; int n, l, x, y, ai[maxn]; void init() { for (int i = 1; i <= n; i++) scanf("%d", &ai[i]); } int brs(int l, int r, int now, int t) { while (l <= r) { int mid = (l + r) / 2; if (now - ai[mid] == t) { return 1; } if (now - ai[mid] > t) { l = mid + 1; } else { r = mid - 1; } } return 0; } void DYGANDQYM() { int p1 = 0; int p2 = 0; for (int i = 2; i <= n; i++) { int t1 = brs(1, i - 1, ai[i], x); int t2 = brs(1, i - 1, ai[i], y); if (t1 == 1) { p1 = -1; } if (t2 == 1) { p2 = -1; } } if (p1 == -1 && p2 == -1) printf("0\n"); else if (p1 == -1) { printf("1\n"); printf("%d\n", l - y); } else if (p2 == -1) { printf("1\n"); printf("%d\n", l - x); } else { int idx = -1; for (int i = 2; i <= n; i++) { int t1 = brs(1, i - 1, ai[i], x + y); int t2 = brs(1, i - 1, ai[i], y - x); if (t1 == 1) { idx = i; break; } if (t2 == 1) { long long aa = ai[i]; if (aa - y >= 0 || aa + x <= l) { idx = i; break; } } } if (idx == -1) { printf("2\n"); printf("%d %d\n", l - x, l - y); } else { printf("1\n"); long long tt = ai[idx]; if (tt - y >= 0) { printf("%d\n", ai[idx] - y); } else { printf("%d\n", ai[idx] + x); } } } } int main() { while (scanf("%d%d%d%d", &n, &l, &x, &y) != EOF) { init(); DYGANDQYM(); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y, k[100010]; map<int, bool> bj; int main() { scanf("%d%d%d%d", &n, &l, &x, &y); int xx = 1, yy = 1, zz = -1; for (int i = 1; i <= n; i++) scanf("%d", &k[i]), bj[k[i]] = 1; for (int i = 1; i <= n; i++) { if (bj[k[i] + x]) xx = 0; if (bj[k[i] + y]) yy = 0; if (bj[k[i] + y - x]) if (k[i] + y <= l) zz = k[i] + y; if (bj[k[i] + x - y]) if (k[i] + x <= l) zz = k[i] + x; if (bj[k[i] - x + y]) if (k[i] - x >= 0) zz = k[i] - x; if (bj[k[i] - y + x]) if (k[i] - y >= 0) zz = k[i] - y; if (bj[k[i] + x + y] && !bj[k[i] + x] && !bj[k[i] + y]) if (k[i] + x + y <= l) zz = k[i] + x; if (bj[k[i] + x] && bj[k[i] - y]) xx = yy = 0; if (bj[k[i] - y] && bj[k[i] + x]) xx = yy = 0; } int ans = xx + yy; if (ans == 2) { if (zz != -1) printf("1\n%d", zz); else printf("2\n%d %d\n", x, y); } if (ans == 1) { if (yy) printf("1\n%d\n", y); else printf("1\n%d\n", x); } if (ans == 0) printf("0\n"); return 0; }
8
CPP
n, l, x, y = map(int, input().split()) a = set(map(int, input().split())) ok1 = ok2 = ok3 = False for c in a: if c + x in a: ok1 = True if c + y in a: ok2 = True if c - x > 0 and c - x + y in a: ok3 = True mark = c - x if c + x < l and c + x - y in a: ok3 = True mark = c + x if c + x + y in a: ok3 = True mark = c + x if c - x - y in a: ok3 = True mark = c - x if ok1 and ok2: print(0) elif (not ok1) and (not ok2): if ok3: print(1) print(mark) else: print(2) print(x, y) else: print(1) print(y if ok1 else x)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, l, x, y; scanf("%d %d %d %d", &n, &l, &x, &y); set<int> q; bool z1 = false; bool z2 = false; bool z3 = false; int num = 0; for (int i = 0; i < n; i++) { int x1; scanf("%d", &x1); q.insert(x1); if (q.find(x1 - x) != q.end()) z1 = true; if (q.find(x1 - y) != q.end()) z2 = true; if (q.find(x1 - y - x) != q.end()) { z3 = true; num = x1 - y; } if (q.find(x1 - (y - x)) != q.end()) { if (x1 + x <= l) { z3 = true; num = x1 + x; } if (x1 - y >= 0) { z3 = true; num = x1 - y; } } } if (z1 && z2) cout << "0"; if (z1 ^ z2) { cout << "1\n"; if (z1) cout << y; if (z2) cout << x; } if (!(z1 || z2)) { if (z3) { cout << "1\n"; cout << num; } else { cout << "2\n"; cout << x << " " << y; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<int> arr; set<int> spots; int main(int argc, char** argv) { int n, l, x, y; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { int xx; cin >> xx; arr.push_back(xx); spots.insert(xx); } bool canX = false; bool canY = false; for (int i = 0; i < n; i++) { int can1 = arr[i] + x; int can2 = arr[i] - x; int can3 = arr[i] + y; int can4 = arr[i] - y; if (spots.find(can1) != spots.end() || spots.find(can2) != spots.end()) { canX = true; } if (spots.find(can3) != spots.end() || spots.find(can4) != spots.end()) { canY = true; } } if (canX && canY) { cout << 0; return 0; } if (canX) { cout << 1 << endl; cout << y; return 0; } if (canY) { cout << 1 << endl; cout << x; return 0; } for (int i = 1; i < n - 1; i++) { int can1 = arr[i] - x; int can2 = arr[i] + x; int exp1 = can1 + y; int exp2 = can1 - y; int exp3 = can2 + y; int exp4 = can2 - y; if (can1 >= 0 && can1 <= l) { if (spots.find(exp1) != spots.end()) { cout << 1 << endl; cout << can1 << endl; return 0; } if (spots.find(exp2) != spots.end()) { cout << 1 << endl; cout << can1 << endl; return 0; } } if (can2 >= 0 && can2 <= l) { if (spots.find(exp3) != spots.end()) { cout << 1 << endl; cout << can2 << endl; return 0; } if (spots.find(exp4) != spots.end()) { cout << 1 << endl; cout << can2 << endl; return 0; } } } int can1 = arr[0] + x; int can2 = arr[n - 1] - x; int exp1 = can1 - y; int exp2 = can1 + y; int exp3 = can2 - y; int exp4 = can2 + y; if (can1 >= 0 && can1 <= l) { if (spots.find(exp1) != spots.end()) { cout << 1 << endl; cout << can1 << endl; return 0; } if (spots.find(exp2) != spots.end()) { cout << 1 << endl; cout << can1 << endl; return 0; } } if (can2 >= 0 && can2 <= l) { if (spots.find(exp3) != spots.end()) { cout << 1 << endl; cout << can2 << endl; return 0; } if (spots.find(exp4) != spots.end()) { cout << 1 << endl; cout << can2 << endl; return 0; } } cout << 2 << endl; cout << x << " " << y << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n = 2, l = 300, x = 185, y = 230; cin >> n >> l >> x >> y; vector<long long> in(n); set<int> total; for (int i = 0; i < n; i++) { cin >> in[i]; total.insert(in[i]); } set<long long> X; for (int i = 0; i < n; i++) { int right = in[i] + x; int left = in[i] - x; if (right <= l) X.insert(right); if (left >= 0) X.insert(left); if (total.count(left) || total.count(right)) { X.clear(); break; } } set<long long> Y; for (int i = 0; i < n; i++) { int right = in[i] + y; int left = in[i] - y; if (right <= l) { if (X.count(right)) { Y.clear(); X.clear(); Y.insert(right); break; } else { Y.clear(); Y.insert(right); } } if (left >= 0) { if (X.count(left)) { Y.clear(); X.clear(); Y.insert(left); break; } else { Y.clear(); Y.insert(left); } } if (total.count(left) || total.count(right)) { Y.clear(); break; } } int size = min(1, (int)Y.size()) + min(1, (int)X.size()); cout << min(2, size) << endl; for (long long i : Y) { cout << i << " "; break; } for (long long i : X) { cout << i << " "; break; } }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 100000; int ti1, ti2; int N; int L, L1, L2; int L0[MAX]; int DP_A(int temp) { int t0, t1; t0 = 0; t1 = N - 1; if (temp > L || temp < 0) return -1; else while (t0 <= t1) { int t; t = (t0 + t1) / 2; if (L0[t] == temp) return 1; else if (L0[t] < temp) { t0 = t + 1; } else if (L0[t] > temp) { t1 = t - 1; } } return -1; } int DP2() { int temp1, temp2; for (int i = 0; i < N; i++) { temp1 = L0[i] + L1; temp2 = L0[i] + L2; if (temp1 <= L && (DP_A(temp1 - L2) == 1 || DP_A(temp1 + L2) == 1)) { cout << 1 << '\n' << temp1 << endl; return 1; } if (temp2 <= L && (DP_A(temp2 - L1) == 1 || DP_A(temp2 + L1) == 1)) { cout << 1 << '\n' << temp2 << endl; return 1; } temp1 = L0[i] - L1; temp2 = L0[i] - L2; if (temp1 >= 0 && (DP_A(temp1 - L2) == 1 || DP_A(temp1 + L2) == 1)) { cout << 1 << '\n' << temp1 << endl; return 1; } if (temp2 >= L && (DP_A(temp2 - L1) == 1 || DP_A(temp2 + L1) == 1)) { cout << 1 << '\n' << temp2 << endl; return 1; } } cout << 2 << '\n' << L1 << ' ' << L2 << endl; } void DP() { int temp; for (int i = 0; i < N; i++) { temp = DP_A(L0[i] + L1); if (temp != -1) ti1 = temp; temp = DP_A(L0[i] + L2); if (temp != -1) ti2 = temp; temp = DP_A(L0[i] - L1); if (temp != -1) ti1 = temp; temp = DP_A(L0[i] - L2); if (temp != -1) ti2 = temp; } if (ti1 != -1 && ti2 != -1) cout << 0 << endl; else if (ti1 != -1) cout << 1 << '\n' << L2 << endl; else if (ti2 != -1) cout << 1 << '\n' << L1 << endl; else if (ti1 == -1 && ti2 == -1) DP2(); else cout << "出错" << endl; } int main() { ti1 = -1; ti2 = -1; cin >> N; cin >> L >> L1 >> L2; for (int i = 0; i < N; i++) cin >> L0[i]; sort(L0, L0 + N); DP(); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; set<long long> numbers; int main() { long long n, l, x, y; cin >> n >> l >> x >> y; for (int i = 0; i < n; ++i) { long long x; cin >> x; numbers.insert(x); } long long sub = y - x; bool find_x = false, find_y = false; int v = -1; for (auto d : numbers) { if (numbers.find(d + x) != numbers.end()) { find_x = true; } if (numbers.find(d + y) != numbers.end()) { find_y = true; } if (numbers.find(d + sub) != numbers.end()) { if (d - x >= 0) v = d - x; if (d + y <= l) v = d + y; } if (numbers.find(d + x + y) != numbers.end() && d + x <= l) { v = d + x; } } if (!find_x && !find_y) { if (v != -1) { cout << "1\n" << v; } else { cout << "2\n" << x << ' ' << y; } } else if (!find_x && find_y) { cout << "1\n" << x; } else if (find_x && !find_y) { cout << "1\n" << y; } else { cout << 0; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int NMax = 200000, INF = 1000000000; int N, L, X, Y, A[NMax]; int Binary(int first, int second, int a, int z) { int l = first, r = second + 1; while (l < r) { if (l + 1 == r) break; int mid = (l + r) / 2; if (A[mid] - a <= z) l = mid; else r = mid; } return l; } int main() { scanf("%d%d%d%d", &N, &L, &X, &Y); for (int i = 1; i <= N; i++) scanf("%d", A + i); int flag1 = 0, flag2 = 0; for (int i = 1; i < N; i++) { int first = Binary(i + 1, N, A[i], X), second = Binary(i + 1, N, A[i], Y); if (A[first] - A[i] == X) flag1 = 1; if (A[second] - A[i] == Y) flag2 = 1; } if (flag1 && flag2) { puts("0"); getchar(); getchar(); return 0; } if (flag1) { printf("1\n%d\n", Y); getchar(); getchar(); return 0; } if (flag2) { printf("1\n%d\n", X); getchar(); getchar(); return 0; } for (int i = 1; i <= N; i++) { if (i != 1) { if (A[i] > X) { int t = A[i] - X; int t1 = Binary(1, i - 1, t, 0); int first = Binary(1, t1, t, -Y); if (t - A[first] == Y) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } first = Binary(t1 + 1, N, t, Y); if (A[first] - t == Y) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } } if (A[i] > Y) { int t = A[i] - Y; int t1 = Binary(1, i - 1, t, 0); int first = Binary(1, t1, t, -X); if (t - A[first] == X) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } first = Binary(t1 + 1, N, t, X); if (A[first] - t == X) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } } } if (i != N) { if (A[i] + X < L) { int t = A[i] + X; int t1 = Binary(i, N, t, 0); int first = Binary(1, t1, t, -Y); if (t - A[first] == Y) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } first = Binary(t1 + 1, N, t, Y); if (A[first] - t == Y) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } } if (A[i] + Y < L) { int t = A[i] + Y; int t1 = Binary(i, N, t, 0); int first = Binary(1, t1, t, -X); if (t - A[first] == X) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } first = Binary(t1 + 1, N, t, X); if (A[first] - t == X) { printf("1\n%d\n", t); getchar(); getchar(); return 0; } } } } printf("2\n%d %d\n", X, Y); getchar(); getchar(); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9 + 7, N = 1e5 + 10; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); ll n, l, x, y; cin >> n >> l >> x >> y; vector<ll> A(n); for (auto &e : A) cin >> e; ll is_x = 0, is_y = 0; for (ll i = 0; i < n; i++) { is_x |= binary_search(A.begin(), A.end(), A[i] + x); is_y |= binary_search(A.begin(), A.end(), A[i] + y); } if (is_x & is_y) { return cout << 0, 0; } if (is_x) { cout << "1\n" << y << '\n'; return 0; } if (is_y) { cout << "1\n" << x << '\n'; return 0; } for (ll i = 0; i < n; i++) { if (A[i] + x <= l and (binary_search(A.begin(), A.end(), A[i] + x + y) or binary_search(A.begin(), A.end(), A[i] + x - y))) { return cout << "1\n" << A[i] + x, 0; 21; } if (A[i] - x >= 0 and (binary_search(A.begin(), A.end(), A[i] - x + y) or binary_search(A.begin(), A.end(), A[i] - x - y))) { return cout << "1\n" << A[i] - x, 0; 21; } swap(x, y); if (A[i] + x <= l and (binary_search(A.begin(), A.end(), A[i] + x + y) or binary_search(A.begin(), A.end(), A[i] + x - y))) { return cout << "1\n" << A[i] + x, 0; 21; } if (A[i] - x >= 0 and (binary_search(A.begin(), A.end(), A[i] - x + y) or binary_search(A.begin(), A.end(), A[i] - x - y))) { return cout << "1\n" << A[i] - x, 0; 21; } swap(x, y); } cout << "2\n" << x << ' ' << y << '\n'; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, m, x, y, i, j, num[100005]; pair<int, int> findfi(int x) { int l = 1, r = 1; for (r = 1; r <= n; r++) { while (num[l] + x < num[r] && l <= n) l++; if (num[l] + x == num[r]) return {num[l], num[r]}; } return {-1, -1}; } pair<int, int> findls(int x) { int l = n, r = n; for (l = n; l; l--) { while (num[l] + x < num[r] && r >= 1) r--; if (num[l] + x == num[r]) return {num[l], num[r]}; } return {-1, -1}; } bool in(long long x) { return (x > -1 && x <= m); } int main() { ios::sync_with_stdio(0); cin >> n >> m >> x >> y; for (i = 1; i <= n; i++) cin >> num[i]; if (findfi(x) != pair<int, int>{-1, -1}) { if (findfi(y) != pair<int, int>{-1, -1}) { cout << 0; return 0; } cout << 1 << endl << y; return 0; } if (findfi(y) != pair<int, int>{-1, -1}) { cout << 1 << endl << x; return 0; } if (findfi(x + y) != pair<int, int>{-1, -1}) { cout << 1 << endl << findfi(x + y).first + x; return 0; } if (findfi(y - x) != pair<int, int>{-1, -1} && findfi(y - x).first + y <= m) { cout << 1 << endl << findfi(y - x).first + y; return 0; } if (findls(y - x) != pair<int, int>{-1, -1} && findls(y - x).first - x >= 0) { cout << 1 << endl << findls(y - x).first - x; return 0; } cout << 2 << endl << x << ' ' << y; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100010; int64_t N, L, X, Y; int64_t A[MAX_N]; bool hasX = false, hasY = false; set<int64_t> S; void Input() { cin >> N >> L >> X >> Y; for (int i = 0; i < N; i++) cin >> A[i]; } void Precalc() { for (int i = 0; i < N; i++) { S.insert(A[i]); } for (int i = 0; i < N; i++) { if (S.count(X + A[i])) hasX = true; if (S.count(Y + A[i])) hasY = true; } } void Solve2() { bool ok = false; for (int i = 0; i < N; i++) { if (S.count(A[i] + X + Y)) { cout << 1 << endl; cout << A[i] + X << endl; ok = true; break; } if (S.count(A[i] - X - Y)) { cout << 1 << endl; cout << A[i] - X << endl; ok = true; break; } if (S.count(A[i] + Y - X)) { if (A[i] + Y <= L) { cout << 1 << endl; cout << A[i] + Y << endl; ok = true; break; } } if (S.count(A[i] - Y + X)) { if (A[i] - Y >= 0) { cout << 1 << endl; cout << A[i] - Y << endl; ok = true; break; } } } if (!ok) { cout << 2 << endl; cout << X << " " << Y << endl; } } void Solve() { Precalc(); if (hasX && hasY) { cout << 0 << endl; } else if (hasX) { cout << 1 << endl; cout << Y << endl; } else if (hasY) { cout << 1 << endl; cout << X << endl; } else { Solve2(); } } int main() { Input(); Solve(); return 0; }
8
CPP
n, l, x, y = map(int, input().split()) def f(t, q): i = j = 0 while j < n: d = t[j] - t[i] if d < q: j += 1 elif d > q: i += 1 else: return 0 return q def g(t): q = x + y i = j = 0 while j < n: d = t[j] - t[i] if d < q: j += 1 elif d > q: i += 1 else: return t[j] return 0 def h(t): q = y - x i = j = 0 while j < n: d = t[j] - t[i] if d < q: j += 1 elif d > q: i += 1 else: a, b = t[i] - x, t[j] + x if a >= 0: return [a] if b <= l:return [b] j += 1 return [x, y] def e(t): print(len(t)) print(' '.join(map(str, t))) t = list(map(int, input().split())) t.sort() x = f(t, x) y = f(t, y) if x and y: z = g(t) if z: e([z - y]) else: e(h(t)) elif x: e([x]) elif y: e([y]) else: e([])
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, l, x, y, a[100005]; bool xok, yok; pair<int, int> ff(int v) { int l = 0; for (int r = 0; r < n; r++) { while (a[l] + v < a[r]) l++; if (a[l] + v == a[r]) return make_pair(a[l], a[r]); } return make_pair(-1, -1); } pair<int, int> fl(int v) { int r = n - 1; for (int l = n - 1; l >= 0; l--) { while (a[l] + v < a[r]) r--; if (a[l] + v == a[r]) return make_pair(a[l], a[r]); } } int main() { ios::sync_with_stdio(false); cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) cin >> a[i]; if (ff(x) != make_pair(-1, -1)) xok = true; if (ff(y) != make_pair(-1, -1)) yok = true; if (xok && yok) { cout << 0; return 0; } else if (xok) { cout << 1 << endl << y; return 0; } else if (yok) { cout << 1 << endl << x; return 0; } else { pair<int, int> ss = ff(x + y); if (ss != make_pair(-1, -1)) { cout << 1 << endl << ss.first + x; return 0; } ss = ff(y - x); if (ss != make_pair(-1, -1) && ss.first + y <= l) { cout << 1 << endl << ss.first + y; return 0; } ss = fl(y - x); if (ss != make_pair(-1, -1) && ss.first - x >= 0) { cout << 1 << endl << ss.first - x; return 0; } cout << 2 << endl << x << ' ' << y << endl; return 0; } }
8
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int n, l, x, y; const int N = 101000; int p[N]; set<int> st; bool c1 = 0, c2 = 0; bool check0() { for (int i = 0; i < n; i++) { if (st.count(p[i] + x) || st.count(p[i] - x)) c1 = 1; if (st.count(p[i] + y) || st.count(p[i] - y)) c2 = 1; } return c1 && c2; } bool check(int c) { if (st.count(c) || c < 0 || c > l) return 0; if ((c1 || st.count(c + x) || st.count(c - x)) && (c2 || st.count(c + y) || st.count(c - y))) { puts("1"); printf("%d\n", c); return 1; } return 0; } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; i++) { scanf("%d", p + i); st.insert(p[i]); } if (check0()) { puts("0"); return 0; } for (int i = 0; i < n; i++) if (check(p[i] + x) || check(p[i] - x) || check(p[i] + y) || check(p[i] - y)) { return 0; } puts("2"); printf("%d %d\n", x, y); }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const double pi = 3.141592653589793; const int L_MAX = 1000000005; const int N_MAX = 100005; int ar[N_MAX]; int main(int argc, char const *argv[]) { int n, l, x, y; scanf("%d%d%d%d", &n, &l, &x, &y); int ai; map<int, int> dict; for (int i = 0; i < n; i++) { scanf("%d", &ar[i]); } for (int i = 0; i < n; i++) { if (!dict.count(ar[i])) dict[ar[i]] = 1; } bool fx = false, fy = false, dif = false, sm = false; int p; for (int i = 0; i < n; i++) { if (dict.count(ar[i] + x)) fx = true; if (dict.count(ar[i] + y)) fy = true; if (dict.count(ar[i] + y - x)) { if (ar[i] + y <= l) { dif = true; p = ar[i] + y; } else if (ar[i] - x >= 0) { dif = true; p = ar[i] - x; } } if (dict.count(ar[i] + (y + x))) { sm = true; p = ar[i] + y; } if (dict.count(ar[i] - (y + x))) { sm = true; p = ar[i] - x; } } if (fx && fy) cout << 0 << endl; else if (fx) { cout << 1 << endl; cout << ar[0] + y << endl; } else if (fy) { cout << 1 << endl; cout << ar[0] + x << endl; } else if (dif) { cout << 1 << endl; cout << p << endl; } else if (sm) { cout << 1 << endl; cout << p << endl; } else { cout << 2 << endl; cout << ar[0] + x << " " << ar[0] + y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; map<int, int> visit; int main() { int n, l, x, y, i; while (~scanf("%d%d%d%d", &n, &l, &x, &y)) { visit.clear(); int flag = 0; int ans = 0; int tans = 0; for (i = 1; i <= n; i++) { int tmp; scanf("%d", &tmp); visit[tmp] = 1; if (visit[tmp - x]) flag |= 1; if (visit[tmp - y]) flag |= 2; if (visit[tmp - (y - x)] && tmp + x <= l) ans |= 1, tans = tmp + x; if (visit[tmp - (y - x)] && tmp - y >= 0) ans |= 1, tans = tmp - y; if (visit[tmp - x - y]) ans |= 1, tans = tmp - x; } if (flag == 0) { if (ans) { printf("%d\n%d\n", 1, tans); } else { printf("%d\n%d %d\n", 2, x, y); } } else if (flag == 1) { printf("%d\n%d\n", 1, y); } else if (flag == 2) { printf("%d\n%d\n", 1, x); } else { printf("%d\n", 0); } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; bool findBinary(int, int*, int, int); int main() { int numberOfMarks, lengthI, distanceOfGirl, distanceOfBoy; int measure[100000]; int congNu[100000]; int truNu[100000]; int congNam[100000]; int truNam[100000]; bool girl = false, boy = false; cin >> numberOfMarks >> lengthI >> distanceOfGirl >> distanceOfBoy; for (int i = 0; i < numberOfMarks; i++) { cin >> measure[i]; int girlProcessedPlus = measure[i] + distanceOfGirl; int boyProcessedPlus = measure[i] + distanceOfBoy; int girlProcessedMinus = measure[i] - distanceOfGirl; int boyProcessedMinus = measure[i] - distanceOfBoy; congNu[i] = girlProcessedPlus; truNu[i] = girlProcessedMinus; congNam[i] = boyProcessedPlus; truNam[i] = boyProcessedMinus; } int flag = 0; girl = findBinary(distanceOfGirl, measure, numberOfMarks, lengthI); boy = findBinary(distanceOfBoy, measure, numberOfMarks, lengthI); if (boy && girl) { cout << "0" << endl; } else if (boy) { for (int i = 0; i < numberOfMarks; i++) { if (findBinary(congNu[i], measure, numberOfMarks, lengthI)) { girl = true; break; } } if (girl) { cout << "0" << endl; } else { cout << "1" << endl << distanceOfGirl; } } else if (girl) { for (int i = 0; i < numberOfMarks; i++) { if (findBinary(congNam[i], measure, numberOfMarks, lengthI)) { boy = true; break; } } if (boy) { cout << "0" << endl; } else { cout << "1" << endl << distanceOfBoy; } } else { for (int i = 0; i < numberOfMarks; i++) { if (findBinary(congNu[i], measure, numberOfMarks, lengthI)) { girl = true; break; } } for (int i = 0; i < numberOfMarks; i++) { if (findBinary(congNam[i], measure, numberOfMarks, lengthI)) { boy = true; break; } } if (boy && girl) { cout << "0" << endl; } else if (boy) { cout << "1" << endl << distanceOfGirl; } else if (girl) { cout << "1" << endl << distanceOfBoy; } else { for (int i = 0; i < numberOfMarks; i++) { if (findBinary(truNam[i], congNu, numberOfMarks, lengthI)) { flag = truNam[i]; break; } if (findBinary(truNam[i], truNu, numberOfMarks, lengthI)) { flag = truNam[i]; break; } if (findBinary(congNam[i], congNu, numberOfMarks, lengthI)) { flag = congNam[i]; break; } if (findBinary(congNam[i], truNu, numberOfMarks, lengthI)) { flag = congNam[i]; break; } } if (flag != 0) { cout << "1" << endl << flag; } else { cout << "2" << endl << distanceOfGirl << " " << distanceOfBoy; } } } return 0; } bool findBinary(int k, int array[], int size, int lengthI) { if (k >= 0 && k <= lengthI) { int begin = 0; int end = size - 1; int mid = (end - begin) / 2; while (begin <= end) { if (array[mid] == k && array[mid] >= 0 && array[mid] <= lengthI) { return true; } if (array[mid] > k) { end = mid - 1; mid = (begin + end) / 2; } else { begin = mid + 1; mid = (begin + end) / 2; } } } return false; }
8
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; long long msum(long long a, long long b, long long m) { return (a % m + b % m) % m; } long long msub(long long a, long long b, long long m) { return (a % m - b % m) % m; } long long mpro(long long a, long long b, long long m) { return ((a % m) * (b % m)) % m; } long long m_m(long long a, long long b, long long m); long long fxp(long long a, long long b, long long m); void swap(long long &a, long long &b) { long long t = a; a = b; b = t; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { long long n, l, x, y, i, j; cin >> n >> l >> x >> y; vector<long long> v; vector<long long> res; map<long long, long long> m; for (i = 0; i < n; i++) { long long tm; cin >> tm; v.push_back(tm); m[tm] = 1; } long long check_x = 0, check_y = 0, res1 = -1, res2 = -1; for (i = 0; i < n; i++) { if (m[v[i] + x]) check_x = 1; if (m[v[i] + y]) check_y = 1; if (m[v[i] + y + x] && res1 == -1) { res1 = v[i] + y; } if (m[v[i] + y - x] && res1 == -1) { if (v[i] + y <= l) res1 = v[i] + y; if (v[i] - x >= 0) res1 = v[i] - x; } } if (check_x && check_y) cout << 0; else if (check_x) cout << 1 << "\n" << y; else if (check_y) cout << 1 << "\n" << x; else if (res1 != -1) cout << 1 << "\n" << res1; else { cout << 2 << "\n"; cout << x << " " << y; } cout << "\n"; } return 0; } long long fxp(long long a, long long b, long long m) { if (b == 0) return 1; if (b % 2 == 0) return fxp(m_m(a, a, m), b / 2, m); return m_m(fxp(a, b - 1, m), a, m); } long long m_m(long long a, long long b, long long m) { long long res = 0; a = a % m; while (b) { if (b & 1) { res += a; res = res % m; } a = (a * 2) % m; b = b / 2; } return res; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, l, x, y; cin >> n >> l >> x >> y; set<int> d; for (int i = 0; i < n; ++i) { int t; cin >> t; d.insert(t); } bool issetX = false, issetY = false; for (set<int>::iterator i = d.begin(); i != d.end(); ++i) { if (d.find(*i + x) != d.end()) { issetX = true; } if (d.find(*i + y) != d.end()) { issetY = true; } } if (issetX && issetY) { cout << 0; return 0; } else if (issetX) { cout << "1 " << endl << y; } else if (issetY) { cout << "1 " << endl << x; } else { int point = -1; for (set<int>::iterator i = d.begin(); i != d.end(); ++i) { if (d.find(*i + (y - x)) != d.end()) { if (*i - x >= 0) { point = *i - x; break; } else if (*i + (y - x) + x <= l) { point = *i + (y - x) + x; break; } } if (d.find(*i + (y + x)) != d.end()) { point = *i + x; break; } } if (point < 0) { cout << "2 " << endl << x << " " << y; } else { cout << "1 " << endl << point; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; template <class T> inline T abS(T a) { return ((a >= 0) ? a : -a); } template <class T> inline T maX(T a, T b) { return ((a > b) ? a : b); } template <class T> inline T miN(T a, T b) { return ((a < b) ? a : b); } template <class T> inline void updmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void updmax(T &a, T b) { if (b > a) a = b; } int main() { int n, l, x, y; cin >> n >> l >> x >> y; set<int> S; for (int i = 0; i < n; i++) { int t; cin >> t; S.insert(t); } set<int>::iterator it = S.begin(); bool isx = 0, isy = 0; for (typeof(S.begin()) it = S.begin(); it != S.end(); it++) { int k = *it; if (k <= l - x) { if (S.count(k + x)) { isx = 1; break; } } } set<int>::iterator itt = S.begin(); for (typeof(S.begin()) it = S.begin(); it != S.end(); it++) { int k = *it; if (k <= l - y) { if (S.count(k + y)) { isy = 1; break; } } } if (isx && isy) { cout << 0; return 0; } if (isx) { cout << 1 << endl << y; return 0; } if (isy) { cout << 1 << endl << x; return 0; } int p = y - x; bool can = false; for (typeof(S.begin()) it = S.begin(); it != S.end(); it++) { int k = *it; if (k <= l - p) { if (S.count(k + p)) { if (k + p + x <= l) { cout << 1 << endl << k + p + x; return 0; } if (k - x >= 0) { cout << 1 << endl << k - x; return 0; } } } } p = x + y; for (typeof(S.begin()) it = S.begin(); it != S.end(); it++) { int k = *it; if (k <= l - p) { if (S.count(k + p)) { cout << 1 << endl << k + x; return 0; } } } cout << 2 << endl << x << " " << y; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; vector<int> vc; int L; bool doit(int x, int l) { if (x - l >= 0) { int low = *lower_bound(vc.begin(), vc.end(), x - l); if (low == x - l) { return true; } } if (x + l <= L) { int low = *lower_bound(vc.begin(), vc.end(), x + l); if (low == x + l) return true; } return false; } int main() { int n, l, x, y, i, a, flag1 = 0, flag2 = 0, ans = 2, coord = -1; scanf("%d", &n), scanf("%d", &l), scanf("%d", &x), scanf("%d", &y); L = l; for (i = (1); i <= (n); ++i) { scanf("%d", &a); vc.push_back(a); } for (i = (1); i <= (n); ++i) { a = vc[i - 1]; if (a >= x && flag1 == 0) { int low = *lower_bound(vc.begin(), vc.end(), a - x); flag1 = (low == a - x); } if (a >= y && flag2 == 0) { flag2 = ((*lower_bound(vc.begin(), vc.end(), a - y)) == a - y); } if (ans == 2) { if (a + x < l) if (doit(a + x, y)) { ans = 1, coord = a + x; continue; } if (a - x > 0) if (doit(a - x, y)) { ans = 1, coord = a - x; continue; } if (a + y < l) if (doit(a + y, x)) { ans = 1, coord = a + y; continue; } if (a - y > 0) if (doit(a - y, x)) { ans = 1, coord = a - y; continue; } } } if (flag1 == 1 && flag2 == 1) { cout << 0 << endl; } else if (ans == 1) { cout << 1 << endl << coord << endl; } else { cout << (flag1 == 0) + (flag2 == 0) << endl; if (flag1 == 0) cout << x << " "; if (flag2 == 0) cout << y; cout << endl; } }
8
CPP
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcountll(s); } const int bfsz = 1 << 16; char bf[bfsz + 5]; int rsz = 0; int ptr = 0; char gc() { if (rsz <= 0) { ptr = 0; rsz = (int)fread(bf, 1, bfsz, stdin); if (rsz <= 0) return EOF; } --rsz; return bf[ptr++]; } void ga(char &c) { c = EOF; while (!isalpha(c)) c = gc(); } int gs(char s[]) { int l = 0; char c = gc(); while (isspace(c)) c = gc(); while (c != EOF && !isspace(c)) { s[l++] = c; c = gc(); } s[l] = '\0'; return l; } template <class T> bool gi(T &v) { v = 0; char c = gc(); while (c != EOF && c != '-' && !isdigit(c)) c = gc(); if (c == EOF) return false; bool neg = c == '-'; if (neg) c = gc(); while (isdigit(c)) { v = v * 10 + c - '0'; c = gc(); } if (neg) v = -v; return true; } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } return a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int n, l, x, y, a[500005]; map<int, int> M; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> l >> x >> y; for (int i = (1); i <= (n); ++i) { cin >> a[i]; M[a[i]] = 1; } bool have0 = false, have1 = false; for (int i = (1); i <= (n); ++i) { int d = a[i] + x; if (d <= l && M[d]) have0 = true; d = a[i] + y; if (d <= l && M[d]) have1 = true; } if (have0 && have1) { cout << 0 << endl; return 0; } else if (have0) { cout << 1 << endl; cout << y << endl; } else if (have1) { cout << 1 << endl; cout << x << endl; } else { for (int i = (1); i <= (n); ++i) { int d = a[i] + x; if (d <= l && d >= 0 && (M[d + y] || M[d - y])) { cout << 1 << endl; cout << d << endl; return 0; } d = a[i] - x; if (d <= l && d >= 0 && (M[d + y] || M[d - y])) { cout << 1 << endl; cout << d << endl; return 0; } } cout << 2 << endl; cout << x << " " << y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int num[100010]; map<int, int> mymap; int main() { int n; int l; int x, y; scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; i++) { scanf("%d", &num[i]); mymap[num[i]] = 1; } if (mymap[x] == 1 && mymap[y] == 1) { printf("0"); } else { sort(num, num + n); bool flag1 = 0, flag2 = 0; for (int i = 0; i < n; i++) { if (num[i] + x > l) break; if (mymap[num[i] + x] == 1) { flag1 = 1; } if (mymap[num[i] + y] == 1) { flag2 = 1; } } if (flag1 && flag2) { cout << 0; } else if (flag1 && !flag2) { cout << 1 << endl; cout << y; } else if (!flag1 && flag2) { cout << 1 << endl; cout << x; } else { bool flag = 0; int ans1; for (int i = 0; i < n; i++) { if (num[i] + x + y <= l && mymap[num[i] + x + y] == 1) { if (num[i] + x <= l) { ans1 = x + num[i]; flag = 1; break; } } if (num[i] + x - y <= l && mymap[num[i] + x - y] == 1) { if (num[i] + x <= l) { ans1 = x + num[i]; flag = 1; break; } } if (num[i] - x + y <= l && mymap[num[i] - x + y] == 1) { if (num[i] - x >= 0) { ans1 = num[i] - x; flag = 1; break; } } if (num[i] - x - y <= l && mymap[num[i] - x - y] == 1) { ans1 = num[i] - x; flag = 1; break; } if (num[i] + y - x <= l && mymap[num[i] + y - x] == 1) { if (num[i] + y <= l) { ans1 = num[i] + y; flag = 1; break; } } if (num[i] - y + x <= l && mymap[num[i] - y + x] == 1) { if (num[i] - y >= 0) { ans1 = num[i] - y; flag = 1; break; } } } if (flag == 1) { cout << 1 << endl; cout << ans1; } else { cout << 2 << endl; cout << x << ' ' << y; } } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long nC2(long long a) { long long t = a; t *= t - 1; t /= 2; return t; } int arr[1000001]; int main() { long long n, l, x, y; bool fx = 0, fy = 0; int a = 2; cin >> n >> l >> x >> y; map<long long, int> make_pair; for (int i = 0; i < n; i++) { cin >> arr[i]; make_pair[arr[i]] = 1; } for (int i = 0; i < n && a; i++) { if (!fx) { if (make_pair[x + arr[i]] == 1 || make_pair[arr[i] - x] == 1) { fx = 1; a--; } } if (!fy) { if (make_pair[y + arr[i]] == 1 || make_pair[arr[i] - y] == 1) { fy = 1; a--; } } } if (a == 0) cout << a << endl; else { if (a == 1) { cout << a << endl; if (fx) cout << y << endl; else cout << x << endl; } else { bool nf = 1; long long X; for (int i = 0; i < n && nf; i++) { long long z = arr[i] + x; if (z >= 0 && z <= l) { if (make_pair[z + y] == 1 || make_pair[z - y] == 1) { nf = 0; X = z; break; } } z = arr[i] - x; if (z >= 0 && z <= l) { if (make_pair[z + y] == 1 || make_pair[z - y] == 1) { nf = 0; X = z; break; } } } if (nf == 0) { cout << 1 << endl; cout << X << endl; } else { cout << 2 << endl; cout << x << ' '; cout << y << endl; } } } cin >> n; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100010; inline int read() { int x(0), w(1); char c = getchar(); while (c ^ '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') w = -1, c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar(); return x * w; } int n, l, r, mid, x, y, a[N], ans[5]; inline int check(int len) { int l, r, mid; for (int i = 2; i <= n; ++i) { l = 1, r = i - 1; while (l <= r) { mid = (l + r) >> 1; if (a[i] - a[mid] > len) { l = mid + 1; } else if (a[i] - a[mid] < len) { r = mid - 1; } else if (a[i] - a[mid] == len) { return a[mid]; } } } return -1; } int main() { n = read(), l = read(), x = read(), y = read(); for (int i = 1; i <= n; ++i) { a[i] = read(); } ans[0] = check(x); ans[1] = check(y); ans[2] = check(x + y); ans[3] = check(y - x); if (ans[0] != -1 && ans[1] != -1) { printf("0\n"); return 0; } if (ans[0] != -1 && ans[1] == -1) { printf("1\n%d\n", y); return 0; } if (ans[0] == -1 && ans[1] != -1) { printf("1\n%d\n", x); return 0; } if (ans[2] != -1) { printf("1\n%d\n", ans[2] + x); return 0; } for (int i = 2; i <= n; ++i) { l = 1, r = i - 1; while (l <= r) { mid = (l + r) >> 1; if (a[i] - a[mid] > y - x) { l = mid + 1; } else if (a[i] - a[mid] < y - x) { r = mid - 1; } else if (a[i] - a[mid] == y - x) { if (a[mid] - x > 0) { printf("1\n%d\n", a[mid] - x); return 0; } if (a[mid] + y < a[n]) { printf("1\n%d\n", a[mid] + y); return 0; } break; } } } printf("2\n%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { while (b > 0) { a %= b; swap(a, b); } return a; } template <class _T> inline _T sqr(const _T& first) { return first * first; } template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; const double EPS = 1e-9; char TEMPORARY_CHAR; const int INF = 1e9; inline void input(int& a) { a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')) { } char neg = 0; if (TEMPORARY_CHAR == '-') { neg = 1; TEMPORARY_CHAR = getchar(); } while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') { a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar(); } if (neg) a = -a; } inline void out(long long a) { if (!a) putchar('0'); if (a < 0) { putchar('-'); a = -a; } char s[20]; int i; for (i = 0; a; ++i) { s[i] = '0' + a % 10; a /= 10; } for (int j = (i)-1; j >= 0; j--) putchar(s[j]); } inline int nxt() { int(ret); input((ret)); ; return ret; } int main() { srand(234134211); int(n); input((n)); ; int(l); input((l)); ; int(first); input((first)); ; int(second); input((second)); ; long long a[n]; for (int i = 0; i < n; ++i) { a[i] = nxt(); } int canX = -1; int canY = -1; int canXY = -1; int canA = -1; int canB = -1; for (int i = 0; i < n; ++i) { long long p = a[i] + first; if (binary_search(a, a + n, p)) { canX = i; } p = a[i] + second; if (binary_search(a, a + n, p)) { canY = i; } } if (canX != -1 && canY != -1) { cout << "0\n"; return 0; } if (canX != -1) { cout << "1\n"; cout << second << endl; return 0; } if (canY != -1) { cout << "1\n"; cout << first << endl; return 0; } for (int i = 0; i < n; ++i) { if (a[i] + first <= l && binary_search(a, a + n, a[i] + first + second)) { cout << "1\n"; cout << a[i] + first << "\n"; return 0; } if (a[i] + first <= l && binary_search(a, a + n, a[i] + first - second)) { cout << "1\n"; cout << a[i] + first << "\n"; return 0; } if (a[i] - first >= 0 && binary_search(a, a + n, a[i] - first + second)) { cout << "1\n"; cout << a[i] - first << "\n"; return 0; } if (a[i] - first >= 0 && binary_search(a, a + n, a[i] - first - second)) { cout << "1\n"; cout << a[i] - first << "\n"; return 0; } if (a[i] + second <= l && binary_search(a, a + n, a[i] + first + second)) { cout << "1\n"; cout << a[i] + second << "\n"; return 0; } if (a[i] + second <= l && binary_search(a, a + n, a[i] - first + second)) { cout << "1\n"; cout << a[i] + second << "\n"; return 0; } if (a[i] - second >= 0 && binary_search(a, a + n, a[i] - second + first)) { cout << "1\n"; cout << a[i] - second << "\n"; return 0; } if (a[i] - second >= 0 && binary_search(a, a + n, a[i] - second - first)) { cout << "1\n"; cout << a[i] - second << "\n"; return 0; } } cout << "2\n"; cout << first << " " << second << "\n"; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void YES(bool t = 1) { cout << YESNO[t] << endl; } void Yes(bool t = 1) { cout << YesNo[t] << endl; } void yes(bool t = 1) { cout << yesno[t] << endl; } template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); } template <class T> void scan(vector<T> &); template <class T> void scan(vector<T> &a) { for (auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } vector<int> iota(int n) { vector<int> a(n); iota(begin(a), end(a), 0); return a; } template <typename T> vector<int> iota(vector<T> &a, bool greater = false) { vector<int> res(a.size()); iota(begin(res), end(res), 0); sort(begin(res), end(res), [&](int i, int j) { if (greater) return a[i] > a[j]; return a[i] < a[j]; }); return res; } template <class T> T POW(T x, int n) { T res = 1; for (; n; n >>= 1, x *= x) if (n & 1) res *= x; return res; } vector<pair<long long, long long>> factor(long long x) { vector<pair<long long, long long>> ans; for (long long i = 2; i * i <= x; i++) if (x % i == 0) { ans.push_back({i, 1}); while ((x /= i) % i == 0) ans.back().second++; } if (x != 1) ans.push_back({x, 1}); return ans; } template <class T> vector<T> divisor(T x) { vector<T> ans; for (T i = 1; i * i <= x; i++) if (x % i == 0) { ans.push_back(i); if (i * i != x) ans.push_back(x / i); } return ans; } template <typename T> void zip(vector<T> &x) { vector<T> y = x; sort(begin(y), end(y)); for (int i = 0; i < x.size(); ++i) { x[i] = distance((y).begin(), lower_bound(begin(y), end(y), (x[i]))); } } int popcount(long long x) { return __builtin_popcountll(x); } int in() { int x; cin >> x; return x; } long long lin() { unsigned long long x; cin >> x; return x; } template <typename T> struct edge { int from, to; T cost; int id; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; using Tree = vector<vector<int>>; using Graph = vector<vector<int>>; template <class T> using Wgraph = vector<vector<edge<T>>>; Graph getG(int n, int m = -1, bool directed = false, int margin = 1) { Tree res(n); if (m == -1) m = n - 1; while (m--) { int a, b; cin >> a >> b; a -= margin, b -= margin; res[a].emplace_back(b); if (!directed) res[b].emplace_back(a); } return move(res); } template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) { Wgraph<T> res(n); if (m == -1) m = n - 1; while (m--) { int a, b; T c; cin >> a >> b >> c; a -= margin, b -= margin; res[a].emplace_back(b, c); if (!directed) res[b].emplace_back(a, c); } return move(res); } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto it = begin(v); it != end(v); ++it) { if (it == begin(v)) os << *it; else os << " " << *it; } return os; } template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) { os << p.first << " " << p.second; return os; } template <class S, class T> string to_string(pair<S, T> p) { return "(" + to_string(p.first) + "," + to_string(p.second) + ")"; } template <class A> string to_string(A v) { if (v.empty()) return "{}"; string ret = "{"; for (auto &x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } void dump() { cerr << endl; } template <class Head, class... Tail> void dump(Head head, Tail... tail) { cerr << to_string(head) << " "; dump(tail...); } template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); } } setup_io; int main() { int n, l, x, y; IN(n, l, x, y); set<int> s; for (long long i = 0; i < n; ++i) s.emplace(in()); int X = 0, Y = 0; for (auto &e : s) { if (s.count(e + x)) X = 1; if (s.count(e + y)) Y = 1; } if (X and Y) cout << "0" << '\n', exit(0); if (X) { cout << 1 << '\n' << y << '\n'; exit(0); } if (Y) { cout << 1 << '\n' << x << '\n'; exit(0); } for (auto &e : s) { if (s.count(e + x + y)) { cout << 1 << '\n' << e + x << '\n'; exit(0); } } for (auto &e : s) { if (s.count(e + y - x) and e + y < l) { cout << 1 << '\n' << e + y << '\n'; exit(0); } if (s.count(e - y + x) and e - y > 0) { cout << 1 << '\n' << e - y << '\n'; exit(0); } } cout << 2 << '\n' << x << " " << y << '\n'; }
8
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> inline T POW(T B, T P) { if (P == 0) return 1; if (P & 1) return B * POW(B, P - 1); else return SQR(POW(B, P / 2)); } template <typename T> inline T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m); return ((s % m) * (s % m)) % m; } return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; } template <typename T> inline T ModInv(T b, T m) { return BigMod(b, m - 2, m); } template <typename T> inline T ABS(T a) { if (a < 0) return -a; else return a; } template <typename T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b / gcd(a, b)); } long long int n, l, x, y, arr[100005]; int main() { scanf("%I64d%I64d", &n, &l); scanf("%I64d%I64d", &x, &y); long long int p; for (int i = 1; i <= n; i++) { scanf("%I64d", &arr[i]); if (x != -1) { p = (lower_bound(arr + 1, arr + 1 + i, arr[i] - x) - arr); if (arr[p] == arr[i] - x) { x = -1; } } if (y != -1) { p = (lower_bound(arr + 1, arr + 1 + i, arr[i] - y) - arr); if (arr[p] == arr[i] - y) { y = -1; } } } if (x == -1 && y == -1) { cout << 0 << endl; return 0; } if (x == -1 || y == -1) { if (x == -1) cout << 1 << endl << y << endl; else cout << 1 << endl << x << endl; return 0; } long long int xx, yy, ch = 0, ans; for (int i = 1; i <= n; i++) { xx = arr[i] + x; if (ch == 0 && xx <= l) { yy = xx + y; p = (lower_bound(arr + 1, arr + 1 + n, yy) - arr); if (arr[p] == yy) { ch = 1; ans = xx; } else { yy = xx - y; p = (lower_bound(arr + 1, arr + 1 + n, yy) - arr); if (arr[p] == yy) { ch = 1; ans = xx; } } } xx = arr[i] - x; if (ch == 0 && xx >= 0) { yy = xx + y; p = (lower_bound(arr + 1, arr + 1 + n, yy) - arr); if (arr[p] == yy) { ch = 1; ans = xx; } else { yy = xx - y; if (yy >= 0) { p = (lower_bound(arr + 1, arr + 1 + n, yy) - arr); if (arr[p] == yy) { ch = 1; ans = xx; } } } } } if (ch == 1) cout << 1 << endl << ans << endl; else { cout << 2 << endl << x << " " << y << endl; } return 0; }
8
CPP
n,l,x,y=map(int,input().split(" ")) li=list(map(int,input().split(" ",n)[:n])) li.sort() dic={} a1,a2=0,0 ans=2 x1=x y1=y xi=-1 yi=-1 for i in li: dic[i]=1 for i in range(n): if li[i]-x>=0: if li[i]-x in dic: a1=1 xi=i if li[i]+x<=l: if li[i]+x in dic: a1=1 xi=i if li[i]-y>=0: if li[i]-y in dic: a2=1 yi=i if li[i]+y<=l: if li[i]+y in dic: a2=1 yi=i if a1==1 and a2==1: print(0) elif a1==1: if li[xi]-x>=0: if li[xi]-x in dic: if li[xi]-x+y<=l and li[xi]-x+y in dic: a2=1 if li[xi]-x-y>=0 and li[xi]-x-y in dic: a2=1 if li[xi]+x<=l: if li[xi]+x in dic: if li[xi]+x+y<=l and li[xi]+x+y in dic: a2=1 if li[xi]+x-y>=0 and li[xi]+x-y in dic: a2=1 if a2==1: print(0) else: print(1) print(y) elif a2==1: if li[yi]-y>=0: if li[yi]-y in dic: if li[yi]-y+x<=l and li[yi]-y+x in dic: a1=1 if li[yi]-y-x>=0 and li[yi]-y-x in dic: a1=1 if li[yi]+y<=l: if li[yi]+x in dic: if li[yi]+y+x<=l and li[yi]+y+x in dic: a1=1 if li[yi]+y-x>=0 and li[yi]+y-x in dic: a1=1 if a1==1: print(0) else: print(1) print(x) else: for i in range(n): if li[i]-x>=0: a1=1 xi=i if li[xi]-x+y<=l and li[xi]-x+y in dic: a2=1 if li[xi]-x-y>=0 and li[xi]-x-y in dic: a2=1 if a2==1: print(1) print(li[i]-x) break else: a1=0 if li[i]+x<=l: a1=1 xi=i if li[xi]+x+y<=l and li[xi]+x+y in dic: a2=1 if li[xi]+x-y>=0 and li[xi]+x-y in dic: a2=1 if a2==1: print(1) print(li[i]+x) break else: a1=0 if li[i]-y>=0: a2=1 yi=i if li[yi]-y+x<=l and li[yi]-y+x in dic: a1=1 if li[yi]-y-x>=0 and li[yi]-y-x in dic: a1=1 if a1==1: print(1) print(li[i]-y) break else: a2=0 if li[i]+y<=l: a2=1 yi=i if li[yi]+y+x<=l and li[yi]+y+x in dic: a1=1 if li[yi]+y-x>=0 and li[yi]+y-x in dic: a1=1 if a1==1: print(1) print(li[i]+y) break else: a2=0 if a1==0 and a2==0: print(2) print(x,y)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> pnt; int main() { ios_base::sync_with_stdio(0); ; int n, l, x, y, p; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> p; pnt.push_back(p); } int ok1 = 0; for (int i = 0; i < n && !ok1; i++) { int lo = i + 1; int hi = n - 1; int mid; while (lo <= hi) { mid = (lo + hi) >> 1; int sum = pnt[mid] - pnt[i]; if (sum == x) { ok1 = 1; break; } if (sum < x) { lo = mid + 1; } else { hi = mid - 1; } } } int ok2 = 0; for (int i = 0; i < n && !ok2; i++) { int lo = i + 1; int hi = n - 1; int mid; while (lo <= hi) { mid = (lo + hi) >> 1; int sum = pnt[mid] - pnt[i]; if (sum == y) { ok2 = 1; break; } if (sum < y) { lo = mid + 1; } else { hi = mid - 1; } } } if (ok1 && ok2) { cout << 0 << "\n"; } else if (ok1) { cout << 1 << "\n"; cout << y << "\n"; } else if (ok2) { cout << 1 << "\n"; cout << x << "\n"; } else { int ok = 0; for (int i = 0; i < n && !ok; i++) { int diff = (((pnt[i] - x) < 0) ? (-(pnt[i] - x)) : (pnt[i] - x)); int df = y; int tmp1 = pnt[i] + x; int tmp2 = tmp1 + df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } tmp2 = tmp1 - df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } tmp1 = pnt[i] - x; tmp2 = tmp1 + df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } tmp2 = tmp1 - df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } } swap(x, y); for (int i = 0; i < n && !ok; i++) { int diff = (((pnt[i] - x) < 0) ? (-(pnt[i] - x)) : (pnt[i] - x)); int df = y; int tmp1 = pnt[i] + x; int tmp2 = tmp1 + df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } tmp2 = tmp1 - df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } tmp1 = pnt[i] - x; tmp2 = tmp1 + df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } tmp2 = tmp1 - df; if (tmp1 >= 0 && tmp1 <= l && tmp2 >= 0 && tmp2 <= l && binary_search((pnt).begin(), (pnt).end(), tmp2)) { cout << 1 << "\n"; cout << tmp1 << "\n"; ok = 1; return 0; } } swap(x, y); cout << 2 << "\n"; cout << x << " " << y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[100005], n; bool b(int l, int r, int val) { int left = l, right = r, mid; while (left <= right) { mid = (right + left) >> 1; if (a[mid] == val) { return 1; } else if (a[mid] < val) { left = mid + 1; } else right = mid - 1; } return 0; } int main() { int i, j, l, x, y; scanf("%d%d%d%d", &n, &l, &x, &y); for (i = 1; i <= n; i++) scanf("%d", &a[i]); bool flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0; int t = y - x, ans = -1, t2 = y + x; for (i = 1; i <= n; i++) { if (!flag1 && a[i] >= x) { flag1 = b(1, i - 1, a[i] - x); } if (!flag2 && a[i] >= y) { flag2 = b(1, i - 1, a[i] - y); } if (a[i] >= t) { flag3 = b(1, i - 1, a[i] - t); if (flag3 && a[i] > y) { ans = a[i] - y; } if (flag3 && a[i] + x < l) { ans = a[i] + x; } } if (a[i] >= t2) { flag4 = b(1, i - 1, a[i] - t2); if (flag4 && a[i] > y) { ans = a[i] - y; } } } int ct = 0; if (!flag1) ct++; if (!flag2) ct++; if (ans == -1) { printf("%d\n", ct); if (!flag1) printf("%d ", x); if (!flag2) printf("%d ", y); } else { if (ct <= 1) { printf("%d\n", ct); if (!flag1) printf("%d ", x); if (!flag2) printf("%d ", y); } else { printf("1\n"); printf("%d", ans); } } puts(""); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { for (; a != b; a++) cerr << *a << ' '; cerr << endl; } template <class T> bool isprime(T x) { int till = (T)sqrt(x + .0); if (x <= 1) return 0; if (x == 2) return 1; if (x / 2 * 2 == x) return 0; for (int i = 3; i <= till; i += 2) if (x / i * i == x) return 0; return 1; } int n, l, x, y; int a[100000]; set<int> s; int main() { cin >> n; cin >> l; cin >> x; cin >> y; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } bool okx = 0; for (int i = 0; i < n; i++) if (s.find(a[i] - x) != s.end() || s.find(a[i] + x) != s.end()) { okx = 1; break; } bool oky = 0; for (int i = 0; i < n; i++) if (s.find(a[i] - y) != s.end() || s.find(a[i] + y) != s.end()) { oky = 1; break; } if (okx && oky) { cout << 0; } else if (!okx && !oky) { for (int i = 0; i < n; i++) { if (a[i] - x >= 0 && (s.find(a[i] - x - y) != s.end() || s.find(a[i] - x + y) != s.end())) { cout << 1 << "\n"; cout << a[i] - x; return 0; } if (a[i] + x <= l && (s.find(a[i] + x - y) != s.end() || s.find(a[i] + x + y) != s.end())) { cout << 1 << "\n"; cout << a[i] + x; return 0; } } cout << 2 << "\n"; cout << x << " " << y; } else { int z = okx ? y : x; cout << 1 << "\n"; cout << z; } return EXIT_SUCCESS; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[200010][2], n, b[200010]; bool find(int x, int k) { int l = 1, r = n; if (k) r *= 2; while (l <= r) { int mid = (l + r) >> 1; if (x == a[mid][k]) return 1; if (x < a[mid][k]) r = mid - 1; else l = mid + 1; } return 0; } int main() { int l, x, y; scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1; i <= n; i++) { scanf("%d", &a[i][0]); b[i * 2 - 1] = a[i][0] - y; b[i * 2] = a[i][0] + y; } sort(b + 1, b + 2 * n + 1); for (int i = 1; i <= 2 * n; i++) a[i][1] = b[i]; bool ok1 = 0, ok2 = 0; for (int i = 1; i <= n; i++) if (find(a[i][0] + x, 0)) { ok1 = 1; break; } for (int i = 1; i <= n; i++) if (find(a[i][0] + y, 0)) { ok2 = 1; break; } if ((ok1) && (ok2)) { printf("0\n"); return 0; } if ((ok1) && (!ok2)) { printf("1\n%d\n", y); return 0; } if ((ok2) && (!ok1)) { printf("1\n%d\n", x); return 0; } ok1 = 0; int ans; for (int i = 1; i <= n; i++) if ((a[i][0] + x <= l) && (find(a[i][0] + x, 1))) { ok1 = 1; ans = a[i][0] + x; break; } for (int i = 1; i <= n; i++) if ((a[i][0] - x >= 0) && (find(a[i][0] - x, 1))) { ok1 = 1; ans = a[i][0] - x; break; } if (ok1) printf("1\n%d\n", ans); else printf("2\n%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, INF = int(1e9) + 1, mod = 1e9 + 7; const long long BIG = 1e16; int n, l, a[N], b[10], c[5], ans; set<int> s; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> l >> c[0] >> c[1]; for (int i = 1; i <= n; i++) { cin >> a[i]; s.insert(a[i]); } int x = c[0], y = c[1]; bool fx = 0, fy = 0; for (int i = 1; i <= n; i++) { if (a[i] - y >= 0 and s.count(a[i] - y)) { fy = 1; } if (a[i] + y <= l and s.count(a[i] + y)) { fy = 1; } if (a[i] + x <= l and s.count(a[i] + x)) { fx = 1; } if (a[i] - x >= 0 and s.count(a[i] - x)) { fx = 1; } } if (fx and fy) { cout << "0\n"; return 0; } if (fx and !fy) { cout << "1\n"; cout << y << '\n'; return 0; } if (!fx and fy) { cout << "1\n"; cout << x << '\n'; return 0; } for (int i = 1; i <= n; i++) { if (a[i] + x <= l and a[i] + x + y <= l and s.count(a[i] + x + y)) { cout << "1\n"; cout << a[i] + x << endl; return 0; } if (a[i] + x <= l and a[i] + x - y >= 0 and s.count(a[i] + x - y)) { cout << 1 << endl; cout << a[i] + x << endl; return 0; } if (a[i] - x >= 0 and a[i] - x + y <= l and s.count(a[i] - x + y)) { cout << "1\n"; cout << a[i] - x << endl; return 0; } if (a[i] - x >= 0 and a[i] - x - y >= 0 and s.count(a[i] - x - y)) { cout << 1 << endl; cout << a[i] - x << endl; return 0; } } cout << 2 << endl; cout << x << " " << y << endl; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, l, x, y, a[maxn]; bool Find(int L) { for (int i = 1; i <= n; ++i) { if (a[i] + L > l) break; int t = lower_bound(a + 1, a + n + 1, a[i] + L) - a; if (a[t] == a[i] + L) return 1; } return 0; } bool Zero() { if (Find(x) && Find(y)) { puts("0"); return 1; } return 0; } bool One() { if (Find(x)) { puts("1"); printf("%d", y); return 1; } if (Find(y)) { puts("1"); printf("%d", x); return 1; } for (int i = 1; i <= n; ++i) { if (a[i] - x >= 0) { int t = lower_bound(a + 1, a + 1 + n, a[i] - x - y) - a; if (a[t] == a[i] - x - y) { puts("1"); printf("%d", a[i] - x); return 1; } t = lower_bound(a + 1, a + 1 + n, a[i] - x + y) - a; if (a[t] == a[i] - x + y) { puts("1"); printf("%d", a[i] - x); return 1; } } if (a[i] + x <= l) { int t = lower_bound(a + 1, a + 1 + n, a[i] + x - y) - a; if (a[t] == a[i] + x - y) { puts("1"); printf("%d", a[i] + x); return 1; } t = lower_bound(a + 1, a + 1 + n, a[i] + x + y) - a; if (a[t] == a[i] + x + y) { puts("1"); printf("%d", a[i] + x); return 1; } } } return 0; } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1; i <= n; ++i) scanf("%d", a + i); if (Zero()) return 0; if (One()) return 0; puts("2"); printf("%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y; int a[100001]; vector<int> rem; set<int> s; bool solve0(); bool solve1(); int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { fscanf(stdin, "%d", &a[i]); s.insert(a[i]); } if (solve0()) { return 0; } if (solve1()) { return 0; } cout << 2 << endl; cout << x << " " << y << endl; return 0; } bool solve0() { bool foundx = false; bool foundy = false; for (int i = 0; i < n; i++) { int target = a[i] + x; set<int>::iterator it = s.find(target); if (it != s.end()) { foundx = true; } target = a[i] + y; it = s.find(target); if (it != s.end()) { foundy = true; } } if (foundx && foundy) { cout << 0 << endl; return true; } if (foundx) { rem.push_back(y); } else if (foundy) { rem.push_back(x); } else { rem.push_back(x); rem.push_back(y); } return false; } bool solve1() { if (rem.size() == 1) { cout << 1 << endl; cout << rem[0] << endl; return true; } for (int i = 0; i < n; i++) { int target = a[i] + x; set<int>::iterator it = s.find(target); if (it == s.end() && a[i] + x < l) { set<int>::iterator ity1 = s.find(target - y); set<int>::iterator ity2 = s.find(target + y); if (ity1 != s.end() || ity2 != s.end()) { cout << 1 << endl; cout << a[i] + x << endl; return true; } } } for (int i = 0; i < n; i++) { int target = a[i] - x; set<int>::iterator it = s.find(target); if (it == s.end() && a[i] - x > 0) { set<int>::iterator ity1 = s.find(target - y); set<int>::iterator ity2 = s.find(target + y); if (ity1 != s.end() || ity2 != s.end()) { cout << 1 << endl; cout << a[i] - x << endl; return true; } } } for (int i = 0; i < n; i++) { int target = a[i] + y; set<int>::iterator it = s.find(target); if (it == s.end() && a[i] + y < l) { set<int>::iterator itx1 = s.find(target - x); set<int>::iterator itx2 = s.find(target + x); if (itx1 != s.end() || itx2 != s.end()) { cout << 1 << endl; cout << a[i] + y << endl; return true; } } } for (int i = 0; i < n; i++) { int target = a[i] - y; set<int>::iterator it = s.find(target); if (it == s.end() && a[i] - y > 0) { set<int>::iterator itx1 = s.find(target - x); set<int>::iterator itx2 = s.find(target + x); if (itx1 != s.end() || itx2 != s.end()) { cout << 1 << endl; cout << a[i] - y << endl; return true; } } } return false; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y, marks[100005]; bool flag_x, flag_y, flag_z, flag_d; int main() { while (scanf("%d%d%d%d", &n, &l, &x, &y) != EOF) { flag_x = flag_y = flag_z = flag_d = 0; ; int pos, pos2; for (int i = 0; i < n; i++) scanf("%d", &marks[i]); for (int i = 0; i < n; i++) { int a = lower_bound(marks, marks + n, x + marks[i]) - marks; int b = lower_bound(marks, marks + n, y + marks[i]) - marks; int c = lower_bound(marks, marks + n, y - x + marks[i]) - marks; int d = lower_bound(marks, marks + n, x + y + marks[i]) - marks; if (a != n && marks[a] == x + marks[i]) flag_x = 1; if (b != n && marks[b] == y + marks[i]) flag_y = 1; if (c != n && marks[c] == y - x + marks[i] && (marks[i] + y <= l || marks[i] - x >= 0)) { flag_z = 1; pos = marks[i]; } if (d != n && marks[d] == x + y + marks[i]) { flag_d = 1; pos2 = marks[i]; } } if (flag_x && flag_y) { printf("0\n"); continue; } if (flag_x) { printf("1\n%d\n", marks[0] + y); continue; } if (flag_y) { printf("1\n%d\n", marks[0] + x); continue; } if (flag_z) { if (pos + y <= l) { printf("1\n%d\n", pos + y); continue; } if (pos - x >= 0) { printf("1\n%d\n", pos - x); continue; } } if (flag_d) { printf("1\n%d\n", pos2 + x); continue; } printf("2\n%d %d\n", marks[0] + x, marks[0] + y); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ii = pair<int, int>; using ll = long long; using llu = unsigned long long; const int INF = numeric_limits<int>::max(); int main() { int n, d1, d2, l; while (cin >> n >> l >> d1 >> d2) { vector<int> v(n); vector<ii> p; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { p.emplace_back(v[i], 0); if (v[i] - d1 >= 0) p.emplace_back(v[i] - d1, 1); if (v[i] + d1 <= l) p.emplace_back(v[i] + d1, 1); if (v[i] - d2 >= 0) p.emplace_back(v[i] - d2, 2); if (v[i] + d2 <= l) p.emplace_back(v[i] + d2, 2); } p.emplace_back(l + 1, 0); sort(p.begin(), p.end()); int o = -1; bool has[3]; int a1 = -1, a2 = -1; for (auto pp : p) { int x = pp.first; int j = pp.second; if (x != o) { if (o != -1) { if (has[1]) { if (has[0]) a1 = INF; if (a1 == -1) a1 = o; } if (has[2]) { if (has[0]) a2 = INF; if (a2 == -1) a2 = o; } if (has[1] && has[2] && a1 != INF && a2 != INF) a1 = a2 = o; } o = x; for (int i = 0; i < 3; i++) has[i] = false; } has[j] = true; } vi add; if (a1 != INF) add.emplace_back(a1); if (a2 != INF && a2 != a1) add.emplace_back(a2); cout << add.size() << endl; if (!add.empty()) { for (int i = 0; i < add.size(); i++) { if (i) cout << " "; cout << add[i]; } cout << endl; } } }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, L, x, y, a[N]; inline void read(int &x) { char ch; x = 0; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar()) ; } int query(int key) { int l = 0, r = 1; while (l <= r && r < n) { if (a[r] - a[l] == key) return 1; else if (a[r] - a[l] > key) l++; else r++; } return 0; } void solve() { int isX = query(x), isY = query(y); if (isX && isY) { printf("0\n"); return; } if (isX && !isY) { printf("1\n%d\n", y); return; } if (!isX && isY) { printf("1\n%d\n", x); return; } int l = 0, r = 1, key = y + x; while (l <= r && r < n) { if (a[r] - a[l] == key) { printf("1\n%d\n", a[l] + x); return; } else if (a[r] - a[l] > key) l++; else r++; } l = 0, r = 1, key = y - x; while (l <= r && r < n) { if (a[r] - a[l] == key) { if (a[l] - x > 0) { printf("1\n%d\n", a[l] - x); return; } if (a[r] + x < L) { printf("1\n%d\n", a[r] + x); return; } l++; } else if (a[r] - a[l] > y - x) l++; else r++; } printf("2\n%d %d\n", x, y); } int main() { read(n); read(L); read(x); read(y); for (int i = 0; i < n; i++) read(a[i]); solve(); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 100 * 1000 + 1000; int a[maxn]; set<int> st; int main() { int n, l, x, y; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; st.insert(a[i]); } bool xh = false, yh = false; for (int i = 0; i < n; i++) { if (st.find(a[i] - x) != st.end()) xh = true; if (st.find(a[i] - y) != st.end()) yh = true; } if (xh) { if (yh) { cout << 0 << endl; return 0; } cout << 1 << endl << y << endl; return 0; } if (yh) { cout << 1 << endl << x << endl; return 0; } for (int i = 0; i < n; i++) { int nw = a[i] - x; if (nw < 0) continue; if (st.find(nw + y) != st.end() || st.find(nw - y) != st.end()) { cout << 1 << endl << nw << endl; return 0; } } for (int i = 0; i < n; i++) { int nw = a[i] + x; if (nw > l) continue; if (st.find(nw + y) != st.end() || st.find(nw - y) != st.end()) { cout << 1 << endl << nw << endl; return 0; } } cout << 2 << endl << x << " " << y << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, l, x, y, a[maxn], res; bool xok, yok; map<int, int> m; void check(int d, int t) { if (d < 0 || d > l) return; if (m[d + t] || m[d - t]) { cout << 1 << endl << d; exit(0); } } int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = 1; } for (int i = 0; i <= n; i++) { xok |= m[a[i] - x]; xok |= m[a[i] + x]; yok |= m[a[i] + y]; yok |= m[a[i] - y]; } if (xok && yok) { cout << 0; return 0; } else if (xok) { cout << 1 << endl; cout << y; return 0; } else if (yok) { cout << 1 << endl; cout << x; return 0; } else { for (int i = 0; i < n; i++) { check(a[i] - x, y); check(a[i] + x, y); check(a[i] - y, x); check(a[i] + y, x); } cout << 2 << " " << x << " " << y; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, l, x, y; cin >> n >> l >> x >> y; vector<int> a(n); map<int, int> m; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = 1; } int ans = 0, i; vector<int>::iterator it; bool q1 = false, q2 = false, q3 = false; int v; for (i = 0; i < n; i++) { if (!q1 && m[a[i] + x]) q1 = true; if (!q2 && m[a[i] + y]) q2 = true; if (!q3 && (m[a[i] + x + y] || m[a[i] + x - y])) { if (m[a[i] + x + y]) { v = a[i] + x; q3 = true; } else if (a[i] + x < l) { v = a[i] + x; q3 = true; } else if (a[i] - y > 0) { q3 = true; v = a[i] - y; } } } if (!q1 && !q2) { if (q3) cout << "1\n" << v; else cout << "2\n" << x << " " << y; } else if (!q1) cout << "1\n" << x; else if (!q2) cout << "1\n" << y; else cout << "0"; cout << endl; }
8
CPP
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::vector; class Ruler { public: template <typename Iterator> Ruler(Iterator begin, Iterator end) : marks_(begin, end) {} void CanMeasure(int distance, bool &can_measure, int &left_mark, int &right_mark) { for (int left = 0; left < marks_.size(); ++left) { int to_search = distance + marks_[left]; int found_place = BinarySearch(to_search, left, marks_.size()); if (found_place != -1) { left_mark = left; right_mark = found_place; can_measure = true; return; } } can_measure = false; } void CanMeasureRight(int distance, bool &can_measure, int &left_mark, int &right_mark) { for (int left = marks_.size() - 1; left >= 0; --left) { int to_search = distance + marks_[left]; int found_place = BinarySearch(to_search, left, marks_.size()); if (found_place != -1) { left_mark = left; right_mark = found_place; can_measure = true; return; } } can_measure = false; } int BinarySearch(int value, int left_bound, int right_bound) { while (left_bound < right_bound - 1) { int middle = (left_bound + right_bound) / 2; if (marks_[middle] == value) { return middle; } else if (marks_[middle] > value) { right_bound = middle; } else { left_bound = middle; } } return -1; } private: vector<int> marks_; }; vector<int> GetExtraMarksToMeasure(const vector<int> &marks, int girl_distance, int boy_distance) { Ruler ruler(marks.begin(), marks.end()); int left_mark, right_mark; bool can_measure_boy, can_measure_girl, can_measure_sum, can_measure_diff; ruler.CanMeasure(girl_distance, can_measure_girl, left_mark, right_mark); ruler.CanMeasure(boy_distance, can_measure_boy, left_mark, right_mark); if (can_measure_boy && can_measure_girl) { return {}; } if (can_measure_girl) { return {boy_distance}; } if (can_measure_boy) { return {girl_distance}; } ruler.CanMeasure(girl_distance + boy_distance, can_measure_sum, left_mark, right_mark); if (can_measure_sum) { return {marks[left_mark] + girl_distance}; } int length = *marks.rbegin(); ruler.CanMeasure(boy_distance - girl_distance, can_measure_diff, left_mark, right_mark); if (can_measure_diff) { if (length - marks[right_mark] >= girl_distance) { return {marks[right_mark] + girl_distance}; } } ruler.CanMeasureRight(boy_distance - girl_distance, can_measure_diff, left_mark, right_mark); if (can_measure_diff) { if (marks[left_mark] >= girl_distance) { return {marks[left_mark] - girl_distance}; } } return {girl_distance, boy_distance}; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); size_t marks_count, length, girl_distance, boy_distance; cin >> marks_count >> length >> girl_distance >> boy_distance; vector<int> marks(marks_count); for (size_t i = 0; i < marks_count; ++i) { cin >> marks[i]; } vector<int> extra_marks = GetExtraMarksToMeasure(marks, girl_distance, boy_distance); cout << extra_marks.size() << endl; for (int mark : extra_marks) { cout << mark << ' '; } cout << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; set<int> S; int a[200000], n, l, x, y, now; bool fx, fy; int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); S.insert(a[i]); } for (int i = 1; i <= n; i++) { now = a[i] - x; if (S.find(now) != S.end()) { fx = true; break; } now = a[i] + x; if (S.find(now) != S.end()) { fx = true; break; } } for (int i = 1; i <= n; i++) { now = a[i] - y; if (S.find(now) != S.end()) { fy = true; break; } now = a[i] + y; if (S.find(now) != S.end()) { fy = true; break; } } if (fx && fy) { puts("0"); return 0; } if (fx && !fy) { puts("1"); printf("%d\n", y); return 0; } if (!fx && fy) { puts("1"); printf("%d\n", x); return 0; } if (!fx && !fy) { for (int i = 1; i <= n; i++) { now = a[i] + x + y; if (S.find(now) != S.end()) { puts("1"); printf("%d\n", a[i] + x); return 0; } now = a[i] - x - y; if (S.find(now) != S.end()) { puts("1"); printf("%d\n", a[i] - x); return 0; } now = a[i] + x - y; if (S.find(now) != S.end()) { if (a[i] + x <= l) { puts("1"); printf("%d\n", a[i] + x); return 0; } if (a[i] - y >= 0) { puts("1"); printf("%d\n", a[i] - y); } } now = a[i] - x + y; if (S.find(now) != S.end()) { if (a[i] - x >= 0) { puts("1"); printf("%d\n", a[i] - x); return 0; } if (a[i] + y <= l) { puts("1"); printf("%d\n", a[i] + y); return 0; } } } puts("2"); printf("%d %d\n", x, y); return 0; } }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; set<int> s; map<int, int> pt; int a[MAXN]; int main() { int n, l, x, y; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } int px = 1, py = 1; for (int i = 0; i < n; i++) { if (s.find(a[i] - x) != s.end() || s.find(a[i] + x) != s.end()) px = 0; if (s.find(a[i] - y) != s.end() || s.find(a[i] + y) != s.end()) py = 0; } int need = px * 2 + py; if (need == 0) { cout << 0 << endl; return 0; } for (int i = 0; i < n; i++) { if (a[i] - x >= 0) pt[a[i] - x] |= 2; if (a[i] + x <= l) pt[a[i] + x] |= 2; if (a[i] - y >= 0) pt[a[i] - y] |= 1; if (a[i] + y <= l) pt[a[i] + y] |= 1; } for (map<int, int>::iterator it = pt.begin(); it != pt.end(); it++) if ((it->second | need) == it->second) { cout << 1 << endl << it->first << endl; return 0; } cout << 2 << endl << x << " " << y << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, len, x, y; cin >> n >> len >> x >> y; int *a = new int[n]; for (int i = 0; i < n; i++) scanf("%d", a + i); bool flag1 = false; bool flag2 = false; int k, l; k = 0; l = 1; while (l < n) { if (a[l] - a[k] == x) { flag1 = true; break; } else if (a[l] - a[k] > x) { k++; } else l++; } k = 0; l = 1; while (l < n) { if (a[l] - a[k] == y) { flag2 = true; break; } else if (a[l] - a[k] > y) { k++; } else l++; } if (flag1 & flag2) { cout << 0 << endl; return 0; } if (flag1) { cout << 1 << endl << y << endl; return 0; } if (flag2) { cout << 1 << endl << x << endl; return 0; } k = 0; l = 1; while (l < n) { if (a[l] - a[k] == y + x) { cout << 1 << endl << a[k] + x << endl; return 0; } else if (a[l] - a[k] > y + x) { k++; } else l++; } k = 0; l = 1; while (l < n) { if (a[l] - a[k] == y - x && (a[k] - x >= 0)) { cout << 1 << endl << a[k] - x << endl; return 0; } else if (a[l] - a[k] == y - x && (a[l] + x <= len)) { cout << 1 << endl << a[l] + x << endl; return 0; } else if (a[l] - a[k] > y - x) { k++; } else l++; } cout << 2 << endl; cout << x << ' ' << y << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long n, l, x, y; long long a[100100]; int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) cin >> a[i]; bool fx = false, fy = false; for (int i = 0; i < n; i++) { if (binary_search(a, a + n, a[i] + x)) { fx = true; break; } } for (int i = 0; i < n; i++) { if (binary_search(a, a + n, a[i] + y)) { fy = true; break; } } if (fx && fy) { printf("0\n"); return 0; } if (fx && !fy) { printf("1\n"); cout << y << endl; return 0; } if (!fx && fy) { printf("1\n"); cout << x << endl; return 0; } for (int i = 0; i < n; i++) { if (binary_search(a, a + n, a[i] + x + y)) { printf("1\n"); cout << a[i] + x << endl; return 0; } } for (int i = 0; i < n; i++) { if (binary_search(a, a + n, a[i] + y - x)) { if (a[i] + y > l && a[i] - x < 0) continue; if (a[i] + y <= l) { printf("1\n"); cout << a[i] + y << endl; } else { printf("1\n"); cout << a[i] - x << endl; } return 0; } } printf("2\n"); cout << x << ' ' << y << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long a, s, d, f, g, h, j, k, l, i, n, m; set<long long> x, z, c, v; int main() { cin >> n >> m >> k >> l; for (i = 0; i < n; i++) { scanf("%d", &a); x.insert(a + k); c.insert(a + l); s = x.size(); x.insert(a); if (x.size() == s) { d = 1; } s = c.size(); c.insert(a); if (c.size() == s) { f = 1; } s = z.size(); z.insert(a + k); if (s == z.size()) if (a + k < m) j = a + k; else if (a - l > 0) j = a - l; s = z.size(); z.insert(a + l); if (s == z.size()) if (a + l < m) j = a + l; else if (a - k > 0) j = a - k; s = v.size(); v.insert(a + k); if (s == v.size() && a + k < m) j = a + k; s = v.size(); v.insert(a - l); if (s == v.size() && a - l > 0) j = a - l; } if (d + f == 2) cout << 0; else if (d + f == 1) { cout << 1 << endl; if (d == 0) cout << k; else cout << l; } else if (j != 0) cout << 1 << endl << j; else cout << 2 << endl << k << " " << l; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 110; int v[maxn]; vector<int> h; int main() { int n, l, x, y; scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; i++) { scanf("%d", &v[i]); } bool it = false; for (int i = n - 1; i >= 0; i--) { int h = v[i] - x; if (h < 0) { break; } int l = 0; int r = i; while (r - l > 1) { int m = (r + l) / 2; if (v[m] > h) { r = m; } else { l = m; } } for (int i = l; i <= r; i++) { if (v[i] == h) { it = true; } } } bool it_1 = false; for (int i = n - 1; i >= 0; i--) { int h = v[i] - y; if (h < 0) { break; } int l = 0; int r = i; while (r - l > 1) { int m = (r + l) / 2; if (v[m] > h) { r = m; } else { l = m; } } for (int i = l; i <= r; i++) { if (v[i] == h) { it_1 = true; } } } if (it && it_1) { cout << "0"; return 0; } if (it && !it_1) { cout << "1" << endl; cout << y; return 0; } if (!it && it_1) { cout << "1" << endl; cout << x; return 0; } for (int i = 0; i < n; i++) { if (v[i] + x <= l) { if ((*lower_bound(v, v + n, y + v[i] + x)) == y + v[i] + x) { cout << 1 << endl; cout << v[i] + x; return 0; } else if ((*lower_bound(v, v + n, v[i] + x - y)) == v[i] + x - y) { cout << "1" << endl; cout << v[i] + x; return 0; } } if (v[i] - x >= 0) { if ((*lower_bound(v, v + n, v[i] - x + y)) == v[i] - x + y) { cout << "1" << endl; cout << v[i] - x; return 0; } else if ((*lower_bound(v, v + n, v[i] - x - y)) == v[i] - x - y) { cout << "1" << endl; cout << v[i] - x; return 0; } } } cout << "2" << endl; cout << x << ' ' << y; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[100005], *t, n, l, i; int solve(int x) { int s; for (i = 0; i < n - 1; i++) { s = a[i] + x; t = lower_bound(a + i, a + n, s); if (*t == s) return 1; } return 0; } void work(int x, int y) { int s; for (i = 0; i < n - 1; i++) { s = a[i] + y - x; t = lower_bound(a + i, a + n, s); if (*t == s) { if (*t + x <= l) { printf("1\n%d\n", *t + x); break; } else if (*t - y >= 0) { printf("1\n%d\n", *t - y); break; } } } if (i == n - 1) printf("2\n%d %d\n", x, y); } int main() { int x, y; while (~scanf("%d%d%d%d", &n, &l, &x, &y)) { int flag = 0; for (i = 0; i < n; i++) scanf("%d", &a[i]); if (!solve(x)) flag++; if (!solve(y)) flag += 2; if (flag == 0) printf("0\n"); else if (flag == 1) printf("1\n%d\n", x); else if (flag == 2) printf("1\n%d\n", y); else { if (solve(y + x)) printf("1\n%d\n", *t - y); else work(x, y); } } }
8
CPP
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e6 + 8; const long long sz = 1e5 + 5; void f_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; } int32_t main() { f_io(); long long t = 1; while (t--) { long long n, l, x, y; cin >> n >> l >> x >> y; unordered_map<long long, long long> vis; vector<long long> v; for (long long i = 0; i < n; i++) { long long mark; cin >> mark; vis[mark] = 1; v.push_back(mark); } long long fans = 0, flag1 = 0, flag2 = 0; for (long long i = 0; i < n; i++) { if (vis[x + v[i]]) { flag1 = 1; break; } } for (long long i = 0; i < n; i++) { if (vis[y + v[i]]) { flag2 = 1; break; } } vector<long long> ans; if (!flag1) { fans++; ans.push_back(x); } if (!flag2) { fans++; ans.push_back(y); } if (fans == 2) { unordered_map<long long, long long> temp; long long fflag = 0, _ans; for (long long i = 0; i < n; i++) { long long k1 = v[i] - x, k2 = v[i] + x; if (k1 >= 0) temp[k1] = 1; if (k2 <= l) temp[k2] = 1; } for (long long i = 0; i < n; i++) { long long k1 = v[i] - y, k2 = v[i] + y; if (k1 >= 0) { if (temp[k1]) { fflag = 1; _ans = k1; break; } } if (k2 >= 0) { if (temp[k2]) { fflag = 1; _ans = k2; break; } } } if (fflag) { cout << "1" << "\n" << _ans << "\n"; continue; } } cout << fans << "\n"; for (auto k : ans) cout << k << " "; } }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, l, x, y, a[MAXN], xok, yok, arr[MAXN + MAXN], sz; bool check(int d) { for (int i = 0, r = 0; i < n && r < n; ++i) { for (; r < n && a[r] - a[i] < d; ++r) ; if (r < n && a[r] - a[i] == d) return true; } return false; } bool ok(int p) { if (p < 0 || p > l) return false; return binary_search(arr, arr + sz, p); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> l >> x >> y; for (int i = 0; i < n; ++i) { cin >> a[i]; } xok = check(x); yok = check(y); if (xok && yok) cout << 0 << endl; else if (xok || yok) cout << 1 << endl << x * (xok ^ 1) + y * (yok ^ 1) << endl; else { int pos = -1; for (int i = 0; i < n; ++i) { arr[sz++] = a[i] - x; arr[sz++] = a[i] + x; } sort(arr, arr + sz); for (int i = 0; i < n && pos < 0; ++i) { if (ok(a[i] - y)) pos = a[i] - y; else if (ok(a[i] + y)) pos = a[i] + y; } if (pos == -1) cout << 2 << endl << x << " " << y << endl; else cout << 1 << endl << pos << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX / 3; const double eps = 1e-8; const long long LINF = 1e17; const double DINF = 1e60; const int maxn = 1e5 + 10; set<int> st; vector<int> ans; int n, l, x, y, a[maxn]; bool gao0(int val) { for (int i = 1; i <= n; i++) { int pval = a[i] + val; if (st.count(pval)) return true; } return false; } bool gao1(int mid, int p) { bool exmid = false, exp = false; ans.clear(); for (int i = 1; i <= n; i++) { int pval = a[i] + mid + p; if (st.count(pval) && mid + a[i] <= l && mid + a[i] >= 0) { ans.push_back(mid + a[i]); return true; } exmid |= st.count(a[i] + mid); exp |= st.count(a[i] + p); } if (exmid == true && exp == false) { ans.push_back(p); return true; } if (exp == true && exmid == false) { ans.push_back(mid); return true; } return false; } void gao() { if (gao0(x) && gao0(y)) { puts("0"); return; } if (gao1(x, y) || gao1(y, x) || gao1(x, -y) || gao1(y, -x) || gao1(-x, y) || gao1(-y, x)) { puts("1"); printf("%d\n", ans[0]); return; } if (x == y) { printf("1\n%d\n", x); return; } printf("2\n%d %d\n", x, y); } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); st.insert(a[i]); } gao(); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; map<int, bool> Map; int a[100005]; int main() { int n, l, x, y; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; Map[a[i]] = true; } bool bx = false, by = false; int xx, yy; for (int i = 0; i < n; i++) { if (Map[a[i] - x]) bx = true; if (Map[a[i] + x]) bx = true; if (Map[a[i] - y]) { by = true; } if (Map[a[i] + y]) { by = true; } if (bx && by) break; } if (bx && by) { cout << 0 << endl; } else if (bx || by) { cout << 1 << endl; if (bx) cout << y << endl; else cout << x << endl; } else { for (int i = 1; i < n; i++) { if (Map[a[i] - (x + y)]) { cout << 1 << endl; cout << a[i] - y << endl; return 0; } else if (Map[a[i] - (y - x)]) { if (a[i] + x <= l) { cout << 1 << endl; cout << a[i] + x << endl; return 0; } else if (a[i] - y >= 0) { cout << 1 << endl; cout << a[i] - y << endl; return 0; } } } cout << 2 << endl; cout << x << ' ' << y << endl; } }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y; map<int, int> m; int a[100000]; void haha(int a, int b) { if (a < 0 || a > l) return; if (m[a - b] || m[a + b]) { cout << 1 << endl << a << endl; exit(0); } } int main() { ios::sync_with_stdio(false); cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = 1; } bool c, b; c = b = 0; for (int i = 0; i < n; i++) { c |= m[a[i] - x]; c |= m[a[i] + x]; b |= m[a[i] - y]; b |= m[a[i] + y]; } if (c && b) cout << 0 << endl; else if (c) { cout << 1 << endl << y << endl; } else if (b) { cout << 1 << endl << x << endl; } else { for (int i = 0; i < n; i++) { haha(a[i] - x, y); haha(a[i] + x, y); haha(a[i] - y, x); haha(a[i] + y, x); } cout << 2 << endl << x << " " << y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; void err(istringstream &iss) {} template <typename T, typename... Args> void err(istringstream &iss, const T &varVal, const Args &...args) { string varName; iss >> varName; if (varName.back() == ',') varName.back() = ' '; cout << varName << " = " << varVal << "; ", err(iss, args...); } int n, m, T, Q, cn = 0, K; int l, x, y, a[100005]; int flgx = 0, flgy = 0, flgxplusy = 0, flgxminusy = 0; int main() { cin.tie(NULL); cout.tie(NULL); scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (binary_search(a, a + i, a[i] - x)) { flgx = 1; } if (binary_search(a, a + i, a[i] - y)) { flgy = 1; } if (binary_search(a, a + i, a[i] - (x + y))) { flgxplusy = a[i] - x + 1; } if (binary_search(a, a + i, a[i] - abs(x - y))) { if (a[i] + min(x, y) <= l) flgxminusy = a[i] + min(x, y); else if (a[i] - max(x, y) >= 0) flgxminusy = a[i] - max(x, y); } } if (flgx && flgy) { printf("0\n"); } else if (flgx || flgy || flgxplusy || flgxminusy) { printf("1\n"); if (flgxminusy) printf("%d\n", flgxminusy); else if (flgxplusy) printf("%d\n", flgxplusy - 1); else if (flgx) printf("%d\n", y); else printf("%d\n", x); } else { printf("2\n"); printf("%d %d\n", x, y); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y, i, cx, cy; vector<int> vx, vy, vreq; int arr[100005]; int find_a(int x) { int low, high, mid; low = 1; high = n; while ((high - low) > 1) { mid = (high + low) / 2; if (arr[mid] == x) return 1; if (arr[mid] > x) high = mid; else low = mid; } if ((arr[low] != x) && (arr[high] != x)) return -1; return 1; } int find_y(int x) { int low, high, mid; low = 0; high = vy.size() - 1; while ((high - low) > 1) { mid = (low + high) / 2; if (vy[mid] == x) return 1; if (vy[mid] > x) high = mid; else low = mid; } if ((vy[low] != x) && (vy[high] != x)) return -1; return 1; } int main() { scanf("%d", &n); scanf("%d", &l); scanf("%d", &x); scanf("%d", &y); for (i = 1; i <= n; i++) scanf("%d", &arr[i]); for (i = 1; i <= n; i++) { if ((arr[i] + x) <= l) { vx.push_back(arr[i] + x); } if ((arr[i] + y) <= l) { vy.push_back(arr[i] + y); } if ((arr[i] - x) >= 0) { vx.push_back(arr[i] - x); } if ((arr[i] - y) >= 0) { vy.push_back(arr[i] - y); } } sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end()); cx = 0; cy = 0; int y1; for (i = 0; i < vx.size(); i++) { y1 = find_y(vx[i]); if (y1 != -1) { vreq.push_back(vx[i]); } } for (i = 0; i < vx.size(); i++) { y1 = find_a(vx[i]); if (y1 != -1) cx = 1; } for (i = 0; i < vy.size(); i++) { y1 = find_a(vy[i]); if (y1 != -1) cy = 1; } if ((cx + cy) == 2) { cout << "0"; } if ((cx + cy) == 1) { cout << "1" << "\n"; if (cx == 0) cout << x; else cout << y; } if ((cx + cy) == 0) { if (vreq.size() >= 1) { cout << "1" << "\n"; cout << vreq[0]; } else { cout << "2" << "\n"; cout << x << " " << y; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n; long long x, y, l; long long a[MAXN]; long long v; long long p1, p2; int main() { while (scanf("%d%I64d%I64d%I64d", &n, &l, &x, &y) != EOF) { for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]); v = 2; p1 = x, p2 = y; int ll = 1; for (int i = 1; i <= n; i++) { while (a[i] - a[ll] > x) ll++; if (a[i] - a[ll] == x) { v--; p1 = -1; break; } } ll = 1; for (int i = 1; i <= n; i++) { while (a[i] - a[ll] > y) ll++; if (a[i] - a[ll] == y) { v--; p2 = -1; break; } } if (v == 2) { ll = 1; for (int i = 1; i <= n; i++) { while (a[i] - a[ll] > y - x) ll++; if (a[i] - a[ll] == y - x) { if (a[i] + x <= l) { v--; p1 = a[i] + x; p2 = -1; break; } else if (a[ll] - x >= 0) { v--; p1 = a[ll] - x; p2 = -1; break; } } } } if (v == 2) { ll = 1; for (int i = 1; i <= n; i++) { while (a[i] - a[ll] > y + x) ll++; if (a[i] - a[ll] == y + x) { v--; p1 = a[ll] + x; p2 = -1; break; } } } printf("%I64d\n", v); if (p1 != -1) printf("%I64d", p1); if (v == 2) printf(" "); if (p2 != -1) printf("%I64d", p2); if (v > 0) putchar('\n'); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y, a; vector<int> v; int found[2]; set<int> s; bool can(int z) { return (s.find(z - v[0]) != s.end() || s.find(z + v[0]) != s.end()) && (s.find(z - v[1]) != s.end() || s.find(z + v[1]) != s.end()); } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); v = {x, y}; for (int i = 0; i < n; i++) { scanf("%d", &a); s.insert(a); } memset(found, 0, sizeof(found)); for (auto &it : s) { for (int i = 0; i < v.size(); i++) { if (s.find(it + v[i]) != s.end()) { found[i] = true; } } } int need = 0; vector<int> ans; for (int i = 0; i < v.size(); i++) { if (!found[i]) { need++; ans.push_back(v[i]); } } if (need < 2) { printf("%d\n", need); for (int i = 0; i < ans.size(); i++) { if (i != 0) printf(" "); printf("%d", ans[i]); if (i == ans.size() - 1) printf("\n"); } } else { for (auto &it : s) { int putAt = it + v[0]; if (putAt <= l) { if (can(putAt)) { printf("1\n"); printf("%d\n", putAt); return 0; } } putAt = it - v[0]; if (putAt >= 0) { if (can(putAt)) { printf("1\n"); printf("%d\n", putAt); return 0; } } putAt = it + v[1]; if (putAt <= l) { if (can(putAt)) { printf("1\n"); printf("%d\n", putAt); return 0; } } putAt = it - v[1]; if (putAt >= 0) { if (can(putAt)) { printf("1\n"); printf("%d\n", putAt); return 0; } } } printf("%d\n", need); for (int i = 0; i < ans.size(); i++) { if (i != 0) printf(" "); printf("%d", ans[i]); if (i == ans.size() - 1) printf("\n"); } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const long long inf = 1000000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, l, x, y; cin >> n >> l >> x >> y; vector<int> vm; map<int, int> mp; for (int i = 0; i < n; i++) { int x; cin >> x; if (mp[x] == 0) { vm.push_back(x); mp[x]++; } } if (mp[0] == 0) { vm.push_back(0); mp[0] = 1; } if (mp[l] == 0) { vm.push_back(l); mp[l] = 1; } sort(vm.begin(), vm.end()); int cnt = 0; map<int, int> mp2; for (int i = 0; i < vm.size(); i++) { int cur = vm[i]; if (mp[cur - x] == 1 && mp2[x] == 0) { cnt++; mp2[x] = 1; } if (mp[cur - y] == 1 && mp2[y] == 0) { cnt++; mp2[y] = 1; } } if (cnt == 2) { cout << "0" << '\n'; return 0; } else if (cnt == 1) { cout << "1" << '\n'; if (mp2[x] == 0) { cout << x << '\n'; } else cout << y << '\n'; return 0; } else if (cnt == 0) { for (int i = 0; i < vm.size(); i++) { int cur = vm[i]; if (cur - x >= 0 && (mp[cur - x + y] == 1 || mp[cur - x - y] == 1)) { cout << "1" << '\n'; cout << cur - x << '\n'; return 0; } else if (cur + x <= l && (mp[cur + x - y] == 1 || mp[cur + x + y] == 1)) { cout << "1" << '\n'; cout << cur + x << '\n'; return 0; } if (cur - y >= 0 && (mp[cur - y + x] == 1 || mp[cur - y - x] == 1)) { cout << "1" << '\n'; cout << cur - y << '\n'; return 0; } else if (cur + y <= l && (mp[cur + y - x] == 1 || mp[cur + y + x] == 1)) { cout << "1" << '\n'; cout << cur + y << '\n'; return 0; } } } cout << "2" << '\n'; cout << x << " " << y << '\n'; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } inline int getBit(long long x, int pos) { return ((x >> pos) & 1); } const double eps = 1e-9; const double pi = acos(-1.0); const int MAXN = (int)(1e5) + 10; int n, l; int g, b; int a[MAXN]; int ng, nb; int gg[2 * MAXN], bb[2 * MAXN]; int bst, ans[2]; int main() { scanf("%d%d%d%d", &n, &l, &g, &b); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } ng = nb = 0; for (int i = 0; i < n; i++) { if (a[i] - g >= 0) { gg[ng++] = a[i] - g; } if (a[i] + g <= l) { gg[ng++] = a[i] + g; } if (a[i] - b >= 0) { bb[nb++] = a[i] - b; } if (a[i] + b <= l) { bb[nb++] = a[i] + b; } } sort(gg, gg + ng); sort(bb, bb + nb); bst = 2; ans[0] = g; ans[1] = b; int two = 0; for (int i = 0; i < ng; i++) { if (binary_search(a, a + n, gg[i])) { two |= 1; break; } } for (int i = 0; i < nb; i++) { if (binary_search(a, a + n, bb[i])) { two |= 2; break; } } if (two == 3) { puts("0"); return 0; } if (two != 0) { if (two == 1) { bst = 1; ans[0] = b; } else { bst = 1; ans[0] = g; } } for (int i = 0; i < ng; i++) { if (binary_search(bb, bb + nb, gg[i])) { if (bst > 1) { bst = 1; ans[0] = gg[i]; } } } for (int i = 0; i < ng; i++) { if (!binary_search(a, a + n, gg[i]) && (binary_search(a, a + n, gg[i] + b) || binary_search(a, a + n, gg[i] - b))) { if (bst > 1) { bst = 1; ans[0] = gg[i]; } } } for (int i = 0; i < nb; i++) { if (!binary_search(a, a + n, bb[i]) && (binary_search(a, a + n, bb[i] - g) || binary_search(a, a + n, bb[i] + g))) { if (bst > 1) { bst = 1; ans[0] = bb[i]; } } } printf("%d\n", bst); for (int i = 0; i < bst; i++) { printf("%d ", ans[i]); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; map<long long, bool> isMark; int main() { long long n, x, y, l; cin >> n >> l >> x >> y; bool b = 0, g = 0, d = 0, bd = 0; long long diff = y - x, B = y + x; long long tmp; long long mark = -1, mark2 = -1; bool n1 = 1, n2 = 1; for (int i = 0; i < n; i++) { cin >> tmp; isMark[tmp] = 1; b |= isMark.count(tmp - x); g |= isMark.count(tmp - y); d |= isMark.count(tmp - diff); bd |= isMark.count(tmp - B); if (b && g) { cout << "0"; return 0; } if (d && n1) { long long idx = tmp + x; if (idx > l) { idx = tmp - y; if (idx >= 0) { mark = idx; } } else { mark = idx; } if (mark == -1) { d = 0; } else { n1 = 0; } } if (bd && n2) { mark2 = tmp - y; n2 = 0; } } if (b & !g) { cout << "1\n" << y; } else if (g & !b) { cout << "1\n" << x; } else if (d) { cout << "1\n"; cout << mark; } else if (bd) { cout << "1\n" << mark2 << "\n"; } else { cout << "2\n"; cout << x << " " << y; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, l, x, y; int a[maxn]; set<int> pos; bool in(int x) { return x >= 0 && x <= l; } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1, t; i <= n; i++) { scanf("%d", &a[i]); pos.insert(a[i]); } int repx = -1, repy = -1; for (int i = 1; i <= n; i++) { if (pos.count(a[i] - x)) repx = a[i]; if (pos.count(a[i] - y)) repy = a[i]; } if (repx != -1 && repy != -1) { printf("0\n"); return 0; } if (repx != -1) { printf("1\n%d\n", y); return 0; } if (repy != -1) { printf("1\n%d\n", x); return 0; } for (int i = 1; i <= n; i++) { if (pos.count(a[i] - x - y)) { printf("1\n%d\n", a[i] - x); return 0; } if (pos.count(a[i] - (y - x))) { if (in(a[i] + x)) { printf("1\n%d\n", a[i] + x); return 0; } if (in(a[i] - (y - x) - x)) { printf("1\n%d\n", a[i] - (y - x) - x); return 0; } } } printf("2\n%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> const int maxn = 100010; const int mod = 1e9 + 7; using namespace std; long long A, B, N, S, num[maxn]; map<long long, int> M; int main() { scanf("%I64d%I64d%I64d%I64d", &N, &S, &A, &B); for (int i = 1; i <= N; i++) { scanf("%d", &num[i]); M[num[i]] = 1; } int ma = 0, mb = 0; for (int i = 1; i <= N; i++) { int k = num[i]; if (M[k + A] || M[k - A]) ma = 1; if (M[k + B] || M[k - B]) mb = 1; } if (ma && mb) { printf("0\n"); return 0; } if (ma || mb) { printf("1\n%I64d\n", ma ? B : A); return 0; } for (int i = 1; i <= N; i++) { long long K = num[i]; if ((M[K + A + B] || M[K + A - B]) && K + A <= S) { printf("1\n%I64d\n", K + A); return 0; } if ((M[K - A + B] || M[K - A - B]) && K - A >= 0) { printf("1\n%I64d\n", K - A); return 0; } } printf("2\n%I64d %I64d\n", A, B); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int n, l, x, y; int a[MAXN]; bool check(int i, int x) { int j = lower_bound(a, a + n, a[i] + x) - a; if (j < n && a[j] == a[i] + x) return true; else return false; } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; ++i) scanf("%d", a + i); bool b1 = false; bool b2 = false; for (int i = 0; i < n; ++i) { if (check(i, x)) b1 = true; if (check(i, y)) b2 = true; } if (b1 && b2) printf("0\n"); else if (b1) printf("1\n%d\n", y); else if (b2) printf("1\n%d\n", x); else { bool flag = false; for (int i = 0; i < n; ++i) { if (check(i, y - x)) { if (a[i] + y <= l) { printf("1\n%d\n", a[i] + y); flag = true; break; } else if (a[i] - x >= 0) { printf("1\n%d\n", a[i] - x); flag = true; break; } } if (check(i, x + y)) { printf("1\n%d\n", a[i] + x); flag = true; break; } } if (!flag) printf("2\n%d %d\n", x, y); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-7; const long long SZ = 200010, SSZ = 21, APB = 52, one = 11; const long long INF = 0x7f7f7f7f, mod = 1000000007; long long n, len, alen, blen, arr[SZ]; set<int> st; bool chk1() { bool ok1 = 0, ok2 = 0; for (int i = 1; i <= n; ++i) { ok1 |= st.find(arr[i] + alen) != st.end(); ok2 |= st.find(arr[i] + blen) != st.end(); } if (ok1 && ok2) cout << 0 << endl; else if (ok1) cout << 1 << endl << blen << endl; else if (ok2) cout << 1 << endl << alen << endl; return ok1 || ok2; } bool chk2() { bool ok = 0; for (int i = 1; i <= n; ++i) { int pos = arr[i] + alen; ok |= st.find(pos + blen) != st.end(); ok |= st.find(pos - blen) != st.end(); if (ok && pos >= 0 && pos <= len) { cout << 1 << endl; cout << pos << endl; return 1; } else ok = 0; pos = arr[i] - alen; ok |= st.find(pos + blen) != st.end(); ok |= st.find(pos - blen) != st.end(); if (ok && pos >= 0 && pos <= len) { cout << 1 << endl; cout << pos << endl; return 1; } else ok = 0; } return ok; } void init() { cin >> n >> len >> alen >> blen; for (int i = 1; i <= n; ++i) { cin >> arr[i]; st.insert(arr[i]); } if (chk1()) ; else if (chk2()) ; else cout << 2 << endl << alen << " " << blen << endl; } void work() {} int main() { std::ios::sync_with_stdio(0); int casenum; { init(); work(); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, l, x, y, a[MAXN], xok, yok, arr1[MAXN + MAXN], arr2[MAXN + MAXN], sz; bool check(int d) { for (int i = 0, r = 0; i < n && r < n; ++i) { for (; r < n && a[r] - a[i] < d; ++r) ; if (r < n && a[r] - a[i] == d) return true; } return false; } bool ok(int p) { if (p < 0 || p > l) return false; return binary_search(arr1, arr1 + sz, p) || binary_search(arr2, arr2 + sz, p); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> l >> x >> y; for (int i = 0; i < n; ++i) { cin >> a[i]; } xok = check(x); yok = check(y); if (xok && yok) cout << 0 << endl; else if (xok || yok) cout << 1 << endl << x * (xok ^ 1) + y * (yok ^ 1) << endl; else { int pos = -1; for (int i = 0; i < n; ++i) { arr1[sz] = a[i] - x; arr2[sz++] = a[i] + x; } sort(arr1, arr1 + sz); sort(arr2, arr2 + sz); for (int i = 0; i < n && pos < 0; ++i) { if (ok(a[i] - y)) pos = a[i] - y; else if (ok(a[i] + y)) pos = a[i] + y; } if (pos == -1) cout << 2 << endl << x << " " << y << endl; else cout << 1 << endl << pos << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int flag1 = 0, flag2 = 0, flag3 = 0, ff3, flag4 = 0; int n, a[200000 + 5], x, y; map<int, bool> mp; int main() { n = read(); read(); x = read(); y = read(); for (int i = 1; i <= n; ++i) mp[a[i] = read()] = 1; for (int i = 1; i <= n; ++i) { if (mp[a[i] - x]) flag1 = i; if (mp[a[i] - y]) flag2 = i; if (mp[a[i] - y + x] && (a[i] - y >= 0 || a[i] + x <= a[n])) flag3 = i, ff3 = (a[i] - y >= 0) ? a[i] - y : a[i] + x; ; if (mp[a[i] - y - x]) flag4 = i; } if (flag1 && flag2) puts("0"); else if (flag1 | flag2) printf("1\n%d", flag1 ? y : x); else if (flag3) printf("1\n%d", ff3); else if (flag4) printf("1\n%d", a[flag4] - x); else printf("2\n%d %d", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); int n; long long l, first, second; cin >> n >> l >> first >> second; vector<long long> a(n); map<long long, bool> flag; for (int i = 0; i < int(n); i++) { cin >> a[i]; flag[a[i]] = true; } bool fx = false, fy = false; for (int i = n - 1; i >= 0; i--) { if (flag.count(a[i] - first)) fx = true; if (flag.count(a[i] - second)) fy = true; } if (!fx && !fy) { long long diff = second - first; for (int i = 0; i < n; i++) { if (flag.count(a[i] - diff)) { if (a[i] + first <= l) { cout << 1 << "\n"; cout << a[i] + first; return 0; } if (a[i] - second >= 0) { cout << 1 << "\n"; cout << a[i] - second; return 0; } } } long long add = first + second; for (int i = 0; i < n; i++) { if (flag.count(a[i] + add)) { if (a[i] + first <= l) { cout << 1 << "\n"; cout << a[i] + first; return 0; } } } cout << 2 << "\n"; cout << first << " " << second; } else if (!fx) { cout << 1 << "\n"; cout << first; } else if (!fy) { cout << 1 << "\n"; cout << second; } else cout << "0\n"; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[110000]; map<int, int> num; int n, l, x, y; int main() { int ok = 0; int i, j; scanf("%d %d %d %d", &n, &l, &x, &y); for (i = 0; i < n; i++) { scanf("%d", &a[i]); num.insert(pair<int, int>(a[i], 1)); } for (i = 0, j = 0; j != n;) { if (a[j] - a[i] == x) { ok += 1; break; } else if (a[j] - a[i] < x) { j++; } else i++; } for (i = 0, j = 0; j != n;) { if (a[j] - a[i] == y) { ok += 2; break; } else if (a[j] - a[i] < y) { j++; } else i++; } if (ok == 3) printf("0"); else if (ok == 1) printf("1\n%d", y); else if (ok == 2) printf("1\n%d", x); else { for (i = 0; i < n; i++) { int z = a[i] + x; if (z <= l) { if (num[z + y] == 1 || num[z - y] == 1) { printf("1\n%d", z); break; } } z = a[i] - x; if (z >= 0) { if (num[z + y] == 1 || num[z - y] == 1) { printf("1\n%d", z); break; } } z = a[i] + y; if (z <= l) { if (num[z + x] == 1 || num[z - x] == 1) { printf("1\n%d", z); break; } } z = a[i] - y; if (z >= 0) { if (num[z + x] == 1 || num[z - x] == 1) { printf("1\n%d", z); break; } } } if (i == n) printf("2\n%d %d", x, y); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int N = 100005; int n, l, x, y, tab[N], isX, isY, v, i, diff, sum; set<int> zb; int main() { scanf("%d %d %d %d", &n, &l, &x, &y); zb.clear(); for (i = 0; i < n; i++) { scanf("%d", &tab[i]); zb.insert(tab[i]); } isX = isY = 0; for (i = 0; i < n; i++) { if (zb.find(tab[i] + x) != zb.end()) { isX = 1; } if (zb.find(tab[i] + y) != zb.end()) { isY = 1; } } if (isX == 1 && isY == 1) { printf("0\n"); return 0; } if (isX == 1) { printf("1\n%d\n", y); return 0; } if (isY == 1) { printf("1\n%d\n", x); return 0; } diff = y - x; sum = y + x; for (i = 0; i < n; i++) { if (zb.find(tab[i] + diff) != zb.end()) { v = *(zb.find(tab[i] + diff)); if (tab[i] - x >= 0) { printf("1\n%d\n", tab[i] - x); return 0; } if (tab[i] + y <= l) { printf("1\n%d\n", tab[i] + y); return 0; } } if (tab[i] * 1LL + sum <= l && zb.find(tab[i] + sum) != zb.end()) { printf("1\n%d\n", tab[i] + x); return 0; } } printf("2\n%d %d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 123; int n, l, x, y; int a[maxn]; int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 0; i < n; ++i) scanf("%d", a + i); int res = 0; for (int i = 0; i < n; ++i) { if (binary_search(a, a + n, a[i] + x)) res |= 1; if (binary_search(a, a + n, a[i] + y)) res |= 2; } if (res == 3) return puts("0"), 0; else if (res == 1) return printf("1\n%d\n", y), 0; else if (res == 2) return printf("1\n%d\n", x), 0; int tans = -1; for (int i = 0; i < n && a[i] + x <= l && tans == -1; ++i) { int v = a[i] + x; if (binary_search(a, a + n, v - y) || binary_search(a, a + n, v + y)) tans = v; } for (int i = n - 1; i >= 0 && a[i] - x >= 0 && tans == -1; --i) { int v = a[i] - x; if (binary_search(a, a + n, v - y) || binary_search(a, a + n, v + y)) tans = v; } if (tans == -1) printf("2\n%d %d\n", x, y); else printf("1\n%d\n", tans); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; int a[MAX], X[MAX], Y[MAX], idxX, idxY; int main() { int n, l, x, y; scanf("%d %d %d %d", &n, &l, &x, &y); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } bool checkX = 0, checkY = 0; for (int i = 0; i < n; ++i) { if (binary_search(a, a + n, a[i] + x) || binary_search(a, a + n, a[i] - x)) { checkX = 1; } else if (!checkX) { if (a[i] + x < l) X[idxX++] = a[i] + x; if (a[i] - x >= 0) X[idxX++] = a[i] - x; } if (binary_search(a, a + n, a[i] + y) || binary_search(a, a + n, a[i] - y)) { checkY = 1; } else if (!checkY) { if (a[i] + y < l) Y[idxY++] = a[i] + y; if (a[i] - y >= 0) Y[idxY++] = a[i] - y; } } if (checkX && checkY) { printf("0"); } else if (checkX) { printf("1\n%d", Y[0]); } else if (checkY) { printf("1\n%d", X[0]); } else { sort(X, X + idxX); sort(Y, Y + idxY); for (int i = 0; i < idxX; ++i) { if (binary_search(Y, Y + idxY, X[i])) { printf("1\n%d", X[i]); return 0; } } printf("2\n%d %d", X[0], Y[0]); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y, v[100003]; int check(int q, int s) { int w = 1, r = 0; for (int i = 2; i <= n; ++i) { if (v[i] == q) { return v[i]; } while (w < i && v[i] - v[w] > q) ++w; if (v[i] - v[w] == q) { if (v[i] - s >= 0 || v[w] + s < l) return v[i]; r = v[i]; } } return r; } int main() { cin >> n >> l >> x >> y; for (int i = 1; i <= n; ++i) { cin >> v[i]; } if (!check(x, x)) { if (!check(y, y)) { int r = check(y - x, y); if (r >= y) { cout << 1 << "\n" << r - y; } else if (r && r + x <= l) { cout << 1 << "\n" << r + x; } else { r = check(x + y, x + y); if (r) { cout << 1 << "\n" << r - x; } else { cout << 2 << "\n" << x << " " << y; } } } else { cout << 1 << "\n" << x; } } else if (!check(y, y)) { cout << 1 << "\n" << y; } else { cout << 0; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; set<int> s1, s2, s3; int main() { int n, l, x, y, tem; int flag1 = 0, flag2 = 0, flag3 = 0; cin >> n >> l >> x >> y; for (int i = 1; i <= n; i++) { cin >> tem; if (s1.count(tem)) { flag1 = 1; } if (s2.count(tem)) { flag2 = 1; } if (tem - x >= 0 && tem - x <= l) { s1.insert(tem - x); } if (tem + x >= 0 && x + tem <= l) { s1.insert(tem + x); } if (tem - y >= 0 && tem - y <= l) { s2.insert(tem - y); } if (y + tem >= 0 && y + tem <= l) { s2.insert(tem + y); } } if (flag1 == 1 && flag2 == 1) { cout << 0 << endl; } if (flag1 == 0 && flag2 == 1) { cout << 1 << endl; cout << x << endl; } if (flag1 == 1 && flag2 == 0) { cout << 1 << endl; cout << y << endl; } if (flag1 == 0 && flag2 == 0) { set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), insert_iterator<set<int> >(s3, s3.begin())); if (s3.size() == 0) { cout << 2 << endl; cout << x << ' ' << y << endl; } else { cout << 1 << endl; set<int>::iterator it = s3.begin(); cout << *it << endl; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y, l; cin >> n >> l >> x >> y; set<long long> lin; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; lin.insert(a[i]); } int fl1 = 0; set<long long> boy; for (int i = 0; i < n; i++) { long long p1 = a[i] - x; long long p2 = a[i] + x; if (p1 >= 0) { if (lin.find(p1) != lin.end()) fl1 = 1; boy.insert(p1); } if (p2 <= l) { if (lin.find(p2) != lin.end()) fl1 = 1; boy.insert(p2); } } int fl2 = 0; set<long long> girl; for (int i = 0; i < n; i++) { long long p1 = a[i] - y; long long p2 = a[i] + y; if (p1 >= 0) { if (lin.find(p1) != lin.end()) fl2 = 1; girl.insert(p1); } if (p2 <= l) { if (lin.find(p2) != lin.end()) fl2 = 1; girl.insert(p2); } } if ((fl1 == 0) && (fl2 == 1)) { set<long long>::iterator it = boy.begin(); cout << 1 << endl << *it << endl; return 0; } if ((fl1 == 1) && (fl2 == 0)) { set<long long>::iterator it = girl.begin(); cout << 1 << endl << *it << endl; return 0; } if ((fl1 == 1) && (fl2 == 1)) { cout << 0 << endl; return 0; } for (set<long long>::iterator it = boy.begin(); it != boy.end(); ++it) { if (girl.find(*it) != girl.end()) { cout << 1 << endl << *it << endl; return 0; } } cout << 2 << endl; set<long long>::iterator it = girl.begin(); cout << *it << " "; set<long long>::iterator it2 = boy.begin(); cout << *it2 << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[110000]; int n, l, x, y, ok; int p1, p2, p3, p4; int sc(int s) { int i = 1; for (int j = 2; j <= n; j++) { while (a[j] - a[i] > s) i++; if (a[j] - a[i] == s) return a[i]; } return -1; } void sc2(int s) { int i = 1; for (int j = 2; j <= n; j++) { while (a[j] - a[i] > s) i++; if (a[j] - a[i] == s) { p4 = a[i]; if (p4 + y <= l || p4 - x >= 0) { return; } } } p4 = -1; } int main() { cin >> n >> l >> x >> y; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); p1 = sc(x); p2 = sc(y); p3 = sc(x + y); sc2(y - x); if (p1 != -1 && p2 != -1) printf("0\n"); else { if (p1 != -1) { printf("1\n%d\n", y); } else if (p2 != -1) { printf("1\n%d\n", x); } else if (p3 != -1) { puts("1"); printf("%d\n", p3 + x); } else if (p4 != -1) { if (p4 + y <= l) { puts("1"); printf("%d\n", p4 + y); } else if (p4 - x >= 0) { puts("1"); printf("%d\n", p4 - x); } else { printf("2\n%d %d\n", x, y); } } else printf("2\n%d %d\n", x, y); } }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, i, flaga, flagb, sc; long long l, x, y, ans; long long a[200000]; map<long long, int> bo; int main() { scanf("%d %lld %lld %lld", &n, &l, &x, &y); for (i = 0; i < n; i++) { scanf("%d", &a[i]); bo[a[i]] = 1; } for (i = 0; i < n; i++) { if (bo[a[i] + x] == 1) flaga = 1; if (bo[a[i] + y] == 1) flagb = 1; } if (flaga == 1 && flagb == 1) printf("0\n"); if (flaga == 1 && flagb == 0) { printf("1\n%lld\n", y); } if (flagb == 1 && flaga == 0) { printf("1\n%lld\n", x); } if (flaga == 0 && flagb == 0) { for (i = 0; i < n; i++) { if (bo[a[i] - x + y] == 1 && a[i] - x >= 0) { printf("1\n%lld\n", a[i] - x); sc = 1; break; } if (bo[a[i] + x - y] == 1 && a[i] + x <= l) { printf("1\n%lld\n", a[i] + x); sc = 1; break; } if (bo[a[i] - y + x] == 1 && a[i] - y >= l) { printf("1\n%lld\n", a[i] - y); sc = 1; break; } if (bo[a[i] + y - x] == 1 && a[i] + y <= l) { printf("1\n%lld\n", a[i] + y); sc = 1; break; } if (bo[a[i] + x + y] == 1) { printf("1\n%lld\n", a[i] + x); sc = 1; break; } if (bo[a[i] - x - y] == 1) { printf("1\n%lld\n", a[i] - x); sc = 1; break; } } if (sc != 1) printf("2\n%lld %lld\n", x, y); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, l, x, y, ai; cin >> n >> l >> x >> y; set<int> a; for (int i = 0; i < n; i++) { cin >> ai; a.insert(ai); } bool fx = false, fy = false; int c = -1, q = -1; for (set<int>::const_iterator it = a.begin(); it != a.end(); it++) { int val = *it; if (!fx && a.find(val + x) != a.end()) fx = true; if (!fy && a.find(val + y) != a.end()) fy = true; if (c == -1 && a.find(val + x + y) != a.end()) c = val; if (q == -1 && a.find(val + y - x) != a.end() && (val - x >= 0 || val + y <= l)) q = val; } bool z = true; if (fx && fy) cout << 0 << endl; else if (fx ^ fy) { cout << 1 << endl; cout << (fx ? y : x) << endl; } else { if (c != -1) { cout << 1 << endl; cout << (c + x) << endl; } else if (q != -1) { if (q - x >= 0) { cout << 1 << endl; cout << (q - x) << endl; } else if (q + y <= l) { cout << 1 << endl; cout << (q + y) << endl; } else z = false; } else z = false; } if (!z) { cout << 2 << endl; cout << x << " " << y << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<int> s; int n, l, x, y; void solve() { bool a = false, b = false; for (int i = 0; i < n; i++) if (lower_bound(s.begin(), s.end(), x + s[i]) != s.end()) if (*lower_bound(s.begin(), s.end(), x + s[i]) - s[i] == x) a = true; for (int i = 0; i < n; i++) if (lower_bound(s.begin(), s.end(), y + s[i]) != s.end()) if (*lower_bound(s.begin(), s.end(), y + s[i]) - s[i] == y) b = true; if (a and !b) { cout << 1 << endl << y << endl; return; }; if (b and !a) { cout << 1 << endl << x << endl; return; }; if (a and b) { cout << 0 << endl; return; } for (int i = 0; i < n; i++) if (lower_bound(s.begin(), s.end(), x + y + s[i]) != s.end()) if (*lower_bound(s.begin(), s.end(), x + y + s[i]) - s[i] == x + y) { cout << 1 << endl; cout << s[i] + x << endl; return; } for (int i = 0; i < n; i++) if (lower_bound(s.begin(), s.end(), max(x - y, y - x) + s[i]) != s.end()) if (*lower_bound(s.begin(), s.end(), max(x - y, y - x) + s[i]) - s[i] == max(x - y, y - x)) { if (s[i] + max(x, y) <= l) { cout << 1 << endl; cout << s[i] + max(x, y) << endl; return; } if (s[i] - min(x, y) >= 0) { cout << 1 << endl; cout << s[i] - min(x, y) << endl; return; } } cout << 2 << endl; cout << x << " " << y << endl; return; } int main() { cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { int a; cin >> a; s.push_back(a); } solve(); }
8
CPP
#include <bits/stdc++.h> using namespace std; map<int, int> Map; int a[100100], n, X, Y; int L; int judge0() { int f0(0), f1(0); for (int(i) = (1), (_end_) = (n); (i) <= (_end_); ++(i)) { if (Map.count(a[i] - X) || Map.count(a[i] + X)) f0 = 1; if (Map.count(a[i] - Y) || Map.count(a[i] + Y)) f1 = 1; } return f0 * 2 + f1; } int judge1() { for (int(i) = (1), (_end_) = (n); (i) <= (_end_); ++(i)) { if (a[i] + X <= L && Map.count(a[i] + X - Y)) return a[i] + X; if (a[i] + Y <= L && Map.count(a[i] + Y - X)) return a[i] + Y; if (a[i] - X >= 0 && Map.count(a[i] - X + Y)) return a[i] - X; if (a[i] - Y >= 0 && Map.count(a[i] - Y + X)) return a[i] - Y; if (Map.count(a[i] + X + Y)) return a[i] + X; if (Map.count(a[i] - X - Y)) return a[i] - X; } return -1; } int main() { int m; scanf("%d%d%d%d", &n, &L, &X, &Y); for (int(i) = (1), (_end_) = (n); (i) <= (_end_); ++(i)) { scanf("%d", &a[i]); Map[a[i]] = 1; } if ((m = judge0())) { if (m == 3) printf("0\n"); if (m == 1) printf("1\n%d\n", X); if (m == 2) printf("1\n%d\n", Y); } else if ((m = judge1()) != -1) printf("%d\n%d\n", 1, m); else printf("2\n%d %d\n", X, Y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6; const int inf = (int)2e9; const double eps = 1e-9; const int mod = (int)1e9 + 7; int n, l, x, y, a[maxn], ok1, ok2; map<int, int> was; bool check(int v) { if (v >= 0 && v <= l && (was.count(v - x) || was.count(v + x) || ok1) && (ok2 || was.count(v - y) || was.count(v + y))) return true; return false; } int main() { scanf("%d%d%d%d", &n, &l, &x, &y); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); if (was.count(a[i] - x)) ok1 = true; if (was.count(a[i] - y)) ok2 = true; was[a[i]] = true; } if (ok1 && ok2) { puts("0"); return 0; } for (int i = 1; i <= n; ++i) { if (check(a[i] - x)) { puts("1"); cout << a[i] - x << '\n'; return 0; } if (check(a[i] - y)) { puts("1"); cout << a[i] - y << '\n'; return 0; } if (check(a[i] + x)) { puts("1"); cout << a[i] + x << '\n'; return 0; } if (check(a[i] + y)) { puts("1"); cout << a[i] + y << '\n'; return 0; } } puts("2"); cout << x << ' ' << y << '\n'; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0ULL >> 1; template <class T> inline void read(T &n) { char c; for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar()) ; n = c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0'; } int Pow(int base, int n, int mo) { if (n == 0) return 1; if (n == 1) return base % mo; int tmp = Pow(base, n >> 1, mo); tmp = (long long)tmp * tmp % mo; if (n & 1) tmp = (long long)tmp * base % mo; return tmp; } int n; long long l, x, y, a[200000]; map<long long, int> b; int main() { scanf("%d%I64d%I64d%I64d", &n, &l, &x, &y); if (x > y) swap(x, y); for (int i = (1); i <= (n); ++i) scanf("%I64d", &a[i]), b[a[i]] = 1; int f1 = 0, f2 = 0; for (int i = (1); i <= (n); ++i) { if (b[a[i] - x] || b[a[i] + x]) f1 = 1; if (b[a[i] - y] || b[a[i] + y]) f2 = 1; } if (f1 && f2) { puts("0"); return 0; } if (f1 || f2) { if (!f1) { puts("1"); printf("%I64d\n", x); } else { puts("1"); printf("%I64d\n", y); } return 0; } else { for (int i = (1); i <= (n); ++i) { if (b[a[i] + x + y]) { puts("1"); printf("%I64d\n", a[i] + x); return 0; } } for (int i = (1); i <= (n); ++i) { long long ans = a[i] + y; if (ans <= l) { if (b[ans - x]) { puts("1"); printf("%I64d\n", ans); return 0; } } ans = a[i] - x; if (ans >= 0) { if (b[ans + y]) { puts("1"); printf("%I64d\n", ans); return 0; } } } } puts("2"); printf("%I64d %I64d\n", x, y); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, l, x, y; int a[100005]; set<int> b; int found1(int k) { for (int i = 1; i <= n; i++) if (b.count(a[i] - k)) return 1; return 0; } int found2() { for (int i = 1; i <= n; i++) { if (a[i] + x <= l && (b.count(a[i] + x + y) || b.count(a[i] + x - y))) return a[i] + x; if (a[i] - x >= 0 && (b.count(a[i] - x + y) || b.count(a[i] - x - y))) return a[i] - x; } return -1; } int main() { cin >> n >> l >> x >> y; for (int i = 1; i <= n; i++) { cin >> a[i]; b.insert(a[i]); } int a1 = 0; int a2 = 0; a1 = found1(x); a2 = found1(y); if (a1 && a2) cout << "0" << endl; else if (a1 && !a2) cout << "1" << endl << y << endl; else if (!a1 && a2) cout << "1" << endl << x << endl; else { int te = found2(); if (te == -1) cout << "2" << endl << x << ' ' << y << endl; else cout << "1" << endl << te << endl; } return 0; }
8
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; void solve() { long long int n, l; cin >> n >> l; long long int arr[2]; cin >> arr[0] >> arr[1]; sort(arr, arr + 2); set<long long int> marks; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; marks.insert(x); } map<long long int, long long int> mpp; bool flag1 = false, flag2 = false; for (long long int x : marks) { long long int req1 = arr[0] + x; long long int req2 = x - arr[0]; if (req1 <= l) { if (marks.count(req1)) flag1 = true; else { mpp[-req1] = 1; } } if (req2 >= 0) { if (marks.count(req2)) flag1 = true; else mpp[-req2] = 1; } } bool flag3 = false; for (long long int y : marks) { long long int req1 = arr[1] + y; long long int req2 = y - arr[1]; if (req1 <= l) { if (marks.count(req1)) flag2 = true; else if (mpp.find(-req1) != mpp.end()) { mpp[-req1]++; flag3 = true; } else mpp[req1]++; } if (req2 >= 0) { if (marks.count(req2)) flag2 = true; else if (mpp.find(-req2) != mpp.end()) { mpp[-req2]++; flag3 = true; } else mpp[req2]++; } } if (flag1 && flag2) cout << 0; else if (!flag1 && flag2) { for (auto x : mpp) { if (x.first < 0) { cout << 1 << "\n"; cout << -x.first; return; } } } else if (flag1 && !flag2) { for (auto x : mpp) { if (x.first > 0) { cout << 1 << "\n"; cout << abs(x.first); return; } } } else { if (flag3) { cout << 1 << "\n"; for (auto x : mpp) { if (x.second == 2) { cout << -x.first; return; } } } cout << 2 << "\n"; vector<long long int> temp; for (auto x : mpp) { if (x.first > 0) { temp.push_back(x.first); break; } } for (auto x : mpp) { if (x.first < 0) { temp.push_back(-x.first); break; } } sort(temp.begin(), temp.end()); cout << temp[0] << " " << temp[1]; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { solve(); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; int n, a[MAXN], k; bool search(int x, bool ch) { int e, s; s = e = (ch ? n - 1 : 0); for (s; (ch ? s >= 0 : s < n); (ch ? (e >= 0, s--) : (e < n, s++))) { while ((ch ? e >= 0 : e < n) && abs(a[e] - a[s]) < x) (ch ? e-- : e++); if ((ch ? e >= 0 : e < n) && abs(a[e] - a[s]) == x) return 1, k = e; } return 0; } void chap(int x) { cout << 1 << endl << x << endl; exit(0); } int main() { ios_base::sync_with_stdio(0); int x, y, l; bool ch1, ch2; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) cin >> a[i]; ch1 = search(x, 0); ch2 = search(y, 0); if (ch1 || ch2) { if (ch1 ^ ch2) chap((ch1 ? y : x)); else cout << '0' << endl; return 0; } if (search(x + y, 0)) chap(a[k] - y); if (search(y - x, 0) && a[k] + x < l) chap(a[k] + x); if (search(y - x, 1) && a[k] - x > 0) chap(a[k] - x); cout << 2 << endl << x << endl << y << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<int> v(0); int main() { int n, l, x, y; cin >> n >> l >> x >> y; for (int i = (0); i < (n); i++) { int tmp; cin >> tmp; v.push_back(tmp); } bool isx = false, isy = false, isxpy = false, isxmy = false; int xpyp = -1, xmyp = -1; int fxmyp = -1; int xpy = x + y, xmy = abs(x - y); for (int i = (0); i < (n - 1); i++) { if (binary_search(v.begin() + i, v.end(), v[i] + x)) isx = true; if (binary_search(v.begin() + i, v.end(), v[i] + y)) isy = true; if (binary_search(v.begin() + i, v.end(), v[i] + xpy)) { isxpy = true; xpyp = i; } if (binary_search(v.begin() + i, v.end(), v[i] + xmy)) { isxmy = true; xmyp = i; if (fxmyp == -1) fxmyp = i; } } if (isx && isy) { cout << 0; return 0; } if (isx || isy) { if (isx) { cout << 1 << ' ' << y; return 0; } else { cout << 1 << ' ' << x; return 0; } } if (!isxpy && !isxmy) { cout << 2 << ' ' << x << ' ' << y; return 0; } if (isxpy) { cout << 1 << ' ' << v[xpyp] + x; return 0; } if (isxmy) { int a = max(x, y); if (v[xmyp] + a < l) { cout << 1 << ' ' << v[xmyp] + a; return 0; } else if (v[xmyp] - a + xmy > 0) { cout << 1 << ' ' << v[xmyp] - a + xmy; return 0; } if (v[fxmyp] + a < l) { cout << 1 << ' ' << v[fxmyp] + a; return 0; } else if (v[fxmyp] - a + xmy > 0) { cout << 1 << ' ' << v[fxmyp] - a + xmy; return 0; } else { cout << 2 << ' ' << x << ' ' << y; return 0; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int n; long long l, x, y; vector<long long> val; int main() { scanf("%d %lld %lld %lld", &n, &l, &x, &y); for (int i = 0; i < n; i++) { long long a; scanf("%lld", &a); val.push_back(a); } bool ex = 0, ey = 0; for (int i = 0; i < n; i++) { if (binary_search(val.begin(), val.end(), val[i] + x)) { ex = true; } if (binary_search(val.begin(), val.end(), val[i] + y)) { ey = true; } } if (ex && ey) { puts("0"); return 0; } long long a[4]; bool ok = false; long long res = -1; for (int i = 0; i < n && !ok; i++) { a[0] = val[i] - x; a[1] = val[i] - y; a[2] = val[i] + x; a[3] = val[i] + y; for (int j = 0; j < 4 && !ok; j++) { if (!(0 <= a[j] && a[j] <= l)) continue; if (j % 2 == 0) { if (binary_search(val.begin(), val.end(), a[j] - y) || ey) { ok = true; res = a[j]; } if (binary_search(val.begin(), val.end(), a[j] + y) || ey) { ok = true; res = a[j]; } } else { if (binary_search(val.begin(), val.end(), a[j] - x) || ex) { ok = true; res = a[j]; } if (binary_search(val.begin(), val.end(), a[j] + x) || ex) { ok = true; res = a[j]; } } } } if (ok) { printf("1\n%lld\n", res); return 0; } else { printf("2\n%lld %lld\n", x, y); return 0; } }
8
CPP