problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02640
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; bool flag = false; for (int l = 0; l <= n; l++) { if (((l * 2) + ((n - l) * 4)) == k) { flag = true; break; } } flag ? cout << "Yes\n" : cout << "No\n"; main(); return 0; }
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; bool flag = false; for (int l = 0; l <= n; l++) { if (((l * 2) + ((n - l) * 4)) == k) { flag = true; break; } } flag ? cout << "Yes\n" : cout << "No\n"; // main(); return 0; }
replace
13
14
13
14
TLE
p02640
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long double pi = 3.14159265358979323846; #define x first #define y second int main() { cin.tie(0); cin.sync_with_stdio(0); ll t = 1; // cin>>t; while (t--) { ll x, y; cin >> x >> y; if (y % x == 0 && y / x == 4) cout << "Yes"; else if (y % x == 0 && y / x == 2) cout << "Yes"; else if (y > x * 4 || y < x * 2) cout << "No"; else { while (x && y) { y -= 4; x--; if (y % x == 0 && y / x == 2) { cout << "Yes"; return 0; } } cout << "No"; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long double pi = 3.14159265358979323846; #define x first #define y second int main() { cin.tie(0); cin.sync_with_stdio(0); ll t = 1; // cin>>t; while (t--) { ll x, y; cin >> x >> y; if (y % x == 0 && y / x == 4) cout << "Yes"; else if (y % x == 0 && y / x == 2) cout << "Yes"; else if (y > x * 4 || y < x * 2) cout << "No"; else { while (x && y) { y -= 4; x--; if (!x) break; if (!y) break; if (y % x == 0 && y / x == 2) { cout << "Yes"; return 0; } } cout << "No"; } } return 0; }
insert
26
26
26
30
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int x, n; cin >> x >> n; vector<int> vec(102); rep(i, n) { int a = 0; cin >> a; vec.at(a)++; } int ans = 200; for (int i = x; i >= 0; i--) { if (vec.at(i) == 0) { ans = i; break; } } for (int i = x; i < 210; i++) { if (vec.at(i) == 0 && ans == 200) { ans = i; break; } else if (vec.at(i) == 0 && ans != 200 && x - ans > i - x) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int x, n; cin >> x >> n; vector<int> vec(300); rep(i, n) { int a = 0; cin >> a; vec.at(a)++; } int ans = 200; for (int i = x; i >= 0; i--) { if (vec.at(i) == 0) { ans = i; break; } } for (int i = x; i < 210; i++) { if (vec.at(i) == 0 && ans == 200) { ans = i; break; } else if (vec.at(i) == 0 && ans != 200 && x - ans > i - x) { ans = i; break; } } cout << ans << endl; }
replace
11
12
11
12
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using namespace __detail; typedef long long ll; #define ar array #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define fork(i, n) for (ll i = 0; i < (n); i++) #define forn for (ll i = 0; i < (n); i++) #define fori(i, k, n) for (ll i = k; i < (n); i++) #define all(x) (x).begin(), (x).end() #define en '\n' #define FILL(x, v) memset(x, v, sizeof(x)) #define pb push_back #define fast \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> void print(vector<T> &a) { for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; cout << en; } template <typename T> void print(deque<T> &a) { for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; cout << en; } template <typename T> void print(vector<vector<T>> &a) { for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << ' '; cout << en; } } int main() { fast; int x, n; cin >> x >> n; vector<bool> a(n + 1, 0); if (n == 0) { cout << x << en; return 0; } forn { int t; cin >> t; if (t < 0) continue; a[t] = 1; } int ans, cur = 1e9 + 5; for (int i = x + n; i >= x - n; i--) { if (a[i]) continue; // cout << i << en; int dif = abs(i - x); if (dif <= cur) { cur = dif; ans = i; } } cout << ans << en; }
#include <bits/stdc++.h> using namespace std; using namespace __detail; typedef long long ll; #define ar array #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define fork(i, n) for (ll i = 0; i < (n); i++) #define forn for (ll i = 0; i < (n); i++) #define fori(i, k, n) for (ll i = k; i < (n); i++) #define all(x) (x).begin(), (x).end() #define en '\n' #define FILL(x, v) memset(x, v, sizeof(x)) #define pb push_back #define fast \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> void print(vector<T> &a) { for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; cout << en; } template <typename T> void print(deque<T> &a) { for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; cout << en; } template <typename T> void print(vector<vector<T>> &a) { for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << ' '; cout << en; } } int main() { fast; int x, n; cin >> x >> n; vector<bool> a(n + 1, 0); if (n == 0) { cout << x << en; return 0; } forn { int t; cin >> t; if (t < 0) continue; a[t] = 1; } int ans, cur = 1e9 + 5; for (int i = x + n; i >= 0 && i >= x - n; i--) { if (a[i]) continue; // cout << i << en; int dif = abs(i - x); if (dif <= cur) { cur = dif; ans = i; } } cout << ans << en; }
replace
64
65
64
65
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int x, n; int p[105]; int mi, minv, maxv = 0, ans = 0; int flg[105] = {}; cin >> x >> n; for (int i = 0; i < n; i++) { cin >> p[i]; flg[p[i]] = 1; maxv = max(p[i], maxv); minv = min(p[i], minv); } mi = (x - (minv - 1)); ans = minv - 1; if (n == 0) { cout << x << '\n'; } else { for (int i = minv; i <= maxv + 1; i++) { if (mi > abs(x - i)) { if (flg[i] != 1) { mi = abs(x - i); ans = i; } } } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, n; int p[105]; int mi, minv, maxv = 0, ans = 0; int flg[105] = {}; cin >> x >> n; minv = 105; for (int i = 0; i < n; i++) { cin >> p[i]; flg[p[i]] = 1; maxv = max(p[i], maxv); minv = min(p[i], minv); } mi = (x - (minv - 1)); ans = minv - 1; if (n == 0) { cout << x << '\n'; } else { for (int i = minv; i <= maxv + 1; i++) { if (mi > abs(x - i)) { if (flg[i] != 1) { mi = abs(x - i); ans = i; } } } cout << ans << '\n'; } return 0; }
insert
8
8
8
9
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int X, N; cin >> X >> N; int p[N]; for (int i = 0; i < N; i++) cin >> p[i]; int Min = 1000; int ans = 1000; sort(p, p + N); for (int i = -1000; i <= 1000; i++) { if (p[i] == i) continue; int num = abs(X - i); if (Min > num) { ans = i; Min = num; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int X, N; cin >> X >> N; int p[N]; for (int i = 0; i < N; i++) cin >> p[i]; int Min = 1000; int ans = 1000; sort(p, p + N); for (int i = 0; i <= 101; i++) { bool flag = true; for (int j = 0; j < N; j++) { if (p[j] == i) flag = false; } if (!flag) continue; int num = abs(X - i); if (Min > num) { ans = i; Min = num; } } cout << ans << endl; return 0; }
replace
14
16
14
21
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(k, i, n) for (ll i = k; i < n; ++i) #define push_back pb int main(void) { // Your code here! ll x, n; cin >> x >> n; vector<ll> a(n); rep(0, i, n) { cin >> a[i]; } sort(a.begin(), a.end()); ll m = 1e9, ans, c = 0; rep(0, i, 110) { if (a[c] == i && c < n) { ++c; continue; } ll d = abs(i - x); if (d < m) { m = d; ans = i; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(k, i, n) for (ll i = k; i < n; ++i) #define push_back pb int main(void) { // Your code here! ll x, n; cin >> x >> n; vector<ll> a(n); rep(0, i, n) { cin >> a[i]; } sort(a.begin(), a.end()); ll m = 1e9, ans, c = 0; rep(0, i, 110) { if (c < n && a[c] == i) { ++c; continue; } ll d = abs(i - x); if (d < m) { m = d; ans = i; } } cout << ans; }
replace
14
15
14
15
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int X, N, ans; cin >> X >> N; vector<bool> all(100, false); vector<int> p(N); for (int i = 0; i < N; i++) { cin >> p.at(i); all.at(p.at(i) - 1) = true; } // sort(p.begin(),p.end(),greater<int>()); for (int i = 0; i < 101; i++) { if ((X - i - 1 >= 0) && (all.at(X - i - 1) == false)) { ans = X - i; break; } else if ((X + i - 1 < 101) && (all.at(X + i - 1) == false)) { ans = X + i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int X, N, ans; cin >> X >> N; vector<bool> all(100, false); vector<int> p(N); for (int i = 0; i < N; i++) { cin >> p.at(i); all.at(p.at(i) - 1) = true; } // sort(p.begin(),p.end(),greater<int>()); for (int i = 0; i < 101; i++) { if ((X - i - 1 >= 0) && (all.at(X - i - 1) == false)) { ans = X - i; break; } else if (X - i - 1 < 0) { ans = X - i; break; } else if ((X + i - 1 < 100) && (all.at(X + i - 1) == false)) { ans = X + i; break; } else if (X + i - 1 >= 100) { ans = X + i; break; } } cout << ans << endl; }
replace
18
19
18
25
0
p02641
C++
Runtime Error
#define rep(i, n) for (int i = 0; i < (n); i++) #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const int MOD = 1000000007; // MAX int 2,147,483,647 -> 10桁 // MAX ll 9,223,372,036,854,775,807 -> 19桁 // MAX O(n) 10^18 -> 18回 int main() { int x, n; cin >> x >> n; vector<int> d(n); rep(i, n) { int p; cin >> p; d[p] = 1; } P ans(999999, -1); for (int i = 0; i <= 101; i++) { if (d[i] == 1) continue; int dif = abs(x - i); ans = min(ans, P(dif, i)); } cout << ans.second << endl; return 0; }
#define rep(i, n) for (int i = 0; i < (n); i++) #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const int MOD = 1000000007; // MAX int 2,147,483,647 -> 10桁 // MAX ll 9,223,372,036,854,775,807 -> 19桁 // MAX O(n) 10^18 -> 18回 int main() { int x, n; cin >> x >> n; vector<int> d(102); rep(i, n) { int p; cin >> p; d[p] = 1; } P ans(999999, -1); for (int i = 0; i <= 101; i++) { if (d[i] == 1) continue; int dif = abs(x - i); ans = min(ans, P(dif, i)); } cout << ans.second << endl; return 0; }
replace
13
14
13
14
-6
malloc(): corrupted top size
p02641
C++
Runtime Error
/// Bismillahir Rahmanir Rahim // Author: Tanvir Hussain // ICE,NSTU #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; const long long MOD = 1000000007; #define SET(x) memset(x, 0, sizeof(x)) #define SET2d(x, m, n) memset(x, 0, sizeof(x[0][0]) * m * n) #define SETBOOL(x) memset(x, false, sizeof(x)) #define CLR(x) memset(x, -1, sizeof(x)) #define mp make_pair #define PII pair<int, int> #define pf printf #define sf scanf #define ALL(x) x.begin(), x.end() #define pb push_back #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define np std::string::npos #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() #define Inf INFINITY #define minv(v) *min_element(v.begin(), v.end()) #define maxv(v) *max_element(v.begin(), v.end()) #define cases(cs, t) for (int cs = 1; cs <= t; cs++) #define PI acos(-1) #define no1 __builtin_popcount #define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column)) #define uniq(vec) \ vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end()))) #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define sz(a) int(a.size()) #define ff first #define ss second #define endl "\n" #define forch(it, s) for (auto it : s) #define each(it, s) for (auto it = s.begin(); it != s.end(); ++it) #define rep(i, a) for (int i = 0; i < a; i++) #define rep1(i, a, b) for (int i = (a); i <= (b); ++i) #define irep(i, b, a) for (int i = (b); i >= (a); --i) #define bits(n) __builtin_popcount(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; const int maxx = 100005; // this fuction sorts vector pair according to first element in descending // order. bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return a.first > b.first; } template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } double sq(double x) { return x * x; } void solve() { int n, x; cin >> x >> n; vector<bool> mark(n); rep(i, n) { int a; cin >> a; mark[a] = 1; } int mini = highest(int), ans = -1; rep1(i, 0, 110) { if (!mark[i]) { int val = abs(i - x); if (val < mini) { mini = val; ans = i; } } } cout << ans << endl; } signed main() { IOS; /*#ifndef ONLINE_JUDGE freopen ("data.in","r",stdin); freopen ("data.out","w",stdout); #endif*/ int t; t = 1; while (t--) { solve(); } return 0; } /// Alhamdulillah
/// Bismillahir Rahmanir Rahim // Author: Tanvir Hussain // ICE,NSTU #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; const long long MOD = 1000000007; #define SET(x) memset(x, 0, sizeof(x)) #define SET2d(x, m, n) memset(x, 0, sizeof(x[0][0]) * m * n) #define SETBOOL(x) memset(x, false, sizeof(x)) #define CLR(x) memset(x, -1, sizeof(x)) #define mp make_pair #define PII pair<int, int> #define pf printf #define sf scanf #define ALL(x) x.begin(), x.end() #define pb push_back #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define np std::string::npos #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() #define Inf INFINITY #define minv(v) *min_element(v.begin(), v.end()) #define maxv(v) *max_element(v.begin(), v.end()) #define cases(cs, t) for (int cs = 1; cs <= t; cs++) #define PI acos(-1) #define no1 __builtin_popcount #define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column)) #define uniq(vec) \ vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end()))) #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define sz(a) int(a.size()) #define ff first #define ss second #define endl "\n" #define forch(it, s) for (auto it : s) #define each(it, s) for (auto it = s.begin(); it != s.end(); ++it) #define rep(i, a) for (int i = 0; i < a; i++) #define rep1(i, a, b) for (int i = (a); i <= (b); ++i) #define irep(i, b, a) for (int i = (b); i >= (a); --i) #define bits(n) __builtin_popcount(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; const int maxx = 100005; // this fuction sorts vector pair according to first element in descending // order. bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return a.first > b.first; } template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } double sq(double x) { return x * x; } void solve() { int n, x; cin >> x >> n; vector<bool> mark(110); rep(i, n) { int a; cin >> a; mark[a] = 1; } int mini = highest(int), ans = -1; rep1(i, 0, 110) { if (!mark[i]) { int val = abs(i - x); if (val < mini) { mini = val; ans = i; } } } cout << ans << endl; } signed main() { IOS; /*#ifndef ONLINE_JUDGE freopen ("data.in","r",stdin); freopen ("data.out","w",stdout); #endif*/ int t; t = 1; while (t--) { solve(); } return 0; } /// Alhamdulillah
replace
88
89
88
89
0
p02641
C++
Runtime Error
#include <algorithm> #include <iostream> int main() { int X, N, *p, dif = 1, num = -1; std::cin >> X >> N; p = new int[N + 2]; for (int i = 0; i < N; i++) { std::cin >> p[i]; } p[N + 1] = -1000; p[N + 2] = 1000; std::sort(p, p + N); for (int i = 0; i < N; i++) { if (p[i] == X) num = i; } if (num == -1) { std::cout << X; exit(0); } while (true) { if (p[num - dif] != X - dif) { std::cout << X - dif; break; } if (p[num + dif] != X + dif) { std::cout << X + dif; break; } dif += 1; } }
#include <algorithm> #include <iostream> int main() { int X, N, *p, dif = 1, num = -1; std::cin >> X >> N; p = new int[N + 2]; for (int i = 0; i < N; i++) { std::cin >> p[i]; } p[N] = -1000; p[N + 1] = 1000; std::sort(p, p + N + 2); for (int i = 1; i < N + 1; i++) { if (p[i] == X) num = i; } if (num == -1) { std::cout << X; exit(0); } while (true) { if (p[num - dif] != X - dif) { std::cout << X - dif; break; } if (p[num + dif] != X + dif) { std::cout << X + dif; break; } dif += 1; } }
replace
10
14
10
14
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; return 0; } vector<int> a(n), b(0); rep(i, n) cin >> a[i]; sort(all(a)); int j = 0; rep(i, 100) { if (i + 1 != a[j]) { b.push_back(i + 1); // cout << i+1 << endl; } else j++; } int l = b.size(); vector<int> c(l); rep(i, l) c[i] = abs(b[i] - x); sort(all(c)); int d = c[0]; // cout << d << endl; rep(i, n) { if (b[i] == x - d) { cout << x - d << endl; return 0; } else if (x - d <= 0) { cout << 0 << endl; return 0; } else if (b[i] == x + d) { cout << x + d << endl; return 0; } else if (x + d >= 101) { cout << 101 << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; return 0; } vector<int> a(n), b(0); rep(i, n) cin >> a[i]; sort(all(a)); int j = 0; rep(i, 100) { if (i + 1 != a[j]) { b.push_back(i + 1); // cout << i+1 << endl; } else j++; } int l = b.size(); if (l == 0) { if (x <= 50) { cout << 0 << endl; return 0; } else { cout << 101 << endl; return 0; } } vector<int> c(l); rep(i, l) c[i] = abs(b[i] - x); sort(all(c)); int d = c[0]; // cout << d << endl; rep(i, n) { if (b[i] == x - d) { cout << x - d << endl; return 0; } else if (x - d <= 0) { cout << 0 << endl; return 0; } else if (b[i] == x + d) { cout << x + d << endl; return 0; } else if (x + d >= 101) { cout << 101 << endl; return 0; } } return 0; }
insert
47
47
47
57
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) #define mset(s, _) memset(s, _, sizeof s) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; // head int a[110]; void run() { int n, x; cin >> x >> n; for (int i = 1; i <= n; i++) { int tp; cin >> tp; a[tp] = 1; } if (n == 0) { cout << x << '\n'; return; } int ans = 0; int pre = 1000, pos = 0; for (int i = -1000; i <= 1000; i++) { if (!a[i] && abs(i - x) < pre) pos = i, pre = abs(i - x); } cout << pos << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); // int T; cin >> T; while (T--) run(); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) #define mset(s, _) memset(s, _, sizeof s) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; // head map<int, int> a; void run() { int n, x; cin >> x >> n; for (int i = 1; i <= n; i++) { int tp; cin >> tp; a[tp] = 1; } if (n == 0) { cout << x << '\n'; return; } int ans = 0; int pre = 1000, pos = 0; for (int i = -1000; i <= 1000; i++) { if (!a[i] && abs(i - x) < pre) pos = i, pre = abs(i - x); } cout << pos << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); // int T; cin >> T; while (T--) run(); return 0; }
replace
12
13
12
13
-11
p02641
C++
Runtime Error
#include <bits/stdc++.h> #include <cassert> #include <numeric> using namespace std; typedef long long ll; typedef long double ld; using graph = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using qi = queue<int>; using qpii = queue<pii>; using pqi = priority_queue<int>; using pqr = priority_queue<int, vector<int>, greater<int>>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repd(i, n) for (ll i = n - 1; i >= 0; i--) #define F(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define sd(x) sort(x.rbegin(), x.rend()) // xにはvectorなどのコンテナ #define all(x) x.begin(), x.end() #define size(x) ((ll)(x).size()) #define ma(x) *max_element(all(x)) #define mi(x) *min_element(all(x)) #define so(x) sort(all(a)); #define INF 1000000000000 #define M 10000007 #define MAXR 100000 #define pb push_back #define mp make_pair #define f first #define s second #define fi(x, y) find(all(x), y) != x.end() #define dfi(x, y) find(all(x), y) == x.end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return true; } return false; } template <class T> inline int rt(T a, T b) { if (a % b == 0) return a / b; else return a / b + 1; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; #define bit(n) (1LL << (n)) #define U(v) v.erase(unique(v.begin(), v.end()), v.end()); #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; #define fe(x, a) for (auto &(x) : (a)) #define vin(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define vout(x) \ for (auto &youso_ : (x)) \ cout << youso_ << " " #define sco(x) cout << (x) << " " #define co(x) cout << (x) << endl #define en cout << endl #define gl goto la #define r0 return 0 void CINT() {} template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) { cin >> head; CINT(move(tail)...); } #define vi vector<int> #define vll vector<ll> #define vd vector<double> #define vld vector<ld> #define vs vector<string> #define ci(...) \ int __VA_ARGS__; \ CINT(__VA_ARGS__) #define cd(...) \ double __VA_ARGS__; \ CINT(__VA_ARGS__) #define cld(...) \ ld __VA_ARGS__; \ CINT(__VA_ARGS__) #define cll(...) \ ll __VA_ARGS__; \ CINT(__VA_ARGS__) #define cs(...) \ string __VA_ARGS__; \ CINT(__VA_ARGS__) struct uf { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> rcount; uf(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; const ll MOD = 1000000007; using mint = Fp<MOD>; mint powm(ll a, ll b) { mint re = 1; rep(i, b) re *= a; return re; } int main() { ci(x, n); vector<int> a(n); vector<pii> s; vin(a); F(i, 1, 100) { if (dfi(a, i)) { s.pb(mp(abs(x - i), i)); } } sd(s); co(s[size(s) - 1].s); }
#include <bits/stdc++.h> #include <cassert> #include <numeric> using namespace std; typedef long long ll; typedef long double ld; using graph = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using qi = queue<int>; using qpii = queue<pii>; using pqi = priority_queue<int>; using pqr = priority_queue<int, vector<int>, greater<int>>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repd(i, n) for (ll i = n - 1; i >= 0; i--) #define F(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define sd(x) sort(x.rbegin(), x.rend()) // xにはvectorなどのコンテナ #define all(x) x.begin(), x.end() #define size(x) ((ll)(x).size()) #define ma(x) *max_element(all(x)) #define mi(x) *min_element(all(x)) #define so(x) sort(all(a)); #define INF 1000000000000 #define M 10000007 #define MAXR 100000 #define pb push_back #define mp make_pair #define f first #define s second #define fi(x, y) find(all(x), y) != x.end() #define dfi(x, y) find(all(x), y) == x.end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return true; } return false; } template <class T> inline int rt(T a, T b) { if (a % b == 0) return a / b; else return a / b + 1; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; #define bit(n) (1LL << (n)) #define U(v) v.erase(unique(v.begin(), v.end()), v.end()); #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; #define fe(x, a) for (auto &(x) : (a)) #define vin(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define vout(x) \ for (auto &youso_ : (x)) \ cout << youso_ << " " #define sco(x) cout << (x) << " " #define co(x) cout << (x) << endl #define en cout << endl #define gl goto la #define r0 return 0 void CINT() {} template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) { cin >> head; CINT(move(tail)...); } #define vi vector<int> #define vll vector<ll> #define vd vector<double> #define vld vector<ld> #define vs vector<string> #define ci(...) \ int __VA_ARGS__; \ CINT(__VA_ARGS__) #define cd(...) \ double __VA_ARGS__; \ CINT(__VA_ARGS__) #define cld(...) \ ld __VA_ARGS__; \ CINT(__VA_ARGS__) #define cll(...) \ ll __VA_ARGS__; \ CINT(__VA_ARGS__) #define cs(...) \ string __VA_ARGS__; \ CINT(__VA_ARGS__) struct uf { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> rcount; uf(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; const ll MOD = 1000000007; using mint = Fp<MOD>; mint powm(ll a, ll b) { mint re = 1; rep(i, b) re *= a; return re; } int main() { ci(x, n); vector<int> a(n); vector<pii> s; vin(a); F(i, 0, 200) { if (dfi(a, i)) { s.pb(mp(abs(x - i), i)); } } sd(s); co(s[size(s) - 1].s); }
replace
213
214
213
214
0
p02641
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define ALL(a) (a).begin(), (a).end() #define REP(i, n) for (size_t i = 0; i < (n); i++) #define nvec(T, v, n) \ vector<T> v(n); \ REP(i, n) { cin >> (v)[i]; } #define npairs(T1, T2, v, n) \ vector<pair<T1, T2>> v(n); \ REP(i, n) { cin >> v[i].first >> v[i].second; } #define ntuples(T1, T2, T3, v, n) \ vector<tuple<T1, T2, T3>> v(n); \ REP(i, n) { cin >> get<0>(v[i]) >> get<1>(v[i]) >> get<2>(v[i]); } #define vec2d(T, v, m, n) vector<vector<T>>(v)(m, vector<T>(n)) #define nvec2d(T, v, m, n) \ vec2d(T, v, m, n); \ REP(j, m) { \ REP(i, n) { cin >> (v[j])[i]; } \ } #define min_index(v) size_t(min_element(all(v)) - (v).begin()) #define max_index(v) size_t(max_element(all(v)) - (v).begin()) #define min_e(v) *min_element(ALL(v)) #define max_e(v) *max_element(ALL(v)) #define count_le(v, a) size_t(upper_bound(ALL(v), a) - (v).begin()) #define count_lt(v, a) size_t(lower_bound(ALL(v), a) - (v).begin()) #define count_ge(v, a) size_t((v).end() - lower_bound(ALL(v), a)) #define count_gt(v, a) size_t((v).end() - upper_bound(ALL(v), a)) #define order(neq_sl) [](const auto s, const auto l) { return neq_sl; } #define make_lr(v, type, l, r) \ vector<type> l(n + 1), r(n + 1); \ FOR(i, n) { \ l[i + 1] = l[i] + v[i]; \ r[i + 1] = r[i] + v[n - 1 - i]; \ } #define acm accumulate #define SUM(v) accumulate(ALL(v), 0l) #define SORT(v) sort(ALL(v)) #define GCD(v) gcd(ALL(v), 0l) /*template <typename T> T gcd(T a, T b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b%a, a); } template <typename InputItr, typename T> T gcd(InputItr first, InputItr last, T init) { for (; first != last; ++first) init = gcd(init, *first); return init; }*/ template <typename T> using vec = vector<T>; template <typename T> using vvec = vector<vector<T>>; int main() { int x, n; cin >> x >> n; nvec(int, p, n); vec<pair<int, int>> q; for (int i = 1; i < 101; i++) { bool a = 1; for (int j = 0; j < n; j++) { if (i == p[j]) a = 0; } if (a == 1) q.push_back(make_pair(abs(x - i), i)); } SORT(q); cout << q[0].second; } /* きょむ〜 */
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define ALL(a) (a).begin(), (a).end() #define REP(i, n) for (size_t i = 0; i < (n); i++) #define nvec(T, v, n) \ vector<T> v(n); \ REP(i, n) { cin >> (v)[i]; } #define npairs(T1, T2, v, n) \ vector<pair<T1, T2>> v(n); \ REP(i, n) { cin >> v[i].first >> v[i].second; } #define ntuples(T1, T2, T3, v, n) \ vector<tuple<T1, T2, T3>> v(n); \ REP(i, n) { cin >> get<0>(v[i]) >> get<1>(v[i]) >> get<2>(v[i]); } #define vec2d(T, v, m, n) vector<vector<T>>(v)(m, vector<T>(n)) #define nvec2d(T, v, m, n) \ vec2d(T, v, m, n); \ REP(j, m) { \ REP(i, n) { cin >> (v[j])[i]; } \ } #define min_index(v) size_t(min_element(all(v)) - (v).begin()) #define max_index(v) size_t(max_element(all(v)) - (v).begin()) #define min_e(v) *min_element(ALL(v)) #define max_e(v) *max_element(ALL(v)) #define count_le(v, a) size_t(upper_bound(ALL(v), a) - (v).begin()) #define count_lt(v, a) size_t(lower_bound(ALL(v), a) - (v).begin()) #define count_ge(v, a) size_t((v).end() - lower_bound(ALL(v), a)) #define count_gt(v, a) size_t((v).end() - upper_bound(ALL(v), a)) #define order(neq_sl) [](const auto s, const auto l) { return neq_sl; } #define make_lr(v, type, l, r) \ vector<type> l(n + 1), r(n + 1); \ FOR(i, n) { \ l[i + 1] = l[i] + v[i]; \ r[i + 1] = r[i] + v[n - 1 - i]; \ } #define acm accumulate #define SUM(v) accumulate(ALL(v), 0l) #define SORT(v) sort(ALL(v)) #define GCD(v) gcd(ALL(v), 0l) /*template <typename T> T gcd(T a, T b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b%a, a); } template <typename InputItr, typename T> T gcd(InputItr first, InputItr last, T init) { for (; first != last; ++first) init = gcd(init, *first); return init; }*/ template <typename T> using vec = vector<T>; template <typename T> using vvec = vector<vector<T>>; int main() { int x, n; cin >> x >> n; nvec(int, p, n); vec<pair<int, int>> q; for (int i = 0; i < 102; i++) { bool a = 1; for (int j = 0; j < n; j++) { if (i == p[j]) a = 0; } if (a == 1) q.push_back(make_pair(abs(x - i), i)); } SORT(q); cout << q[0].second; } /* きょむ〜 */
replace
75
76
75
76
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> x >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); int ans = -1, diff = 1001; for (int i = 1; i <= v[n - 1] + 1; i++) { if (binary_search(v.begin(), v.end(), i)) continue; if (abs(x - i) < diff) { diff = abs(x - i); ans = i; } } if (ans == -1) cout << x; else cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> x >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); int ans = -1, diff = 1001; if (n > 0) { for (int i = 0; i <= v[n - 1] + 1; i++) { if (binary_search(v.begin(), v.end(), i)) continue; if (abs(x - i) < diff) { diff = abs(x - i); ans = i; } } } if (ans == -1) cout << x; else cout << ans; return 0; }
replace
11
17
11
19
0
p02641
C++
Time Limit Exceeded
/* author:@bhaskar_8998 */ #include <bits/stdc++.h> using namespace std; typedef long long i64; typedef vector<i64> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef map<int, int> mi; #define all(A) (A).begin(), (A).end() #define pb push_back #define MOD 1000000007 #define ff first #define ss second #define deb(x) cerr << #x << " " << x << "\n"; #define fastio() \ { \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif fastio(); clock_t beg = clock(); int t = 1; // cin>>t; while (t--) { int n, k; cin >> k >> n; mi m; m.clear(); for (int i = 0, a; i < n; i++) { cin >> a; m[a] += 1; } int xm = 0; for (int i = 0;; i++) { int x = INT_MAX, y = INT_MAX; if (m[k - i] == 0) x = k - i; if (m[k + i] == 0) y = k + i; xm = min(x, y); if (xm > 0 && xm != INT_MAX) break; } cout << xm; } clock_t end = clock(); fprintf(stderr, "\n%lf sec\n", (double)(end - beg) / (CLOCKS_PER_SEC)); return 0; }
/* author:@bhaskar_8998 */ #include <bits/stdc++.h> using namespace std; typedef long long i64; typedef vector<i64> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef map<int, int> mi; #define all(A) (A).begin(), (A).end() #define pb push_back #define MOD 1000000007 #define ff first #define ss second #define deb(x) cerr << #x << " " << x << "\n"; #define fastio() \ { \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif fastio(); clock_t beg = clock(); int t = 1; // cin>>t; while (t--) { int n, k; cin >> k >> n; mi m; m.clear(); for (int i = 0, a; i < n; i++) { cin >> a; m[a] += 1; } int xm = 0; for (int i = 0;; i++) { int x = INT_MAX, y = INT_MAX; if (m[k - i] == 0) x = k - i; if (m[k + i] == 0) y = k + i; xm = min(x, y); if (xm >= 0 && xm != INT_MAX) break; } cout << xm; } clock_t end = clock(); fprintf(stderr, "\n%lf sec\n", (double)(end - beg) / (CLOCKS_PER_SEC)); return 0; }
replace
49
50
49
50
TLE
p02641
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int using namespace std; bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.second < b.second); } int main() { ll t, i, j, k, n, l, x, y; cin >> x >> n; map<ll, ll> m; if (n == 0) { cout << x << endl; return 0; } vector<pair<ll, ll>> v; for (i = 0; i < n; i++) { ll p; cin >> p; m[p]++; } for (i = 1; i <= 100; i++) { if (m[i] == 0) { v.push_back({i, abs(i - x)}); } } sort(v.begin(), v.end(), sortbysec); cout << v[0].first << endl; return 0; }
#include <bits/stdc++.h> #define ll long long int using namespace std; bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.second < b.second); } int main() { ll t, i, j, k, n, l, x, y; cin >> x >> n; map<ll, ll> m; if (n == 0) { cout << x << endl; return 0; } vector<pair<ll, ll>> v; for (i = 0; i < n; i++) { ll p; cin >> p; m[p]++; } for (i = -1000; i <= 1000; i++) { if (m[i] == 0) { v.push_back({i, abs(i - x)}); } } sort(v.begin(), v.end(), sortbysec); cout << v[0].first << endl; return 0; }
replace
21
22
21
22
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define M 200005 #define MOD 1000000007 #define PI 3.14159265358979323846 #define ep emplace_back #define mk make_pair #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() typedef long long int lli; typedef unsigned long long int ulli; typedef pair<int, int> PII; typedef pair<lli, lli> PLL; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int x, n; cin >> x >> n; map<int, int> mp; for (int i = 0; i < n; i++) { int temp; cin >> temp; mp[temp]++; } vector<PII> res; for (int i = 1; i <= 100; i++) { if (mp[i] == 0) { res.ep(mk(abs(i - x), i)); } } sort(all(res)); int ans = res[0].second; cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define M 200005 #define MOD 1000000007 #define PI 3.14159265358979323846 #define ep emplace_back #define mk make_pair #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() typedef long long int lli; typedef unsigned long long int ulli; typedef pair<int, int> PII; typedef pair<lli, lli> PLL; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int x, n; cin >> x >> n; map<int, int> mp; for (int i = 0; i < n; i++) { int temp; cin >> temp; mp[temp]++; } vector<PII> res; for (int i = 0; i <= 1000; i++) { if (mp[i] == 0) { res.ep(mk(abs(i - x), i)); } } sort(all(res)); int ans = res[0].second; cout << ans << "\n"; }
replace
34
35
34
35
0
p02641
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll x, n; cin >> x >> n; if (!n) { cout << x << endl; return 0; } bitset<101> bs; rep(i, n) { int a; cin >> a; bs.set(a, true); } for (int i = 0;; i++) { if (!bs.test(x - i)) { cout << x - i << endl; break; } if (!bs.test(x + i)) { cout << x + i << endl; break; } } }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll x, n; cin >> x >> n; if (!n) { cout << x << endl; return 0; } bitset<102> bs; rep(i, n) { int a; cin >> a; bs.set(a, true); } for (int i = 0;; i++) { if (!bs.test(x - i)) { cout << x - i << endl; break; } if (!bs.test(x + i)) { cout << x + i << endl; break; } } }
replace
43
44
43
44
0
p02641
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int x, n; // a+b=x;2*a + 4*b=y; cin >> x >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); set<int> st; for (int i = 0; i < n; i++) st.insert(a[i]); int dif = 0; while (1) { if (st.find(x - dif) == st.end()) { cout << x - dif << endl; break; } if (st.find(x + dif) == st.end()) { cout << x + dif << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int x, n; // a+b=x;2*a + 4*b=y; cin >> x >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); set<int> st; for (int i = 0; i < n; i++) st.insert(a[i]); int dif = 0; while (1) { if (st.find(x - dif) == st.end()) { cout << x - dif << endl; break; } if (st.find(x + dif) == st.end()) { cout << x + dif << endl; break; } dif++; } return 0; }
insert
24
24
24
25
TLE
p02641
Python
Runtime Error
x, n = map(int, input().split()) p = list(map(int, input().split())) min = float("inf") for i in range(1, 101)[::-1]: if abs(x - i) <= min: if i not in p: min = abs(x - i) ans = i print(ans)
x, n = map(int, input().split()) p = list(map(int, input().split())) min = float("inf") for i in range(0, 102)[::-1]: if abs(x - i) <= min: if i not in p: min = abs(x - i) ans = i print(ans)
replace
4
5
4
5
0
p02641
Python
Runtime Error
x, n = map(int, input().split()) if n != 0: p = list(map(int, input().split())) else: print(x) exit(1) dif = 100 ans = 0 for i in range(min(p) - 1, max(p) + 2): if not (i in p): if dif > abs(x - i): dif = abs(x - i) ans = i print(ans)
x, n = map(int, input().split()) if n != 0: p = list(map(int, input().split())) else: print(x) exit() dif = 100 ans = 0 for i in range(min(p) - 1, max(p) + 2): if not (i in p): if dif > abs(x - i): dif = abs(x - i) ans = i print(ans)
replace
6
7
6
7
0
p02641
Python
Runtime Error
import numpy as np X, N = map(int, input().split()) P = list(map(int, input().split())) candidate = list(range(1, 101)) P = sorted(set(candidate).difference(set(P))) i = np.argmin([abs(p - X) for p in P]) print(P[i])
import numpy as np X, N = map(int, input().split()) P = list(map(int, input().split())) candidate = list([x - 500 for x in range(1, 1000)]) P = sorted(set(candidate).difference(set(P))) i = np.argmin([abs(p - X) for p in P]) print(P[i])
replace
4
5
4
5
TLE
p02641
C++
Runtime Error
/* (: ///////|||||| BEGINS |||||||\\\\ :) */ /* REMEMBER Deletes all characters except first one Deletes 4 characters from index number 1 str.erase(1); str.erase(1,4); Deletes character at position 4 str.erase(str.begin() + 4); bool compare(const pair<int, int>&a, const pair<int, int>&b) { return a.second<b.second; } maxn = max_element(mp.begin(), mp.end(), compare)->second; bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); } min(a,b,c,d)==min({a,b,c,d}); priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define endl '\n' #define mod 1000000007 #define fo(i, n) for (int i = 1; i <= n; i++) #define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower) #define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper) #define all(x) (x).begin(), (x).end() #define pb push_back #define lb lower_bound #define ub upper_bound #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define gcd(a, b) __gcd(a, b) #define pq priority_queue #define fr first #define sc second #define sz(x) x.size() const int inf = 0x3f3f3f3f; bool ispalindrome(string s) { ll len = s.length(); for (ll i = 0; i < len; i++) { if (s[i] != s[len - i - 1]) return false; } return true; } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } long long isprime(long long n) { for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int x, n; cin >> x >> n; int a[n]; int h[105] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; h[a[i]] = 1; } if (n == 0) cout << x << endl; else { vector<pair<int, int>> v; for (int i = 1; i <= 100; i++) { if (h[i] == 0) v.pb({abs(i - x), i}); } sort(all(v)); cout << v[0].second << endl; } return 0; }
/* (: ///////|||||| BEGINS |||||||\\\\ :) */ /* REMEMBER Deletes all characters except first one Deletes 4 characters from index number 1 str.erase(1); str.erase(1,4); Deletes character at position 4 str.erase(str.begin() + 4); bool compare(const pair<int, int>&a, const pair<int, int>&b) { return a.second<b.second; } maxn = max_element(mp.begin(), mp.end(), compare)->second; bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); } min(a,b,c,d)==min({a,b,c,d}); priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define endl '\n' #define mod 1000000007 #define fo(i, n) for (int i = 1; i <= n; i++) #define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower) #define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper) #define all(x) (x).begin(), (x).end() #define pb push_back #define lb lower_bound #define ub upper_bound #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define gcd(a, b) __gcd(a, b) #define pq priority_queue #define fr first #define sc second #define sz(x) x.size() const int inf = 0x3f3f3f3f; bool ispalindrome(string s) { ll len = s.length(); for (ll i = 0; i < len; i++) { if (s[i] != s[len - i - 1]) return false; } return true; } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } long long isprime(long long n) { for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int x, n; cin >> x >> n; int a[n]; int h[105] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; h[a[i]] = 1; } if (n == 0) cout << x << endl; else { vector<pair<int, int>> v; for (int i = 0; i <= 102; i++) { if (h[i] == 0) v.pb({abs(i - x), i}); } sort(all(v)); cout << v[0].second << endl; } return 0; }
replace
83
84
83
84
-11
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(void) { int X, N; cin >> X >> N; int check = 0; vector<int> list(100); rep(i, N) { cin >> check; list.at(check - 1) = 1; check = 0; } for (int j = 0; j < 500; j++) { if (X - j - 1 >= 0) { if (list.at(X - j - 1) != 1) { cout << X - j; break; } } else { cout << X - j; break; } if (X + j - 1 <= 100) { if (list.at(X + j - 1) != 1) { cout << X + j; break; } } else { cout << X + j; break; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(void) { int X, N; cin >> X >> N; int check = 0; vector<int> list(100); rep(i, N) { cin >> check; list.at(check - 1) = 1; check = 0; } for (int j = 0; j < 500; j++) { if (X - j - 1 >= 0) { if (list.at(X - j - 1) != 1) { cout << X - j; break; } } else { cout << X - j; break; } if (X + j - 1 <= 99) { if (list.at(X + j - 1) != 1) { cout << X + j; break; } } else { cout << X + j; break; } } }
replace
27
28
27
28
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define endl '\n' using namespace std; #define N 100007 #define pb push_back; vector<ll> v[N]; vector<bool> vs(N); #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); int main() { ll x, n, i; cin >> x >> n; vector<ll> v; map<ll, ll> mp; for (i = 0; i < n; i++) { ll y; cin >> y; mp[y]++; } for (i = 1; i <= 100; i++) { if (mp[i] == 0) { v.push_back(i); } } ll ind = lower_bound(v.begin(), v.end(), x) - v.begin(); if (ind == 0) { cout << v[ind]; } else { if (abs(x - v[ind]) >= abs(x - v[ind - 1])) { cout << v[ind - 1]; } else { cout << v[ind]; } } }
#include <bits/stdc++.h> #define ll long long #define endl '\n' using namespace std; #define N 100007 #define pb push_back; vector<ll> v[N]; vector<bool> vs(N); #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); int main() { ll x, n, i; cin >> x >> n; vector<ll> v; map<ll, ll> mp; for (i = 0; i < n; i++) { ll y; cin >> y; mp[y]++; } for (i = 0; i <= 107; i++) { if (mp[i] == 0) { v.push_back(i); } } ll ind = lower_bound(v.begin(), v.end(), x) - v.begin(); if (ind == 0) { cout << v[ind]; } else { if (abs(x - v[ind]) >= abs(x - v[ind - 1])) { cout << v[ind - 1]; } else { cout << v[ind]; } } }
replace
22
23
22
23
0
p02641
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x, n, i, j; cin >> x; cin >> n; int p[n]; for (int i = 0; i < n; i++) { cin >> p[i]; } i = 0; while (1) { for (j = 0; j < n; j++) { if (p[j] == x + i) { j = 0; break; } } if (j != 0) { cout << x + i << endl; return 0; } if (i >= 0) { i = i * (-1) - 1; } else { i = i * (-1); } } return 0; }
#include <iostream> using namespace std; int main() { int x, n, i, j; cin >> x; cin >> n; int p[n]; if (n == 0) { cout << x << endl; return 0; } for (int i = 0; i < n; i++) { cin >> p[i]; } i = 0; while (1) { for (j = 0; j < n; j++) { if (p[j] == x + i) { j = 0; break; } } if (j != 0) { cout << x + i << endl; return 0; } if (i >= 0) { i = i * (-1) - 1; } else { i = i * (-1); } } return 0; }
insert
8
8
8
13
TLE
p02641
C++
Time Limit Exceeded
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; // #define int cpp_int using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define ll long long #define ld long double #define vi vector<int> #define pii pair<int, int> #define vpii vector<pair<int, int>> #define uset unordered_set #define umap unordered_map #define maxpq priority_queue<int> #define minpq priority_queue<int, vi, greater<int>()> #define all(v) v.begin(), v.end() #define part(v, s, e) v.begin() + s, v.begin() + e #define rev(v) reverse(v.begin(), v.end()) #define sz(x) (int)x.size() #define def(v) memset(v, -1, sizeof(v)); #define def0(v) memset(v, 0, sizeof(v)); #define minv(a) *min_element(all(a)) #define maxv(a) *max_element(all(a)) #define sumv(a) accumulate(all(a), 0) #define lb lower_bound #define ub upper_bound #define desc greater<int>() #define pb emplace_back #define mp make_pair #define F first #define S second #define mod 1000000007 #define inf 1000000000000000 #define infty 1000000000000000000LL #define md 998244353 #define PI acos(-1.0) #define endl "\n" #define rr return #define br cout << "\n"; #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a / (__gcd(a, b))) * b #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define ip(v) \ for (auto &i : v) \ cin >> i; #define op(v) \ for (auto i : v) \ cout << i << " "; \ cout << endl; #define deb(x) cout << "Value of " #x << " : " << x << endl; void solve() { int x, n; cin >> x >> n; set<int> s; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } sort(a, a + n); int diff = INT_MAX, ans; for (int i = a[0] - 1; i <= a[n - 1] + 1; i++) { if (s.find(i) == s.end()) { if (abs(i - x) < diff) { diff = abs(i - x); ans = i; } } } cout << ans << endl; } int32_t main() { fastio cout << setprecision(15) << fixed; int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case "<<i<<" : "<<endl; solve(); } #ifndef ONLINE_JUDGE cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; #endif return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; // #define int cpp_int using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define ll long long #define ld long double #define vi vector<int> #define pii pair<int, int> #define vpii vector<pair<int, int>> #define uset unordered_set #define umap unordered_map #define maxpq priority_queue<int> #define minpq priority_queue<int, vi, greater<int>()> #define all(v) v.begin(), v.end() #define part(v, s, e) v.begin() + s, v.begin() + e #define rev(v) reverse(v.begin(), v.end()) #define sz(x) (int)x.size() #define def(v) memset(v, -1, sizeof(v)); #define def0(v) memset(v, 0, sizeof(v)); #define minv(a) *min_element(all(a)) #define maxv(a) *max_element(all(a)) #define sumv(a) accumulate(all(a), 0) #define lb lower_bound #define ub upper_bound #define desc greater<int>() #define pb emplace_back #define mp make_pair #define F first #define S second #define mod 1000000007 #define inf 1000000000000000 #define infty 1000000000000000000LL #define md 998244353 #define PI acos(-1.0) #define endl "\n" #define rr return #define br cout << "\n"; #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a / (__gcd(a, b))) * b #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define ip(v) \ for (auto &i : v) \ cin >> i; #define op(v) \ for (auto i : v) \ cout << i << " "; \ cout << endl; #define deb(x) cout << "Value of " #x << " : " << x << endl; void solve() { int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; rr; } set<int> s; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } sort(a, a + n); int diff = INT_MAX, ans; for (int i = a[0] - 1; i <= a[n - 1] + 1; i++) { if (s.find(i) == s.end()) { if (abs(i - x) < diff) { diff = abs(i - x); ans = i; } } } cout << ans << endl; } int32_t main() { fastio cout << setprecision(15) << fixed; int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case "<<i<<" : "<<endl; solve(); } #ifndef ONLINE_JUDGE cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; #endif return 0; }
insert
68
68
68
73
TLE
p02641
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll MOD = 1000000007; int main(void) { int x, n; cin >> x >> n; int p[n]; int dif = 0; rep(i, n) cin >> p[i]; while (1) { rep(i, n) { if (x - dif == p[i]) break; else if (i == n - 1) { cout << x - dif << endl; return 0; } } rep(i, n) { if (x + dif == p[i]) break; else if (i == n - 1) { cout << x + dif << endl; return 0; } } dif++; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll MOD = 1000000007; int main(void) { int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; return 0; } int p[n]; int dif = 0; rep(i, n) cin >> p[i]; while (1) { rep(i, n) { if (x - dif == p[i]) break; else if (i == n - 1) { cout << x - dif << endl; return 0; } } rep(i, n) { if (x + dif == p[i]) break; else if (i == n - 1) { cout << x + dif << endl; return 0; } } dif++; } return 0; }
insert
24
24
24
28
TLE
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int x, n, ans = 100, tmp = 100; cin >> x >> n; vector<int> p(n), test(100); for (int i = 0; i <= 100; i++) test.at(i) = i; for (int i = 0; i < n; i++) { cin >> p.at(i); test.erase(remove(test.begin(), test.end(), p.at(i)), test.end()); } for (int i : test) { if (abs(x - i) < tmp) { ans = i; tmp = abs(x - i); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, n, ans = 100, tmp = 100; cin >> x >> n; vector<int> p(n), test(102); for (int i = 0; i <= 101; i++) test.at(i) = i; for (int i = 0; i < n; i++) { cin >> p.at(i); test.erase(remove(test.begin(), test.end(), p.at(i)), test.end()); } for (int i : test) { if (abs(x - i) < tmp) { ans = i; tmp = abs(x - i); } } cout << ans << endl; return 0; }
replace
6
8
6
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 100) >= this->size() (which is 100)
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; return 0; } vector<int> p(100); for (int i = 0; i < n; i++) { int t = 0; cin >> t; p.at(t) = 1; } for (int i = 0; i < 100; i++) { if (p[x - i] != 1) { cout << x - i << endl; return 0; } if (p[x + i] != 1) { cout << x + i << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; return 0; } vector<int> p(100); for (int i = 0; i < n; i++) { int t = 0; cin >> t; p[t]++; } for (int i = 0; i < 100; i++) { if (p[x - i] != 1) { cout << x - i << endl; return 0; } if (p[x + i] != 1) { cout << x + i << endl; return 0; } } return 0; }
replace
15
16
15
16
0
p02641
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> int main() { int x, n; std::cin >> x >> n; std::vector<int> p(n); for (int i = 0; i < n; ++i) std::cin >> p[i]; int minD = 1000; int result = 0; for (int j = 200; j > -100; ++j) { if (std::any_of(p.begin(), p.end(), [j](int v) { return j == v; })) continue; if (minD >= std::abs(j - x)) { minD = std::abs(j - x); result = j; } } std::cout << result << std::endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> int main() { int x, n; std::cin >> x >> n; std::vector<int> p(n); for (int i = 0; i < n; ++i) std::cin >> p[i]; int minD = 1000; int result = 0; for (int j = 200; j > -100; --j) { if (std::any_of(p.begin(), p.end(), [j](int v) { return j == v; })) continue; if (minD >= std::abs(j - x)) { minD = std::abs(j - x); result = j; } } std::cout << result << std::endl; return 0; }
replace
14
15
14
15
TLE
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0) /* start */ int was[110]; signed main() { IOS; int x, n; cin >> x >> n; for (int i = 0; i < n; i++) { int it; cin >> it; was[it] = 1; } vector<pair<int, int>> ans; for (int i = 1; i <= 100; i++) { if (!was[i]) ans.push_back({abs(i - x), i}); } sort(ans.begin(), ans.end()); cout << ans[0].second << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0) /* start */ int was[110]; signed main() { IOS; int x, n; cin >> x >> n; for (int i = 0; i < n; i++) { int it; cin >> it; was[it] = 1; } vector<pair<int, int>> ans; for (int i = 0; i < 10000; i++) { if (i < 110) { if (!was[i]) ans.push_back({abs(i - x), i}); } else ans.push_back({abs(i - x), i}); } sort(ans.begin(), ans.end()); cout << ans[0].second << "\n"; }
replace
20
22
20
25
0
p02641
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> int main() { int X, N; std::cin >> X >> N; std::vector<int> P(N); int Distance = 0; int ans; for (auto &p : P) { std::cin >> p; } while (1) { auto itr1 = std::find(P.begin(), P.end(), X - Distance); auto itr2 = std::find(P.begin(), P.end(), X + Distance); if (itr1 == P.end()) { ans = X - Distance; break; } else if (itr2 == P.end()) { ans = X + Distance; break; } Distance; } std::cout << ans; return 0; }
#include <algorithm> #include <iostream> #include <vector> int main() { int X, N; std::cin >> X >> N; std::vector<int> P(N); int Distance = 0; int ans; for (auto &p : P) { std::cin >> p; } while (1) { auto itr1 = std::find(P.begin(), P.end(), X - Distance); auto itr2 = std::find(P.begin(), P.end(), X + Distance); if (itr1 == P.end()) { ans = X - Distance; break; } else if (itr2 == P.end()) { ans = X + Distance; break; } Distance++; } std::cout << ans; return 0; }
replace
23
24
23
24
TLE
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; #define fil(x) memset(x, 0, sizeof(x)) #define fillb(x) memset(x, false, sizeof(x)) #define fillm(x) memset(x, -1, sizeof(x)) #define mp make_pair #define pll pair<int, int> #define pf printf #define sf scanf #define all(x) x.begin(), x.end() #define pb push_back #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define np std::string::npos #define fo(i, n) for (int i = 0; i < n; i++) #define fo1(i, n) for (int i = 1; i < n; i++) #define fof(i, a, b) for (int i = a; i <= b; i++) #define off(i, a, b) for (int i = a; i >= b; i--) #define of(i, n) for (int i = n - 1; i >= 0; i--) #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() #define Inf INFINITY #define minv(v) *min_element(v.begin(), v.end()) #define maxv(v) *max_element(v.begin(), v.end()) #define cases(cs, t) for (int cs = 1; cs <= t; cs++) #define PI acos(-1) #define nl endl typedef unsigned long long lll; typedef long long ll; int knigtx8[] = {2, 2, -2, -2, 1, 1, -1, -1}; /// knight move in chess int knigty8[] = {1, -1, 1, -1, 2, -2, 2, -2}; /// knight move in chess int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; /// for 8 directions int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; /// for 8 directions int dx4[] = {0, 0, 1, -1}; /// for 4 directions int dy4[] = {1, -1, 0, 0}; /// for 4 directions const int maxx = 100005; // this fuction sorts vector pair according to first element in descending // order. bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return a.first > b.first; } ll pw(ll a, ll b) { ll ans = 1; for (ll i = 1; i <= b; ++i) ans = (ans * a); return ans; } template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } int main() { IOS; int n, x; cin >> x >> n; int a[n], ache[101]; fil(ache); // int mn = 1000; vector<pair<int, int>> v; fo(i, n) { cin >> a[i]; ache[a[i]] = 1; // v.pb({abs(a[i]-x), a[i]}); } fo(i, 110) { if (!ache[i]) { v.pb({abs(i - x), i}); } } sort(all(v)); cout << v[0].second << endl; } /// Alhamdulillah
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; #define fil(x) memset(x, 0, sizeof(x)) #define fillb(x) memset(x, false, sizeof(x)) #define fillm(x) memset(x, -1, sizeof(x)) #define mp make_pair #define pll pair<int, int> #define pf printf #define sf scanf #define all(x) x.begin(), x.end() #define pb push_back #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define np std::string::npos #define fo(i, n) for (int i = 0; i < n; i++) #define fo1(i, n) for (int i = 1; i < n; i++) #define fof(i, a, b) for (int i = a; i <= b; i++) #define off(i, a, b) for (int i = a; i >= b; i--) #define of(i, n) for (int i = n - 1; i >= 0; i--) #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() #define Inf INFINITY #define minv(v) *min_element(v.begin(), v.end()) #define maxv(v) *max_element(v.begin(), v.end()) #define cases(cs, t) for (int cs = 1; cs <= t; cs++) #define PI acos(-1) #define nl endl typedef unsigned long long lll; typedef long long ll; int knigtx8[] = {2, 2, -2, -2, 1, 1, -1, -1}; /// knight move in chess int knigty8[] = {1, -1, 1, -1, 2, -2, 2, -2}; /// knight move in chess int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; /// for 8 directions int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; /// for 8 directions int dx4[] = {0, 0, 1, -1}; /// for 4 directions int dy4[] = {1, -1, 0, 0}; /// for 4 directions const int maxx = 100005; // this fuction sorts vector pair according to first element in descending // order. bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return a.first > b.first; } ll pw(ll a, ll b) { ll ans = 1; for (ll i = 1; i <= b; ++i) ans = (ans * a); return ans; } template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } int main() { IOS; int n, x; cin >> x >> n; int a[n], ache[115]; fil(ache); // int mn = 1000; vector<pair<int, int>> v; fo(i, n) { cin >> a[i]; ache[a[i]] = 1; // v.pb({abs(a[i]-x), a[i]}); } fo(i, 110) { if (!ache[i]) { v.pb({abs(i - x), i}); } } sort(all(v)); cout << v[0].second << endl; } /// Alhamdulillah
replace
66
67
66
67
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() using ll = long long; int main() { int i, x, n, ans = 0, dist = 999, j = 0; cin >> x >> n; vector<int> p(n); for (i = 0; i < n; i++) cin >> p[i]; sort(p.begin(), p.end()); for (i = 1; i < x; i++) { if (i != p[j]) { ans = i; } else { j++; } } for (i = x; i < x + (x - ans); i++) { if (i != p[j]) { ans = i; break; } else { j++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() using ll = long long; int main() { int i, x, n, ans = 0, dist = 999, j = 0; cin >> x >> n; if (n == 0) { cout << x; return 0; } vector<int> p(n); for (i = 0; i < n; i++) cin >> p[i]; sort(p.begin(), p.end()); for (i = 1; i < x; i++) { if (i != p[j]) { ans = i; } else { j++; } } for (i = x; i < x + (x - ans); i++) { if (i != p[j]) { ans = i; break; } else { j++; } } cout << ans; return 0; }
insert
8
8
8
12
0
p02641
C++
Runtime Error
#ifdef LOCAL #include <header.hpp> #else #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #endif #define lp(i, l, r) for (auto i = regu(l); i <= decltype(i)(r); ++i) #define rp(i, r, l) for (auto i = regu(r); i >= decltype(i)(l); --i) #define lv(i, a) for (int i = 0; i < int(a.size()); ++i) #define rv(i, a) for (int i = int(a.size()) - 1; i >= 0; --i) #define lm(i, m) for (auto i = m; i; i = (m) & (i - 1)) #define many for (int C = 1, T = -1; T < 0 && cin >> T, C <= T; ++C) #define goog "Case #" + to_string(C) + ":" #define rang(a) begin(a), end(a) #define elif else if #ifndef LOCAL #define endl '\n' #undef assert #define assert #endif using namespace std; using namespace __gnu_pbds; const auto eps = 1e-8, pi = acos(-1); template <class T> int comp(const T &a, const T &b) { return a < b - eps ? -1 : (a > b + eps); } #if __cplusplus > 201103L template <class T> auto regu(const T &a) { return int(a); } template <> auto regu(const long long &a) { return a; } template <> auto regu(const unsigned long long &a) { return (long long)a; } #endif template <class T> int barr(const T &a, const int &i) { return a >> i & 1; } template <class T> int bcnt(const T &a) { return __builtin_popcount(a); } template <> int bcnt(const long long &a) { return __builtin_popcountll(a); } template <class T> int blen(const T &a) { return a ? 1 + blen(a / 2) : 0; } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> T rint(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <class A, class B> B conv(const A &a, B b = B()) { stringstream s; s << a, s >> b; return b; } template <class T = int> T inf() { return numeric_limits<T>::max() / 2; } template <class T> T sign(const T &a) { return a == 0 ? 0 : (a < 0 ? -1 : 1); } template <class T> T floor(const T &a, const T &b) { assert(b != 0); return sign(a) * sign(b) > 0 ? abs(a) / abs(b) : -(abs(a) + abs(b) - 1) / abs(b); } template <class T> T ceil(const T &a, const T &b) { assert(b != 0); return sign(a) * sign(b) > 0 ? (abs(a) + abs(b) - 1) / abs(b) : -abs(a) / abs(b); } template <class T> bool tmin(T &a, T b) { return b < a ? a = b, true : false; } template <class T> bool tmax(T &a, T b) { return b > a ? a = b, true : false; } #if __cplusplus > 201103L template <class T> auto min(const T &a) { return *min_element(rang(a)); } template <class T> auto max(const T &a) { return *max_element(rang(a)); } template <class T> auto sum(const T &a) { return accumulate(rang(a), (typename T::value_type)0); } template <> auto sum(const vector<int> &a) { return accumulate(rang(a), 0ll); } template <> auto sum(const vector<string> &a) { return accumulate(rang(a), string()); } template <class C, class V> auto find(C &c, const V &v) { return find(rang(c), v); } template <class C, class V> auto find(const C &c, const V &v) { return find(rang(c), v); } #endif template <class T, class C = less<typename T::value_type>> void sort(T &a, C c = C()) { sort(rang(a), c); } template <class T> void reve(T &a) { reverse(rang(a)); } template <class T> void uniq(T &a) { sort(a), a.erase(unique(rang(a)), end(a)); } template <class T> void shuf(T &a) { shuffle(rang(a), rng); } template <class T> void merg(T l, T m, T r) { inplace_merge(l, m, r); } #if __cplusplus > 201103L template <class T> auto vect(const T &v, int n) { return vector<T>(n, v); } template <class T, class... D> auto vect(const T &v, int n, D... m) { return vector<decltype(vect(v, m...))>(n, vect(v, m...)); } #endif template <class F, class S> istream &operator>>(istream &s, pair<F, S> &a) { return s >> a.first >> a.second; } template <class F, class S> ostream &operator<<(ostream &s, const pair<F, S> &a) { return s << a.first << " " << a.second; } template <class T> istream &operator>>(istream &s, vector<T> &a) { for (int i = -1; i < 0 && (!a.size() && (cin >> i, a.resize(i), 0), i = 0), i < int(a.size());) s >> a[i++]; return s; } template <class T> ostream &operator<<(ostream &s, const vector<T> &a) { lv(i, a) cout << a[i] << (i + 1 == int(a.size()) ? "" : " "); return s; } template <class T> T in() { T a; cin >> a; return a; } template <class T> void in(T &a) { cin >> a; } template <class A, class... B> void in(A &a, B &...b) { cin >> a, in(b...); } void ou() { cout << endl; } template <class T> void ou(const T &a) { cout << a << endl; } template <class A, class... B> void ou(const A &a, const B &...b) { cout << a << ' ', ou(b...); } bool yep(const bool &a) { return ou(a ? "yes" : "no"), a; } bool Yep(const bool &a) { return ou(a ? "Yes" : "No"), a; } bool YEP(const bool &a) { return ou(a ? "YES" : "NO"), a; } template <class T> struct hash_safe {}; template <> struct hash_safe<int> { size_t operator()(unsigned long long a) const { static unsigned long long d = chrono::steady_clock::now().time_since_epoch().count(); a += d + 0x9e3779b97f4a7c15, a = (a ^ (a >> 30)) * 0xbf58476d1ce4e5b9; a = (a ^ (a >> 27)) * 0x94d049bb133111eb; return a ^ (a >> 31); } }; template <> struct hash_safe<long long> { size_t operator()(unsigned long long a) const { return hash_safe<int>()(a); } }; template <class A, class B> struct hash_safe<pair<A, B>> { size_t operator()(pair<A, B> a) const { auto h = hash_safe<A>()(a.first), g = hash_safe<B>()(a.second); return (h >> 16 << 16) + (g >> 16); } }; template <class T> using unordered_set_safe = unordered_set<T, hash_safe<T>>; template <class T> using unordered_multiset_safe = unordered_multiset<T, hash_safe<T>>; template <class K, class V> using unordered_map_safe = unordered_map<K, V, hash_safe<K>>; template <class K, class V> using unordered_multimap_safe = unordered_multimap<K, V, hash_safe<K>>; #define unordered_set unordered_set_safe #define unordered_multiset unordered_multiset_safe #define unordered_map unordered_map_safe #define unordered_multimap unordered_multimap_safe template <class T, class C = less<T>> using bbst = tree<T, null_type, C, rb_tree_tag, tree_order_statistics_node_update>; template <class T, class C = greater<T>> using heap = __gnu_pbds::priority_queue<T, C, pairing_heap_tag>; using ll = long long; using ld = long double; using str = string; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpii = vector<pii>; using vpll = vector<pll>; using vvi = vector<vi>; // The templates end here. int main() { ios::sync_with_stdio(0); cout << setprecision(16) << fixed; cin.tie(0); int x, n; in(x, n); vi a(n); in(a); lp(i, 0, inf()) { if (find(a, x - i) == a.end()) { ou(x - i); return 0; } if (find(a, x + i) == a.end()) { ou(x + i); return 0; } } return 0; }
#ifdef LOCAL #include <header.hpp> #else #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #endif #define lp(i, l, r) for (auto i = regu(l); i <= decltype(i)(r); ++i) #define rp(i, r, l) for (auto i = regu(r); i >= decltype(i)(l); --i) #define lv(i, a) for (int i = 0; i < int(a.size()); ++i) #define rv(i, a) for (int i = int(a.size()) - 1; i >= 0; --i) #define lm(i, m) for (auto i = m; i; i = (m) & (i - 1)) #define many for (int C = 1, T = -1; T < 0 && cin >> T, C <= T; ++C) #define goog "Case #" + to_string(C) + ":" #define rang(a) begin(a), end(a) #define elif else if #ifndef LOCAL #define endl '\n' #undef assert #define assert #endif using namespace std; using namespace __gnu_pbds; const auto eps = 1e-8, pi = acos(-1); template <class T> int comp(const T &a, const T &b) { return a < b - eps ? -1 : (a > b + eps); } #if __cplusplus > 201103L template <class T> auto regu(const T &a) { return int(a); } template <> auto regu(const long long &a) { return a; } template <> auto regu(const unsigned long long &a) { return (long long)a; } #endif template <class T> int barr(const T &a, const int &i) { return a >> i & 1; } template <class T> int bcnt(const T &a) { return __builtin_popcount(a); } template <> int bcnt(const long long &a) { return __builtin_popcountll(a); } template <class T> int blen(const T &a) { return a ? 1 + blen(a / 2) : 0; } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> T rint(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <class A, class B> B conv(const A &a, B b = B()) { stringstream s; s << a, s >> b; return b; } template <class T = int> T inf() { return numeric_limits<T>::max() / 2; } template <class T> T sign(const T &a) { return a == 0 ? 0 : (a < 0 ? -1 : 1); } template <class T> T floor(const T &a, const T &b) { assert(b != 0); return sign(a) * sign(b) > 0 ? abs(a) / abs(b) : -(abs(a) + abs(b) - 1) / abs(b); } template <class T> T ceil(const T &a, const T &b) { assert(b != 0); return sign(a) * sign(b) > 0 ? (abs(a) + abs(b) - 1) / abs(b) : -abs(a) / abs(b); } template <class T> bool tmin(T &a, T b) { return b < a ? a = b, true : false; } template <class T> bool tmax(T &a, T b) { return b > a ? a = b, true : false; } #if __cplusplus > 201103L template <class T> auto min(const T &a) { return *min_element(rang(a)); } template <class T> auto max(const T &a) { return *max_element(rang(a)); } template <class T> auto sum(const T &a) { return accumulate(rang(a), (typename T::value_type)0); } template <> auto sum(const vector<int> &a) { return accumulate(rang(a), 0ll); } template <> auto sum(const vector<string> &a) { return accumulate(rang(a), string()); } template <class C, class V> auto find(C &c, const V &v) { return find(rang(c), v); } template <class C, class V> auto find(const C &c, const V &v) { return find(rang(c), v); } #endif template <class T, class C = less<typename T::value_type>> void sort(T &a, C c = C()) { sort(rang(a), c); } template <class T> void reve(T &a) { reverse(rang(a)); } template <class T> void uniq(T &a) { sort(a), a.erase(unique(rang(a)), end(a)); } template <class T> void shuf(T &a) { shuffle(rang(a), rng); } template <class T> void merg(T l, T m, T r) { inplace_merge(l, m, r); } #if __cplusplus > 201103L template <class T> auto vect(const T &v, int n) { return vector<T>(n, v); } template <class T, class... D> auto vect(const T &v, int n, D... m) { return vector<decltype(vect(v, m...))>(n, vect(v, m...)); } #endif template <class F, class S> istream &operator>>(istream &s, pair<F, S> &a) { return s >> a.first >> a.second; } template <class F, class S> ostream &operator<<(ostream &s, const pair<F, S> &a) { return s << a.first << " " << a.second; } template <class T> istream &operator>>(istream &s, vector<T> &a) { for (int i = -1; i < 0 && (!a.size() && (cin >> i, a.resize(i), 0), i = 0), i < int(a.size());) s >> a[i++]; return s; } template <class T> ostream &operator<<(ostream &s, const vector<T> &a) { lv(i, a) cout << a[i] << (i + 1 == int(a.size()) ? "" : " "); return s; } template <class T> T in() { T a; cin >> a; return a; } template <class T> void in(T &a) { cin >> a; } template <class A, class... B> void in(A &a, B &...b) { cin >> a, in(b...); } void ou() { cout << endl; } template <class T> void ou(const T &a) { cout << a << endl; } template <class A, class... B> void ou(const A &a, const B &...b) { cout << a << ' ', ou(b...); } bool yep(const bool &a) { return ou(a ? "yes" : "no"), a; } bool Yep(const bool &a) { return ou(a ? "Yes" : "No"), a; } bool YEP(const bool &a) { return ou(a ? "YES" : "NO"), a; } template <class T> struct hash_safe {}; template <> struct hash_safe<int> { size_t operator()(unsigned long long a) const { static unsigned long long d = chrono::steady_clock::now().time_since_epoch().count(); a += d + 0x9e3779b97f4a7c15, a = (a ^ (a >> 30)) * 0xbf58476d1ce4e5b9; a = (a ^ (a >> 27)) * 0x94d049bb133111eb; return a ^ (a >> 31); } }; template <> struct hash_safe<long long> { size_t operator()(unsigned long long a) const { return hash_safe<int>()(a); } }; template <class A, class B> struct hash_safe<pair<A, B>> { size_t operator()(pair<A, B> a) const { auto h = hash_safe<A>()(a.first), g = hash_safe<B>()(a.second); return (h >> 16 << 16) + (g >> 16); } }; template <class T> using unordered_set_safe = unordered_set<T, hash_safe<T>>; template <class T> using unordered_multiset_safe = unordered_multiset<T, hash_safe<T>>; template <class K, class V> using unordered_map_safe = unordered_map<K, V, hash_safe<K>>; template <class K, class V> using unordered_multimap_safe = unordered_multimap<K, V, hash_safe<K>>; #define unordered_set unordered_set_safe #define unordered_multiset unordered_multiset_safe #define unordered_map unordered_map_safe #define unordered_multimap unordered_multimap_safe template <class T, class C = less<T>> using bbst = tree<T, null_type, C, rb_tree_tag, tree_order_statistics_node_update>; template <class T, class C = greater<T>> using heap = __gnu_pbds::priority_queue<T, C, pairing_heap_tag>; using ll = long long; using ld = long double; using str = string; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpii = vector<pii>; using vpll = vector<pll>; using vvi = vector<vi>; // The templates end here. int main() { ios::sync_with_stdio(0); cout << setprecision(16) << fixed; cin.tie(0); int x, n; in(x, n); vi a(n); if (n) in(a); lp(i, 0, inf()) { if (find(a, x - i) == a.end()) { ou(x - i); return 0; } if (find(a, x + i) == a.end()) { ou(x + i); return 0; } } return 0; }
replace
177
178
177
179
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define MAX 1000000 int main() { int x, n; cin >> x >> n; vector<int> in(101, 0); int p; for (int i = 0; i < n; i++) { cin >> p; in.at(p)++; } int dis = 99999; int ans; for (int i = 0; i <= 101; i++) { if (in.at(i) == 1) continue; if (dis > abs(x - i)) { dis = abs(x - i); ans = i; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define MAX 1000000 int main() { int x, n; cin >> x >> n; vector<int> in(102, 0); int p; for (int i = 0; i < n; i++) { cin >> p; in.at(p)++; } int dis = 99999; int ans; for (int i = 0; i <= 101; i++) { if (in.at(i) == 1) continue; if (dis > abs(x - i)) { dis = abs(x - i); ans = i; } } cout << ans << endl; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 101) >= this->size() (which is 101)
p02641
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; const int INF = 2e9; int main() { int x, n; cin >> x >> n; vector<int> p(n); rep(i, n) cin >> p[i]; sort(p.begin(), p.end()); queue<int> que; int j = 0; rep(i, 102) { if (i == p[j]) j++; else que.push(i); } int s = que.front(); que.pop(); int ans = 2e9; int res = 2e9; while (!que.empty()) { int t = que.front(); que.pop(); int a = abs(s - x); int b = abs(t - x); if (a <= b) { if (res > a) { res = a; ans = s; } } else { if (res > b) { res = a; ans = t; } } s = t; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; const int INF = 2e9; int main() { int x, n; cin >> x >> n; if (n == 0) { cout << x << endl; return 0; } vector<int> p(n); rep(i, n) cin >> p[i]; sort(p.begin(), p.end()); queue<int> que; int j = 0; rep(i, 102) { if (i == p[j]) j++; else que.push(i); } int s = que.front(); que.pop(); int ans = 2e9; int res = 2e9; while (!que.empty()) { int t = que.front(); que.pop(); int a = abs(s - x); int b = abs(t - x); if (a <= b) { if (res > a) { res = a; ans = s; } } else { if (res > b) { res = a; ans = t; } } s = t; } cout << ans << endl; }
insert
11
11
11
15
0
p02641
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cmath> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> //....................................................................................................................// using std::cin; using std::cout; using std::deque; using std::get; using std::greater; using std::ifstream; using std::ios_base; using std::less; using std::list; using std::lower_bound; using std::make_pair; using std::make_tuple; using std::map; using std::max; using std::max_element; using std::min; using std::min_element; using std::multimap; using std::multiset; using std::ofstream; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::stack; using std::string; using std::swap; using std::tuple; using std::unordered_map; using std::unordered_multimap; using std::unordered_set; using std::upper_bound; using std::vector; //....................................................................................................................// typedef long long ll; typedef unsigned long long ull; [[maybe_unused]] const string endl = "\n"; [[maybe_unused]] const string sep = " "; [[maybe_unused]] const string yes = "YES\n"; [[maybe_unused]] const string no = "NO\n"; [[maybe_unused]] const string ng = "NG\n"; [[maybe_unused]] const string ok = "OK\n"; [[maybe_unused]] const double pi = acos(-1); [[maybe_unused]] const ull modular = 998244353; //....................................................................................................................// template <class T> T min(const T &a, const T &b, const T &c) { return min(a, min(b, c)); } template <class T> T max(const T &a, const T &b, const T &c) { return max(a, max(b, c)); } typedef vector<vector<ll>> graph; vector<ll> lca_h, lca_dfs_list, lca_first, lca_tree; vector<char> lca_dfs_used; void lca_dfs(const graph &g, ll v, ll h = 1) { lca_dfs_used[v] = true; lca_h[v] = h; lca_dfs_list.push_back(v); for (auto i = g[v].begin(); i != g[v].end(); ++i) if (!lca_dfs_used[*i]) { lca_dfs(g, *i, h + 1); lca_dfs_list.push_back(v); } } void lca_build_tree(ll i, ll l, ll r) { if (l == r) lca_tree[i] = lca_dfs_list[l]; else { ll m = (l + r) >> 1; lca_build_tree(i + i, l, m); lca_build_tree(i + i + 1, m + 1, r); if (lca_h[lca_tree[i + i]] < lca_h[lca_tree[i + i + 1]]) lca_tree[i] = lca_tree[i + i]; else lca_tree[i] = lca_tree[i + i + 1]; } } void lca_prepare(const graph &g, ll root) { ll n = (ll)g.size(); lca_h.resize(n); lca_dfs_list.reserve(n * 2); lca_dfs_used.assign(n, 0); lca_dfs(g, root); ll m = (ll)lca_dfs_list.size(); lca_tree.assign(lca_dfs_list.size() * 4 + 1, -1); lca_build_tree(1, 0, m - 1); lca_first.assign(n, -1); for (ll i = 0; i < m; ++i) { ll v = lca_dfs_list[i]; if (lca_first[v] == -1) lca_first[v] = i; } } ll lca_tree_min(ll i, ll sl, ll sr, ll l, ll r) { if (sl == l && sr == r) return lca_tree[i]; ll sm = (sl + sr) >> 1; if (r <= sm) return lca_tree_min(i + i, sl, sm, l, r); if (l > sm) return lca_tree_min(i + i + 1, sm + 1, sr, l, r); ll ans1 = lca_tree_min(i + i, sl, sm, l, sm); ll ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r); return lca_h[ans1] < lca_h[ans2] ? ans1 : ans2; } ll lca(ll a, ll b) { ll left = lca_first[a], right = lca_first[b]; if (left > right) swap(left, right); return lca_tree_min(1, 0, (ll)lca_dfs_list.size() - 1, left, right); } ll gcd(ll a, ll b) { if (a == 0) { return b; } return gcd(b % a, a); } ll fast_power(ll a, ll pow) { if (pow == 0) { return 1; } if (pow % 2 == 0) { auto x = fast_power(a, pow / 2); return (x * x); } else { auto x = fast_power(a, pow - 1); return (a * x); } } ll fast_power(ll a, ll pow, ll mod) { if (pow == 0) { return 1; } if (pow % 2 == 0) { auto x = fast_power(a, pow / 2, mod); return (x * x) % mod; } else { auto x = fast_power(a, pow - 1, mod); return (a * x) % mod; } } void getFactorialsModular(const ll n, const ll mod, vector<ll> &F) { F.resize(n + 1); F[0] = 1; for (ll i = 1; i <= n; ++i) { F[i] = (F[i - 1] * i) % mod; } } void getFactorialsAndInverseModular(const ll n, const ll mod, vector<ll> &F, vector<ll> &I) { getFactorialsModular(n, mod, F); I.resize(n + 1); I[0] = 1; for (ll i = 1; i <= n; ++i) { I[i] = fast_power(F[i], mod - 2, mod); } } ll CnkMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) { return (((F[n] * I[k]) % mod) * I[n - k]) % mod; } ll CnkWithRepetitionMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) { return CnkMod(n + k - 1, k - 1, mod, F, I); } /* MIT License Copyright (c) 2019 ouuan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // for further information and bug tracking, // please visit https://github.com/ouuan/segmentTree template <typename valueType, typename tagType> class segmentTreeNode { public: int id, left, right; valueType val; tagType tag; }; template <typename valueType, typename tagType, valueType (*merge)(valueType, valueType), void (*update)(segmentTreeNode<valueType, tagType> &, tagType)> class segmentTree { private: std::vector<segmentTreeNode<valueType, tagType>> nodes; int leftRange, rightRange; valueType valueZero; tagType tagZero; void push_up(int cur) { nodes[cur].val = merge(nodes[cur << 1].val, nodes[cur << 1 | 1].val); } void push_down(int cur) { update(nodes[cur << 1], nodes[cur].tag); update(nodes[cur << 1 | 1], nodes[cur].tag); nodes[cur].tag = tagZero; } void build(int cur, int l, int r, const std::vector<valueType> &initValue) { nodes[cur].id = cur; nodes[cur].left = l; nodes[cur].right = r; nodes[cur].tag = tagZero; if (l == r - 1) nodes[cur].val = initValue[l - leftRange]; else { build(cur << 1, l, (l + r) >> 1, initValue); build(cur << 1 | 1, (l + r) >> 1, r, initValue); push_up(cur); } } void init(const std::vector<valueType> &_initValue, const valueType &_valueZero, const tagType &_tagZero) { valueZero = _valueZero; tagZero = _tagZero; nodes.resize((rightRange - leftRange) << 2); build(1, leftRange, rightRange, _initValue); } void modify(int cur, int l, int r, int L, int R, const tagType &tag) { if (l >= R || r <= L) return; if (L <= l && r <= R) update(nodes[cur], tag); else { push_down(cur); modify(cur << 1, l, (l + r) >> 1, L, R, tag); modify(cur << 1 | 1, (l + r) >> 1, r, L, R, tag); push_up(cur); } } valueType query(int cur, int l, int r, int L, int R) { if (l >= R || r <= L) return valueZero; if (L <= l && r <= R) return nodes[cur].val; push_down(cur); return merge(query(cur << 1, l, (l + r) >> 1, L, R), query(cur << 1 | 1, (l + r) >> 1, r, L, R)); } public: segmentTree() {} segmentTree(int _leftRange, int _rightRange, const std::vector<valueType> &_initValue, const valueType &_valueZero, const tagType &_tagZero) { leftRange = _leftRange; rightRange = _rightRange; init(_initValue, _valueZero, _tagZero); } segmentTree(int size, const std::vector<valueType> &_initValue, const valueType &_valueZero, const tagType &_tagZero) { leftRange = 1; rightRange = size + 1; init(_initValue, _valueZero, _tagZero); } void modify(int l, int r, const tagType &tag) { modify(1, leftRange, rightRange, l, r, tag); } void modify(int p, const tagType &tag) { modify(p, p + 1, tag); } valueType query(int l, int r) { return query(1, leftRange, rightRange, l, r); } valueType query(int p) { return query(p, p + 1); } }; pair<ll, ll> merge(pair<ll, ll> x, pair<ll, ll> y) { return (x.second > y.second ? x : y); } void update(segmentTreeNode<pair<ll, ll>, pair<ll, ll>> &node, pair<ll, ll> x) { // node.val += x; } int main() { cin.tie(nullptr); cout.tie(nullptr); std::ios_base::sync_with_stdio(false); cout.precision(15); ll x, y; cin >> x >> y; set<ll> S; for (int i = 0; i < y; ++i) { ll a; cin >> a; S.insert(a); } if (!S.count(x)) { cout << x << endl; } else { ll cur = 1; while (true) { if (!S.count(x - cur)) { cout << x - cur << endl; return 0; } else if (!S.count(cur + x)) { cout << cur + x << endl; } else { ++cur; } } } }
#include <algorithm> #include <cassert> #include <cmath> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> //....................................................................................................................// using std::cin; using std::cout; using std::deque; using std::get; using std::greater; using std::ifstream; using std::ios_base; using std::less; using std::list; using std::lower_bound; using std::make_pair; using std::make_tuple; using std::map; using std::max; using std::max_element; using std::min; using std::min_element; using std::multimap; using std::multiset; using std::ofstream; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::stack; using std::string; using std::swap; using std::tuple; using std::unordered_map; using std::unordered_multimap; using std::unordered_set; using std::upper_bound; using std::vector; //....................................................................................................................// typedef long long ll; typedef unsigned long long ull; [[maybe_unused]] const string endl = "\n"; [[maybe_unused]] const string sep = " "; [[maybe_unused]] const string yes = "YES\n"; [[maybe_unused]] const string no = "NO\n"; [[maybe_unused]] const string ng = "NG\n"; [[maybe_unused]] const string ok = "OK\n"; [[maybe_unused]] const double pi = acos(-1); [[maybe_unused]] const ull modular = 998244353; //....................................................................................................................// template <class T> T min(const T &a, const T &b, const T &c) { return min(a, min(b, c)); } template <class T> T max(const T &a, const T &b, const T &c) { return max(a, max(b, c)); } typedef vector<vector<ll>> graph; vector<ll> lca_h, lca_dfs_list, lca_first, lca_tree; vector<char> lca_dfs_used; void lca_dfs(const graph &g, ll v, ll h = 1) { lca_dfs_used[v] = true; lca_h[v] = h; lca_dfs_list.push_back(v); for (auto i = g[v].begin(); i != g[v].end(); ++i) if (!lca_dfs_used[*i]) { lca_dfs(g, *i, h + 1); lca_dfs_list.push_back(v); } } void lca_build_tree(ll i, ll l, ll r) { if (l == r) lca_tree[i] = lca_dfs_list[l]; else { ll m = (l + r) >> 1; lca_build_tree(i + i, l, m); lca_build_tree(i + i + 1, m + 1, r); if (lca_h[lca_tree[i + i]] < lca_h[lca_tree[i + i + 1]]) lca_tree[i] = lca_tree[i + i]; else lca_tree[i] = lca_tree[i + i + 1]; } } void lca_prepare(const graph &g, ll root) { ll n = (ll)g.size(); lca_h.resize(n); lca_dfs_list.reserve(n * 2); lca_dfs_used.assign(n, 0); lca_dfs(g, root); ll m = (ll)lca_dfs_list.size(); lca_tree.assign(lca_dfs_list.size() * 4 + 1, -1); lca_build_tree(1, 0, m - 1); lca_first.assign(n, -1); for (ll i = 0; i < m; ++i) { ll v = lca_dfs_list[i]; if (lca_first[v] == -1) lca_first[v] = i; } } ll lca_tree_min(ll i, ll sl, ll sr, ll l, ll r) { if (sl == l && sr == r) return lca_tree[i]; ll sm = (sl + sr) >> 1; if (r <= sm) return lca_tree_min(i + i, sl, sm, l, r); if (l > sm) return lca_tree_min(i + i + 1, sm + 1, sr, l, r); ll ans1 = lca_tree_min(i + i, sl, sm, l, sm); ll ans2 = lca_tree_min(i + i + 1, sm + 1, sr, sm + 1, r); return lca_h[ans1] < lca_h[ans2] ? ans1 : ans2; } ll lca(ll a, ll b) { ll left = lca_first[a], right = lca_first[b]; if (left > right) swap(left, right); return lca_tree_min(1, 0, (ll)lca_dfs_list.size() - 1, left, right); } ll gcd(ll a, ll b) { if (a == 0) { return b; } return gcd(b % a, a); } ll fast_power(ll a, ll pow) { if (pow == 0) { return 1; } if (pow % 2 == 0) { auto x = fast_power(a, pow / 2); return (x * x); } else { auto x = fast_power(a, pow - 1); return (a * x); } } ll fast_power(ll a, ll pow, ll mod) { if (pow == 0) { return 1; } if (pow % 2 == 0) { auto x = fast_power(a, pow / 2, mod); return (x * x) % mod; } else { auto x = fast_power(a, pow - 1, mod); return (a * x) % mod; } } void getFactorialsModular(const ll n, const ll mod, vector<ll> &F) { F.resize(n + 1); F[0] = 1; for (ll i = 1; i <= n; ++i) { F[i] = (F[i - 1] * i) % mod; } } void getFactorialsAndInverseModular(const ll n, const ll mod, vector<ll> &F, vector<ll> &I) { getFactorialsModular(n, mod, F); I.resize(n + 1); I[0] = 1; for (ll i = 1; i <= n; ++i) { I[i] = fast_power(F[i], mod - 2, mod); } } ll CnkMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) { return (((F[n] * I[k]) % mod) * I[n - k]) % mod; } ll CnkWithRepetitionMod(ll n, ll k, ll mod, vector<ll> &F, vector<ll> &I) { return CnkMod(n + k - 1, k - 1, mod, F, I); } /* MIT License Copyright (c) 2019 ouuan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // for further information and bug tracking, // please visit https://github.com/ouuan/segmentTree template <typename valueType, typename tagType> class segmentTreeNode { public: int id, left, right; valueType val; tagType tag; }; template <typename valueType, typename tagType, valueType (*merge)(valueType, valueType), void (*update)(segmentTreeNode<valueType, tagType> &, tagType)> class segmentTree { private: std::vector<segmentTreeNode<valueType, tagType>> nodes; int leftRange, rightRange; valueType valueZero; tagType tagZero; void push_up(int cur) { nodes[cur].val = merge(nodes[cur << 1].val, nodes[cur << 1 | 1].val); } void push_down(int cur) { update(nodes[cur << 1], nodes[cur].tag); update(nodes[cur << 1 | 1], nodes[cur].tag); nodes[cur].tag = tagZero; } void build(int cur, int l, int r, const std::vector<valueType> &initValue) { nodes[cur].id = cur; nodes[cur].left = l; nodes[cur].right = r; nodes[cur].tag = tagZero; if (l == r - 1) nodes[cur].val = initValue[l - leftRange]; else { build(cur << 1, l, (l + r) >> 1, initValue); build(cur << 1 | 1, (l + r) >> 1, r, initValue); push_up(cur); } } void init(const std::vector<valueType> &_initValue, const valueType &_valueZero, const tagType &_tagZero) { valueZero = _valueZero; tagZero = _tagZero; nodes.resize((rightRange - leftRange) << 2); build(1, leftRange, rightRange, _initValue); } void modify(int cur, int l, int r, int L, int R, const tagType &tag) { if (l >= R || r <= L) return; if (L <= l && r <= R) update(nodes[cur], tag); else { push_down(cur); modify(cur << 1, l, (l + r) >> 1, L, R, tag); modify(cur << 1 | 1, (l + r) >> 1, r, L, R, tag); push_up(cur); } } valueType query(int cur, int l, int r, int L, int R) { if (l >= R || r <= L) return valueZero; if (L <= l && r <= R) return nodes[cur].val; push_down(cur); return merge(query(cur << 1, l, (l + r) >> 1, L, R), query(cur << 1 | 1, (l + r) >> 1, r, L, R)); } public: segmentTree() {} segmentTree(int _leftRange, int _rightRange, const std::vector<valueType> &_initValue, const valueType &_valueZero, const tagType &_tagZero) { leftRange = _leftRange; rightRange = _rightRange; init(_initValue, _valueZero, _tagZero); } segmentTree(int size, const std::vector<valueType> &_initValue, const valueType &_valueZero, const tagType &_tagZero) { leftRange = 1; rightRange = size + 1; init(_initValue, _valueZero, _tagZero); } void modify(int l, int r, const tagType &tag) { modify(1, leftRange, rightRange, l, r, tag); } void modify(int p, const tagType &tag) { modify(p, p + 1, tag); } valueType query(int l, int r) { return query(1, leftRange, rightRange, l, r); } valueType query(int p) { return query(p, p + 1); } }; pair<ll, ll> merge(pair<ll, ll> x, pair<ll, ll> y) { return (x.second > y.second ? x : y); } void update(segmentTreeNode<pair<ll, ll>, pair<ll, ll>> &node, pair<ll, ll> x) { // node.val += x; } int main() { cin.tie(nullptr); cout.tie(nullptr); std::ios_base::sync_with_stdio(false); cout.precision(15); ll x, y; cin >> x >> y; set<ll> S; for (int i = 0; i < y; ++i) { ll a; cin >> a; S.insert(a); } if (!S.count(x)) { cout << x << endl; } else { ll cur = 1; while (true) { if (!S.count(x - cur)) { cout << x - cur << endl; return 0; } else if (!S.count(cur + x)) { cout << cur + x << endl; return 0; } else { ++cur; } } } }
insert
364
364
364
365
TLE
p02641
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; using P = pair<int, int>; int main() { int x, n; cin >> x >> n; vector<int> d(n); for (int i = 0; i < n; ++i) { int p; cin >> p; d[p] = 1; } P ans(99999, -1); for (int i = 0; i <= 101; ++i) { if (d[i] == 1) continue; int dif = abs(x - i); ans = min(ans, P(dif, i)); } cout << ans.second << endl; return 0; }
#include <iostream> #include <vector> using namespace std; using P = pair<int, int>; int main() { int x, n; cin >> x >> n; vector<int> d(102); for (int i = 0; i < n; ++i) { int p; cin >> p; d[p] = 1; } P ans(99999, -1); for (int i = 0; i <= 101; ++i) { if (d[i] == 1) continue; int dif = abs(x - i); ans = min(ans, P(dif, i)); } cout << ans.second << endl; return 0; }
replace
8
9
8
9
-6
malloc(): corrupted top size
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int target, n; cin >> target >> n; if (n == 0) { cout << target << endl; return 0; } vector<int> ex(n); for (int i = 0; i < n; i++) { cin >> ex.at(i); } vector<int> dx(101); for (int i = 0; i < n; i++) { dx.at(ex.at(i)) = 1; } for (int i = 0; i < 101; i++) { if (dx.at(target - i) == 0) { cout << target - i << endl; break; } if (dx.at(target + i) == 0) { cout << target + i << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int target, n; cin >> target >> n; if (n == 0) { cout << target << endl; return 0; } vector<int> ex(n); for (int i = 0; i < n; i++) { cin >> ex.at(i); } vector<int> dx(202); for (int i = 0; i < n; i++) { dx.at(ex.at(i)) = 1; } for (int i = 0; i < 101; i++) { if (dx.at(target - i) == 0) { cout << target - i << endl; break; } if (dx.at(target + i) == 0) { cout << target + i << endl; break; } } return 0; }
replace
17
18
17
18
0
p02641
C++
Time Limit Exceeded
// AUTHOR wiley_codechef // TASK : Atcoder //--------------------------------HEADERS-------------------------------------------------------------// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_set> #include <utility> #include <vector> using namespace std; //-------------------------------------------------------Typedefs----------------------------------------------// typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; //---------------------------------------------------------Hash //defines--------------------------------------------------// #define PII 3.14159265358979323846 #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define FOREACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define T(a) \ ll a; \ cin >> a; #define TT(t) \ T(t); \ while (t--) #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define f(i, x, y) for (int i = x; i < y; i++) #define array(a) ll a[n]; #define line "\n"; //-------------------------------------------------TEMPLATES----------------------------------------------------------// template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } void SieveOfEratosthenes(ll n) // O(nloglogn) { ll prime[n]; memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } } bool isPrime(ll n) // O(sqrt(n)) { if (n < 2) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } std::vector<ll> generatePrimeFactors(ll n) { std::vector<ll> prime; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { prime.pb(i); while (n % i == 0) n = n / i; } } if (n != 1) prime.pb(n); return prime; } std::vector<ll> generateFactors(ll n) { std::vector<ll> fact; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { fact.pb(i); if (n / i != i) fact.pb(n / i); // 24 - 1,2,3,4,6,8,12 } } fact.pb(1); if (n != 1) fact.pb(n); sort(fact.begin(), fact.end()); return fact; } ll extendedGCD(ll a, ll b, ll &x, ll &y) { // produces correct results for negative integers as well if (a == 0) { x = 0; y = 1; return b; } ll x1, y1, d; d = extendedGCD(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } ll gcd(ll a, ll b) // O(log min(a,b)) { /* recursive implementation below if(!b) return a; return gcd(b,a%b); */ // non-recursive implementation below while (b) { a %= b; swap(a, b); } return a; } ll multiply(ll a, ll b, ll m); ll singlemod(ll a, ll m); ll modpow(ll x, ll n, ll m) // O(logn)// used for calculating (x^n)%m { if (n == 0) return 1; ll res = 1; while (n) { if (n % 2) res = multiply(res, x, m); x = multiply(x, x, m); n = n >> 1; } return singlemod(res, m); } ll fastpow(ll x, ll n) { if (n == 0) return 1; ll res = 1; while (n) { if (n % 2) res = res * x; x = x * x; n = n >> 1; } return res; } ll modinverse(ll x, ll m) // O(logn) { return modpow(x, m - 2, m); } ll add(ll a, ll b, ll m) { return (((a % m) + (b % m)) % m); } ll substract(ll a, ll b, ll m) { // if (a < b) // swap(a, b); return (((a % m) - (b % m) + m) % m); } ll multiply(ll a, ll b, ll m) { return (((a % m) * (b % m)) % m); } ll divide(ll a, ll b, ll m) { ll temp = modinverse(b, m); return multiply(a, temp, m); } ll singlemod(ll a, ll m) { return (a % m); } ll eulerstotientfunction(ll n) // O(sqrt(n)) { ll ans = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n = n / i; ans -= ans / i; } } if (n > 1) ans -= ans / n; return ans; } ll ncr(ll n, ll k, ll m) { if (k > n) return 0; if (m == 0) { ll res = 1; k = min(k, n - k); for (ll i = 1; i <= k; i++) { res *= (n - i + 1); res /= i; } return res; } else { ll res = 1; k = min(k, n - k); for (ll i = 1; i <= k; i++) { res = multiply(res, n - i + 1, m); res = divide(res, i, m); } return singlemod(res, m); } } ll kadaneAlgo(const std::vector<ll> &arr) { ll size = arr.size(); ll currmax = arr[0], maxsofar = arr[0]; for (ll i = 1; i < size; i++) { // debug2(currmax,maxsofar); currmax = max(arr[i], currmax + arr[i]); maxsofar = max(maxsofar, currmax); } return maxsofar; } ll getDigitSum(ll n) { ll co = 0; while (n > 0) { co += n % 10; n = n / 10; } return co; } template <class T> void printVector(const std::vector<T> arr) { for (auto i : arr) cout << i << " "; cout << endl; } template <class T> void printArray(T arr[], ll n) { for (ll i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } // const int p1 = 13331,m1 = 1e9+9,p2 = 7919, m2 = 1e9+9; // const int p1 = 97266353,m1 = 972663749,p2 = 97336357, m2 = 1000000007; // const int p1 = 31 ,m1 = 1e9+7; // grid cells // D U R L // ll dx[] = {1, -1, 0, 0}; // ll dy[] = {0, 0, 1, -1}; bool is_perfect(int x) { long double y = sqrt(x); return ((y - floor(y)) == 0); } bool check(int p, int n) { int temp = p, count = 0, f = 5; while (f <= temp) { count += temp / f; f = f * 5; } return (count >= n); } int wiley() { T(x) T(n) array(a) REP(i, n) cin >> a[i]; sort(a, a + n); ll ans = 0; REPN(i, 100000) { if (!binary_search(a, a + n, x - i)) { ans = x - i; break; } else if (!binary_search(a, a + n, x + i)) { ans = x + i; break; } } if (n == 0) cout << x; else cout << ans; } int main() { // Fast I/O --- Vroom Vroom // IOS // TT(t){ // read(); wiley(); // By Order of Peaky Blinders. // } return 0; }
// AUTHOR wiley_codechef // TASK : Atcoder //--------------------------------HEADERS-------------------------------------------------------------// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_set> #include <utility> #include <vector> using namespace std; //-------------------------------------------------------Typedefs----------------------------------------------// typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; //---------------------------------------------------------Hash //defines--------------------------------------------------// #define PII 3.14159265358979323846 #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define FOREACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define T(a) \ ll a; \ cin >> a; #define TT(t) \ T(t); \ while (t--) #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define f(i, x, y) for (int i = x; i < y; i++) #define array(a) ll a[n]; #define line "\n"; //-------------------------------------------------TEMPLATES----------------------------------------------------------// template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } void SieveOfEratosthenes(ll n) // O(nloglogn) { ll prime[n]; memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } } bool isPrime(ll n) // O(sqrt(n)) { if (n < 2) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } std::vector<ll> generatePrimeFactors(ll n) { std::vector<ll> prime; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { prime.pb(i); while (n % i == 0) n = n / i; } } if (n != 1) prime.pb(n); return prime; } std::vector<ll> generateFactors(ll n) { std::vector<ll> fact; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { fact.pb(i); if (n / i != i) fact.pb(n / i); // 24 - 1,2,3,4,6,8,12 } } fact.pb(1); if (n != 1) fact.pb(n); sort(fact.begin(), fact.end()); return fact; } ll extendedGCD(ll a, ll b, ll &x, ll &y) { // produces correct results for negative integers as well if (a == 0) { x = 0; y = 1; return b; } ll x1, y1, d; d = extendedGCD(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } ll gcd(ll a, ll b) // O(log min(a,b)) { /* recursive implementation below if(!b) return a; return gcd(b,a%b); */ // non-recursive implementation below while (b) { a %= b; swap(a, b); } return a; } ll multiply(ll a, ll b, ll m); ll singlemod(ll a, ll m); ll modpow(ll x, ll n, ll m) // O(logn)// used for calculating (x^n)%m { if (n == 0) return 1; ll res = 1; while (n) { if (n % 2) res = multiply(res, x, m); x = multiply(x, x, m); n = n >> 1; } return singlemod(res, m); } ll fastpow(ll x, ll n) { if (n == 0) return 1; ll res = 1; while (n) { if (n % 2) res = res * x; x = x * x; n = n >> 1; } return res; } ll modinverse(ll x, ll m) // O(logn) { return modpow(x, m - 2, m); } ll add(ll a, ll b, ll m) { return (((a % m) + (b % m)) % m); } ll substract(ll a, ll b, ll m) { // if (a < b) // swap(a, b); return (((a % m) - (b % m) + m) % m); } ll multiply(ll a, ll b, ll m) { return (((a % m) * (b % m)) % m); } ll divide(ll a, ll b, ll m) { ll temp = modinverse(b, m); return multiply(a, temp, m); } ll singlemod(ll a, ll m) { return (a % m); } ll eulerstotientfunction(ll n) // O(sqrt(n)) { ll ans = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n = n / i; ans -= ans / i; } } if (n > 1) ans -= ans / n; return ans; } ll ncr(ll n, ll k, ll m) { if (k > n) return 0; if (m == 0) { ll res = 1; k = min(k, n - k); for (ll i = 1; i <= k; i++) { res *= (n - i + 1); res /= i; } return res; } else { ll res = 1; k = min(k, n - k); for (ll i = 1; i <= k; i++) { res = multiply(res, n - i + 1, m); res = divide(res, i, m); } return singlemod(res, m); } } ll kadaneAlgo(const std::vector<ll> &arr) { ll size = arr.size(); ll currmax = arr[0], maxsofar = arr[0]; for (ll i = 1; i < size; i++) { // debug2(currmax,maxsofar); currmax = max(arr[i], currmax + arr[i]); maxsofar = max(maxsofar, currmax); } return maxsofar; } ll getDigitSum(ll n) { ll co = 0; while (n > 0) { co += n % 10; n = n / 10; } return co; } template <class T> void printVector(const std::vector<T> arr) { for (auto i : arr) cout << i << " "; cout << endl; } template <class T> void printArray(T arr[], ll n) { for (ll i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } // const int p1 = 13331,m1 = 1e9+9,p2 = 7919, m2 = 1e9+9; // const int p1 = 97266353,m1 = 972663749,p2 = 97336357, m2 = 1000000007; // const int p1 = 31 ,m1 = 1e9+7; // grid cells // D U R L // ll dx[] = {1, -1, 0, 0}; // ll dy[] = {0, 0, 1, -1}; bool is_perfect(int x) { long double y = sqrt(x); return ((y - floor(y)) == 0); } bool check(int p, int n) { int temp = p, count = 0, f = 5; while (f <= temp) { count += temp / f; f = f * 5; } return (count >= n); } int wiley() { int x, n, a; if (n == 0) { cout << x << endl; return 0; } cin >> x >> n; set<int> s; for (int i = 0; i < n; ++i) { cin >> a; s.insert(a); } int ans1 = x, ans2 = x; while (true) { if (!s.count(ans1)) { cout << ans1 << endl; return 0; } if (!s.count(ans2)) { cout << ans2 << endl; return 0; } --ans1; ++ans2; } } int main() { // Fast I/O --- Vroom Vroom // IOS // TT(t){ // read(); wiley(); // By Order of Peaky Blinders. // } return 0; }
replace
330
348
330
354
TLE
p02641
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { int X, N; vector<int> p; vector<pair<int, int>> q; cin >> X >> N; int y; rep(i, N) { cin >> y; p.push_back(y); } for (int i = 1; i <= 100; i++) { auto result = find(p.begin(), p.end(), i); if (result == p.end()) { q.push_back(make_pair((X - i) * (X - i), i)); } } sort(q.begin(), q.end()); cout << q[0].second << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { int X, N; vector<int> p; vector<pair<int, int>> q; cin >> X >> N; int y; rep(i, N) { cin >> y; p.push_back(y); } for (int i = 0; i <= 101; i++) { auto result = find(p.begin(), p.end(), i); if (result == p.end()) { q.push_back(make_pair((X - i) * (X - i), i)); } } sort(q.begin(), q.end()); cout << q[0].second << endl; return 0; }
replace
16
17
16
17
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repc(i, a, b) for (int i = a; i <= (int)(b); i++) #define ll long long #define vec vector #define ft first #define sd second #define all(vec) vec.begin(), vec.end() typedef pair<int, int> P; const int MOD = 1e9 + 7; const int INF = 1001001001; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------------------------// int main() { int x, n; cin >> x >> n; vec<bool> p(101, false); rep(i, n) { int y; cin >> y; p[y] = true; } int l = x, r = x; int ans = 0; while (ans == 0) { if (p[l] == false && p[r] == false) ans = l; else if (p[l] == false && p[r] == true) ans = l; else if (p[l] == true && p[r] == false) ans = r; l--; r++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repc(i, a, b) for (int i = a; i <= (int)(b); i++) #define ll long long #define vec vector #define ft first #define sd second #define all(vec) vec.begin(), vec.end() typedef pair<int, int> P; const int MOD = 1e9 + 7; const int INF = 1001001001; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------------------------// int main() { int x, n; cin >> x >> n; vec<bool> p(101, false); rep(i, n) { int y; cin >> y; p[y] = true; } int l = x, r = x; int ans = 0; while (ans == 0) { if (l == 0) { ans = 0; break; } if (p[l] == false && p[r] == false) ans = l; else if (p[l] == false && p[r] == true) ans = l; else if (p[l] == true && p[r] == false) ans = r; l--; r++; } cout << ans << endl; return 0; }
insert
30
30
30
34
0
p02641
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { int X, N; cin >> X >> N; int *p; p = new int[N]; for (int i = 0; i < N; i++) { cin >> p[i]; } bool found = true; int output = 0; for (int i = 0; i < N; i++) { if (p[i] == X) { found = true; i = N; } else { found = false; output = X; } } int j = 1; while (found) { for (int i = 0; i < N; i++) { if (p[i] == X - j) { found = true; i = N; } else { found = false; output = X - j; } } if (found) { for (int i = 0; i < N; i++) { if (p[i] == X + j) { found = true; i = N; } else { found = false; output = X + j; } } } j++; } cout << output; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { int X, N; cin >> X >> N; int *p; p = new int[N]; for (int i = 0; i < N; i++) { cin >> p[i]; } bool found = true; int output = 0; for (int i = 0; i < N; i++) { if (p[i] == X) { found = true; i = N; } else { found = false; output = X; } } if (N == 0) { found = false; output = X; } int j = 1; while (found) { for (int i = 0; i < N; i++) { if (p[i] == X - j) { found = true; i = N; } else { found = false; output = X - j; } } if (found) { for (int i = 0; i < N; i++) { if (p[i] == X + j) { found = true; i = N; } else { found = false; output = X + j; } } } j++; } cout << output; return 0; }
insert
28
28
28
34
TLE
p02641
C++
Runtime Error
#include <bits/stdc++.h> #define fin \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ii pair<int, int> #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fore(i, a, b) for (int i = a; i < b; i += 1) #define forr(i, a) for (int i = a; i >= 0; i--) #define fori(i, m) for (auto i = m.begin(); i != m.end(); i++) #define w(t) while (t--) #define sz(s) int(s.size()) #define cls(a, car) memset(a, car, sizeof(a)) #define db(x) cerr << #x << " is " << x << '\n' #define FL freopen("in", "r", stdin), freopen("out", "w", stdout); #define EjecuteTime \ cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n" #define angle(x) double(x * acos(-1) / 180.0) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; const int N = 2 * 1e5 + 5; const ll mod = 1e9 + 7; const double E = 1e-9; // int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; // int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; // fflush(stdout) // cout << flush // a + b = a ^ b + 2 * (a & b) int occ[105]; int main() { // FL; fin; int x, n; cin >> x >> n; vi v; fore(i, 0, n) { int y; cin >> y; occ[y] = 1; } fore(i, 1, 101) if (occ[i] == 0) v.pb(i); int a = 0, b = sz(v), mid; while (b - a > 1) { mid = (a + b) >> 1; if (v[mid] <= x) a = mid; else b = mid; } int val1 = v[a]; a = -1; b = sz(v) - 1; while (b - a > 1) { mid = (a + b) >> 1; if (v[mid] >= x) b = mid; else a = mid; } int val2 = v[b]; if (abs(val1 - x) == abs(val2 - x)) cout << min(val1, val2) << '\n'; else { if (abs(val1 - x) < abs(val2 - x)) cout << val1 << '\n'; else cout << val2 << '\n'; } EjecuteTime; return 0; }
#include <bits/stdc++.h> #define fin \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ii pair<int, int> #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fore(i, a, b) for (int i = a; i < b; i += 1) #define forr(i, a) for (int i = a; i >= 0; i--) #define fori(i, m) for (auto i = m.begin(); i != m.end(); i++) #define w(t) while (t--) #define sz(s) int(s.size()) #define cls(a, car) memset(a, car, sizeof(a)) #define db(x) cerr << #x << " is " << x << '\n' #define FL freopen("in", "r", stdin), freopen("out", "w", stdout); #define EjecuteTime \ cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n" #define angle(x) double(x * acos(-1) / 180.0) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; const int N = 2 * 1e5 + 5; const ll mod = 1e9 + 7; const double E = 1e-9; // int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; // int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; // fflush(stdout) // cout << flush // a + b = a ^ b + 2 * (a & b) int occ[105]; int main() { // FL; fin; int x, n; cin >> x >> n; vi v; fore(i, 0, n) { int y; cin >> y; occ[y] = 1; } fore(i, 0, 105) if (occ[i] == 0) v.pb(i); int a = 0, b = sz(v), mid; while (b - a > 1) { mid = (a + b) >> 1; if (v[mid] <= x) a = mid; else b = mid; } int val1 = v[a]; a = -1; b = sz(v) - 1; while (b - a > 1) { mid = (a + b) >> 1; if (v[mid] >= x) b = mid; else a = mid; } int val2 = v[b]; if (abs(val1 - x) == abs(val2 - x)) cout << min(val1, val2) << '\n'; else { if (abs(val1 - x) < abs(val2 - x)) cout << val1 << '\n'; else cout << val2 << '\n'; } EjecuteTime; return 0; }
replace
46
47
46
47
0
Time elapsed: 0.025323 s.
p02641
Python
Runtime Error
X, N = map(int, input().split()) p = list(map(int, input().split())) if p: x = [i for i in range(1, max(p)) if i not in p] c = x.pop() a = abs(c - X) for i in x: if abs(i - X) < a: c = i print(c) else: print(X)
X, N = map(int, input().split()) p = list(map(int, input().split())) i = 0 while True: if X - i not in p: print(X - i) break elif X + i not in p: print(X + i) break i += 1
replace
3
14
3
12
0
p02641
Python
Runtime Error
def main(): x, n = map(int, input().split()) p = list(map(int, input().split())) min = 1000 for i in range(1, 101): if i in p: continue elif min > abs(x - i): result = i min = abs(x - i) print(result) if __name__ == "__main__": main()
def main(): x, n = map(int, input().split()) p = list(map(int, input().split())) min = 1000 for i in range(-50, 150): if i in p: continue elif min > abs(x - i): result = i min = abs(x - i) print(result) if __name__ == "__main__": main()
replace
6
7
6
7
0
p02641
Python
Runtime Error
x, n = map(int, input().split()) if n != 0: p = list(map(int, input().split())) if x in p: for i in range(-1000, 1001): print(i) if i == -100: mini = i if i in p: pass else: if abs(x - mini) > abs(x - i): mini = i elif abs(x - mini) == abs(x - i): mini = min(mini, i) else: print(mini) else: print(x) else: print(x)
x, n = map(int, input().split()) if n != 0: p = list(map(int, input().split())) if x in p: for i in range(-1000, 1001): if i == -1000: mini = i if i in p: pass else: if abs(x - mini) > abs(x - i): mini = i elif abs(x - mini) == abs(x - i): mini = min(mini, i) else: print(mini) else: print(x) else: print(x)
replace
5
7
5
6
NameError: name 'mini' is not defined. Did you mean: 'min'?
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02641/Python/s131160105.py", line 12, in <module> if abs(x - mini) > abs(x - i): NameError: name 'mini' is not defined. Did you mean: 'min'?
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define ull unsigned long long #define ld long double #define endl "\n" #define ff first #define ss second #define pi pair<ll, ll> #define PI 3.141592653589793238462643383279502884L #define mp make_pair #define pb push_back #define fall(i, a, b) for (int i = a; i < b; i++) #define sz(x) (ll) x.size() #define all(x) x.begin(), x.end() #define ed cout << "ed"; ll MOD = 1e9 + 7; ll MOD1 = 1e9 + 123; ll MOD2 = 1e9 + 321; // ll mod(ll a, ll m) // { // if (a == 0) // return 0; // else // return (a % m + m) % m; // } // int mod(string num, int a) // { // int res = 0; // for (int i = 0; i < num.length(); i++) // res = (res * 10 + (int)num[i] - '0') % a; // return res; // } // ll d, x, y; // void extendedEuclid(int A, int B) // { // if (B == 0) // { // d = A; // x = 1; // y = 0; // } // else // { // extendedEuclid(B, A % B); // int temp = x; // x = y; // y = temp - (A / B) * y; // } // } // ll modInverse(int A, int M) // { // extendedEuclid(A, M); // return (x % M + M) % M; // } // // Generate random base in (before, after) open interval: // int gen_base(const int before, const int after) // { // auto seed = // std::chrono::high_resolution_clock::now().time_since_epoch().count(); // std::mt19937 mt_rand(seed); // int base = std::uniform_int_distribution<int>(before + 1, // after)(mt_rand); return base % 2 == 0 ? base - 1 : base; // } ll poow(ll a, ll b, ll m) { if (b == 0) return 1; else if (b % 2 == 0) return ((ll)poow((a % m) * (a % m), b / 2, m) % m); else return ((a % m) * ((ll)poow((a % m) * (a % m), b / 2, m) % m)) % m; } // vector<int> rabin_karp(string const &t, string const &s) //string ,pattern // { // const ll p1 = gen_base(3597, MOD1); // const ll p2 = gen_base(3597, MOD2); // const ll m1 = MOD1; // const ll m2 = MOD2; // ll S = s.size(), T = t.size(); // vector<long long> p_pow1(max(S, T)), p_pow2(max(S, T)); // p_pow1[0] = 1; // p_pow2[0] = 1; // for (int i = 1; i < (int)p_pow1.size(); i++) // { // p_pow1[i] = (p_pow1[i - 1] * p1) % m1; // p_pow2[i] = (p_pow2[i - 1] * p2) % m2; // } // vector<long long> h1(T + 1, 0), h2(T + 1, 0); // for (int i = 0; i < T; i++) // { // h1[i + 1] = (h1[i] + (t[i]) * p_pow1[i]) % m1; // h2[i + 1] = (h2[i] + (t[i]) * p_pow2[i]) % m2; // } // long long h_s1 = 0, h_s2 = 0; // for (int i = 0; i < S; i++) // { // h_s1 = (h_s1 + (s[i]) * p_pow1[i]) % m1; // h_s2 = (h_s2 + (s[i]) * p_pow2[i]) % m2; // } // vector<int> occurences; // for (int i = 0; i + S - 1 < T; i++) // { // long long cur_h1 = (h1[i + S] + m1 - h1[i]) % m1; // long long cur_h2 = (h2[i + S] + m2 - h2[i]) % m2; // if (cur_h1 == h_s1 * p_pow1[i] % m1 && cur_h2 == h_s2 * p_pow2[i] % // m2) // occurences.push_back(i); // } // return occurences; // } // vector<int> Q; // vector<int> G[1000000]; // vector<int> L(1000000, 0); // vector<int> vis(1000000, 0); // void dfs(ll y) // { // vis[y] = 1; // Q.pb(y); // for (auto h : G[y]) // { // if (vis[h] == 0) // dfs(h); // } // } // bool is_bipartite(ll y, ll d) // { // vis[y] = true; // L[y] = d; // for (auto h : G[y]) // if (vis[h] == false) // return is_bipartite(h, 1 ^ d); // else if (L[h] == d) // return false; // return true; // } bool compa(string a, string b) { if (a.length() <= b.length()) return true; else return false; } int main() { fio; ll t, a, n, q, k, i, m, c, u, f, j, p, r, x, y, s, b, d; // Sieve // p= 1000000; // bool a[p]; // for (i = 2; i <= p; i += 1) // a[i] = true; // a[0] = false; // a[1] = false; // for (i = 2; i * i <= p; i += 1) // { // if (a[i] == true) // for (j = i * i; j <= p; j += i) // a[j] = false; // } cin >> n >> t; if (t == 0) cout << n; else { vector<ll> v; unordered_map<ll, ll> MA; for (i = 0; i < t; i++) { cin >> p; MA[p]++; } for (i = 0; i < 100; i++) { if (MA.find(i + 1) == MA.end()) v.pb(i + 1); } a = 0; b = v.size() - 1; while (a <= b) { m = a + (b - a) / 2; if (v[m] == n) break; else if (v[m] < n) a = m + 1; else b = m - 1; } if (v[m] == n) cout << n; else if (b < 0) cout << v[a]; else if (a >= 100) cout << v[b]; else if (abs(v[a] - n) == abs(v[b] - n)) cout << min(v[a], v[b]); else if (abs(v[a] - n) > abs(v[b] - n)) cout << v[b]; else cout << v[a]; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define ull unsigned long long #define ld long double #define endl "\n" #define ff first #define ss second #define pi pair<ll, ll> #define PI 3.141592653589793238462643383279502884L #define mp make_pair #define pb push_back #define fall(i, a, b) for (int i = a; i < b; i++) #define sz(x) (ll) x.size() #define all(x) x.begin(), x.end() #define ed cout << "ed"; ll MOD = 1e9 + 7; ll MOD1 = 1e9 + 123; ll MOD2 = 1e9 + 321; // ll mod(ll a, ll m) // { // if (a == 0) // return 0; // else // return (a % m + m) % m; // } // int mod(string num, int a) // { // int res = 0; // for (int i = 0; i < num.length(); i++) // res = (res * 10 + (int)num[i] - '0') % a; // return res; // } // ll d, x, y; // void extendedEuclid(int A, int B) // { // if (B == 0) // { // d = A; // x = 1; // y = 0; // } // else // { // extendedEuclid(B, A % B); // int temp = x; // x = y; // y = temp - (A / B) * y; // } // } // ll modInverse(int A, int M) // { // extendedEuclid(A, M); // return (x % M + M) % M; // } // // Generate random base in (before, after) open interval: // int gen_base(const int before, const int after) // { // auto seed = // std::chrono::high_resolution_clock::now().time_since_epoch().count(); // std::mt19937 mt_rand(seed); // int base = std::uniform_int_distribution<int>(before + 1, // after)(mt_rand); return base % 2 == 0 ? base - 1 : base; // } ll poow(ll a, ll b, ll m) { if (b == 0) return 1; else if (b % 2 == 0) return ((ll)poow((a % m) * (a % m), b / 2, m) % m); else return ((a % m) * ((ll)poow((a % m) * (a % m), b / 2, m) % m)) % m; } // vector<int> rabin_karp(string const &t, string const &s) //string ,pattern // { // const ll p1 = gen_base(3597, MOD1); // const ll p2 = gen_base(3597, MOD2); // const ll m1 = MOD1; // const ll m2 = MOD2; // ll S = s.size(), T = t.size(); // vector<long long> p_pow1(max(S, T)), p_pow2(max(S, T)); // p_pow1[0] = 1; // p_pow2[0] = 1; // for (int i = 1; i < (int)p_pow1.size(); i++) // { // p_pow1[i] = (p_pow1[i - 1] * p1) % m1; // p_pow2[i] = (p_pow2[i - 1] * p2) % m2; // } // vector<long long> h1(T + 1, 0), h2(T + 1, 0); // for (int i = 0; i < T; i++) // { // h1[i + 1] = (h1[i] + (t[i]) * p_pow1[i]) % m1; // h2[i + 1] = (h2[i] + (t[i]) * p_pow2[i]) % m2; // } // long long h_s1 = 0, h_s2 = 0; // for (int i = 0; i < S; i++) // { // h_s1 = (h_s1 + (s[i]) * p_pow1[i]) % m1; // h_s2 = (h_s2 + (s[i]) * p_pow2[i]) % m2; // } // vector<int> occurences; // for (int i = 0; i + S - 1 < T; i++) // { // long long cur_h1 = (h1[i + S] + m1 - h1[i]) % m1; // long long cur_h2 = (h2[i + S] + m2 - h2[i]) % m2; // if (cur_h1 == h_s1 * p_pow1[i] % m1 && cur_h2 == h_s2 * p_pow2[i] % // m2) // occurences.push_back(i); // } // return occurences; // } // vector<int> Q; // vector<int> G[1000000]; // vector<int> L(1000000, 0); // vector<int> vis(1000000, 0); // void dfs(ll y) // { // vis[y] = 1; // Q.pb(y); // for (auto h : G[y]) // { // if (vis[h] == 0) // dfs(h); // } // } // bool is_bipartite(ll y, ll d) // { // vis[y] = true; // L[y] = d; // for (auto h : G[y]) // if (vis[h] == false) // return is_bipartite(h, 1 ^ d); // else if (L[h] == d) // return false; // return true; // } bool compa(string a, string b) { if (a.length() <= b.length()) return true; else return false; } int main() { fio; ll t, a, n, q, k, i, m, c, u, f, j, p, r, x, y, s, b, d; // Sieve // p= 1000000; // bool a[p]; // for (i = 2; i <= p; i += 1) // a[i] = true; // a[0] = false; // a[1] = false; // for (i = 2; i * i <= p; i += 1) // { // if (a[i] == true) // for (j = i * i; j <= p; j += i) // a[j] = false; // } cin >> n >> t; if (t == 0) cout << n; else { vector<ll> v; unordered_map<ll, ll> MA; for (i = 0; i < t; i++) { cin >> p; MA[p]++; } for (i = 0; i < 102; i++) { if (MA.find(i) == MA.end()) v.pb(i); } a = 0; b = v.size() - 1; while (a <= b) { m = a + (b - a) / 2; if (v[m] == n) break; else if (v[m] < n) a = m + 1; else b = m - 1; } if (v[m] == n) cout << n; else if (b < 0) cout << v[a]; else if (a >= 100) cout << v[b]; else if (abs(v[a] - n) == abs(v[b] - n)) cout << min(v[a], v[b]); else if (abs(v[a] - n) > abs(v[b] - n)) cout << v[b]; else cout << v[a]; } return 0; }
replace
190
193
190
193
0
p02641
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <set> #include <utility> #include <vector> using namespace std; void forbidden_list(vector<int> v, int x); int main() { int x, n; vector<int> v; cin >> x >> n; for (int i = 0; i < n; i++) { int l; cin >> l; v.push_back(l); } forbidden_list(v, x); return 0; } void forbidden_list(vector<int> v, int x) { auto it = find(v.begin(), v.end(), x); if (it == v.end()) cout << x << endl; else { int min = 100; vector<pair<int, int>> p; for (int i = 1; i < 100; i++) { auto it = find(v.begin(), v.end(), i); if (it == v.end()) { int ab = abs(x - i); if (ab < min) { min = ab; p.push_back(make_pair(min, i)); } } else v.erase(it); } sort(p.begin(), p.end()); auto it = p.begin(); cout << it->second << endl; } }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <set> #include <utility> #include <vector> using namespace std; void forbidden_list(vector<int> v, int x); int main() { int x, n; vector<int> v; cin >> x >> n; for (int i = 0; i < n; i++) { int l; cin >> l; v.push_back(l); } forbidden_list(v, x); return 0; } void forbidden_list(vector<int> v, int x) { auto it = find(v.begin(), v.end(), x); if (it == v.end()) cout << x << endl; else { int min = 100; vector<pair<int, int>> p; for (int i = 0; i <= 101; i++) { auto it = find(v.begin(), v.end(), i); if (it == v.end()) { int ab = abs(x - i); if (ab < min) { min = ab; p.push_back(make_pair(min, i)); } } else v.erase(it); } sort(p.begin(), p.end()); auto it = p.begin(); cout << it->second << endl; } }
replace
31
32
31
32
0
p02641
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int X, N; cin >> X >> N; if (N == 0) { cout << X << endl; return 0; } int tmp = 0; vector<int> P(N); for (int i = 0; i < N; i++) { cin >> tmp; P.at(i) = tmp; } sort(P.begin(), P.end()); vector<int> P_non; bool flag = true; for (int i = 1; i <= 100; i++) { for (int j = 0; j < N; j++) { if (i == P.at(j)) flag = false; } if (flag) P_non.push_back(i); flag = true; } int diff = 1000; int num = 1000; for (unsigned int i = 0; i < P_non.size(); i++) { if (abs(P_non.at(i) - X) < diff) { diff = abs(P_non.at(i) - X); num = i; } } cout << P_non.at(num) << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int X, N; cin >> X >> N; if (N == 0) { cout << X << endl; return 0; } int tmp = 0; vector<int> P(N); for (int i = 0; i < N; i++) { cin >> tmp; P.at(i) = tmp; } sort(P.begin(), P.end()); vector<int> P_non; bool flag = true; for (int i = 1; i <= 100; i++) { for (int j = 0; j < N; j++) { if (i == P.at(j)) flag = false; } if (flag) P_non.push_back(i); flag = true; } P_non.push_back(0); P_non.push_back(101); sort(P_non.begin(), P_non.end()); int diff = 1000; int num = 1000; for (unsigned int i = 0; i < P_non.size(); i++) { if (abs(P_non.at(i) - X) < diff) { diff = abs(P_non.at(i) - X); num = i; } } cout << P_non.at(num) << endl; return 0; }
insert
30
30
30
33
0
p02641
C++
Time Limit Exceeded
#include <climits> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define MOD 1000000007LL int main() { int x, n; int p; bool q[101]; int i; cin >> x >> n; if (n == 0) { printf("%d\n", x); return 0; } for (i = 1; i <= 100; i++) q[i] = true; for (i = 0; i < n; i++) { cin >> p; q[p] = false; } // for (i=1; i<=100; i++) printf("%d ", q[i]); // printf("\n"); for (i = x; i >= 1; i--) { if (q[i]) { break; } // printf("x*2-i = %d q[]=%d\n", x*2-i, q[x*2-i]); int i2 = x * 2 - i; if (i2 <= 100) { if (q[i2]) { i = i2; break; } } else { i = i2; } } printf("%d\n", i); return 0; }
#include <climits> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define MOD 1000000007LL int main() { int x, n; int p; bool q[101]; int i; cin >> x >> n; if (n == 0) { printf("%d\n", x); return 0; } for (i = 1; i <= 100; i++) q[i] = true; for (i = 0; i < n; i++) { cin >> p; q[p] = false; } // for (i=1; i<=100; i++) printf("%d ", q[i]); // printf("\n"); for (i = x; i >= 1; i--) { if (q[i]) { break; } // printf("x*2-i = %d q[]=%d\n", x*2-i, q[x*2-i]); int i2 = x * 2 - i; if (i2 <= 100) { if (q[i2]) { i = i2; break; } } else { i = i2; break; } } printf("%d\n", i); return 0; }
insert
45
45
45
46
TLE
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; int main() { int x, n; cin >> x >> n; vector<bool> h(102); rep(i, 102) { int p; cin >> p; h[p] = true; } pair<int, int> ans(100000, -1); for (int i = 0; i <= 101; i++) { if (h[i]) continue; int dif = abs(x - i); ans = min(ans, pair<int, int>(dif, i)); } cout << ans.second << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; int main() { int x, n; cin >> x >> n; vector<bool> h(102); rep(i, n) { int p; cin >> p; h[p] = true; } pair<int, int> ans(100000, -1); for (int i = 0; i <= 101; i++) { if (h[i]) continue; int dif = abs(x - i); ans = min(ans, pair<int, int>(dif, i)); } cout << ans.second << endl; }
replace
11
12
11
12
0
p02641
C++
Runtime Error
#include <cmath> #include <iomanip> #include <iostream> #include <queue> #include <random> #include <stack> #include <string> #include <algorithm> #include <fstream> #include <vector> #define ll long long int using namespace std; int main(void) { int x, n, tmp; int res, res_u; vector<int> p; cin >> x >> n; res = x; res_u = x; for (int i = 0; i < n; i++) { cin >> tmp; p.push_back(tmp); } sort(p.begin(), p.end()); for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) { if (p[i] == res) { res--; } if (p[n - i] == res_u) { res_u++; } } } if (p[0] == res_u) { res_u++; } if (abs(res - x) <= abs(res_u - x)) { cout << res; } else { cout << res_u; } }
#include <cmath> #include <iomanip> #include <iostream> #include <queue> #include <random> #include <stack> #include <string> #include <algorithm> #include <fstream> #include <vector> #define ll long long int using namespace std; int main(void) { int x, n, tmp; int res, res_u; vector<int> p; cin >> x >> n; res = x; res_u = x; for (int i = 0; i < n; i++) { cin >> tmp; p.push_back(tmp); } sort(p.begin(), p.end()); for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) { if (p[i] == res) { res--; } if (p[n - i] == res_u) { res_u++; } } } if (n) { if (p[0] == res_u) { res_u++; } } if (abs(res - x) <= abs(res_u - x)) { cout << res; } else { cout << res_u; } }
replace
44
46
44
48
0
p02641
Python
Runtime Error
X, N = map(int, input().split()) P = set(list(map(int, input().split()))) targets = set(range(1, 101)) - P print(min([(target, abs(X - target)) for target in targets], key=lambda x: x[1])[0])
X, N = map(int, input().split()) P = set(list(map(int, input().split()))) targets = set(range(-101, 102)) - P if targets: print(min([(target, abs(X - target)) for target in targets], key=lambda x: x[1])[0]) else: print(X)
replace
3
5
3
8
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() int main() { int X, Y, min, ans, j; cin >> X >> Y; vector<int> box(100, 10000); rep(i, Y) { cin >> box.at(i); } sort(box.begin(), box.begin() + Y); min = 10000; j = 0; for (int i = -1 * X; i <= 2 * X; i++) { if (box.at(j) == i) { j++; continue; } if (min > abs(X - i)) { min = abs(X - i); ans = i; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() int main() { int X, Y, min, ans, j; cin >> X >> Y; vector<int> box(1000, 10000); rep(i, Y) { cin >> box.at(i); } sort(box.begin(), box.begin() + Y); min = 10000; j = 0; for (int i = -1 * X; i <= 2 * X; i++) { if (box.at(j) == i) { j++; continue; } if (min > abs(X - i)) { min = abs(X - i); ans = i; } } cout << ans << endl; }
replace
9
10
9
10
0
p02641
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; // Loop #define REP(i, a, b) for (ll(i) = (a); (i) < (b); (i)++) #define RREP(i, a, b) for (ll(i) = (a); (i) >= (b); (i)--) #define rep(i, n) REP(i, 0, n) #define rrep(i, n) RREP(i, n, 0) #define ALL(v) v.begin(), v.end() const int INF = 10000; int main(void) { int x, n; int diff = INF; int ans = 100; cin >> x >> n; int itemp; bool q[101]; rep(i, 101) { q[i] = false; } rep(i, n) { cin >> itemp; q[itemp] = true; } REP(i, 0, 110) { if (q[i]) { continue; } int dtemp = abs(x - i); if (diff == dtemp) { cout << ans << endl; return 0; } if (diff > dtemp) { diff = dtemp; ans = i; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; // Loop #define REP(i, a, b) for (ll(i) = (a); (i) < (b); (i)++) #define RREP(i, a, b) for (ll(i) = (a); (i) >= (b); (i)--) #define rep(i, n) REP(i, 0, n) #define rrep(i, n) RREP(i, n, 0) #define ALL(v) v.begin(), v.end() const int INF = 10000; int main(void) { int x, n; int diff = INF; int ans = 100; cin >> x >> n; int itemp; bool q[110]; rep(i, 110) { q[i] = false; } rep(i, n) { cin >> itemp; q[itemp] = true; } REP(i, 0, 110) { if (q[i]) { continue; } int dtemp = abs(x - i); if (diff == dtemp) { cout << ans << endl; return 0; } if (diff > dtemp) { diff = dtemp; ans = i; } } cout << ans << endl; }
replace
22
24
22
24
0
p02641
Python
Runtime Error
X, N = map(int, input().split()) A = list(map(int, input().split())) tmp = 1000 result = [] result2 = [] for i in range(1, 101): if i in A: continue hoge = abs(X - i) if hoge <= tmp: tmp = hoge result2.append(tmp) result.append(i) result3 = [] for i, v in enumerate(result2): if v == min(result2): result3.append(result[i]) print(min(result3))
X, N = map(int, input().split()) A = list(map(int, input().split())) tmp = 1000 result = [] result2 = [] for i in range(0, 102): if i in A: continue hoge = abs(X - i) if hoge <= tmp: tmp = hoge result2.append(tmp) result.append(i) result3 = [] for i, v in enumerate(result2): if v == min(result2): result3.append(result[i]) print(min(result3))
replace
6
7
6
7
0
p02641
Python
Runtime Error
X, N = map(int, input().split()) if N == 0: print(X) else: p = list(map(int, input().split())) q = [i for i in range(-1, 102)] for r in p: idx = q.index(r) del q[idx] if X in q: print(X) else: q.sort() mindif = 100 for num in q: dif = abs(X - num) if mindif <= dif: break else: mindif = dif ans = num print(ans)
X, N = map(int, input().split()) if N == 0: print(X) else: p = list(map(int, input().split())) q = [i for i in range(-1, 102)] for r in p: idx = q.index(r) del q[idx] if X in q: print(X) else: q.sort() mindif = 1000 for num in q: dif = abs(X - num) if mindif <= dif: break else: mindif = dif ans = num print(ans)
replace
18
19
18
19
0
p02641
Python
Runtime Error
x, n = map(int, input().split()) p = [int(_) for _ in input().split()] not_in_p = [i for i in range(0, 102) if i not in p] nip_temp = list(map(lambda s: abs(x - s), not_in_p)) address = nip_temp.index(min(nip_temp)) print(p[address])
x, n = map(int, input().split()) p = [int(_) for _ in input().split()] not_in_p = [i for i in range(0, 102) if i not in p] nip_temp = list(map(lambda s: abs(x - s), not_in_p)) address = nip_temp.index(min(nip_temp)) print(not_in_p[address])
replace
7
8
7
8
0
p02641
Python
Runtime Error
import numpy as np X, N = map(int, input().split()) P = np.array(list(map(int, input().split()))) P = P - X for i in range(0, X): if i not in P or -i not in P: if -i not in P: ans = X - i else: ans = X + i break print(ans)
import numpy as np X, N = map(int, input().split()) P = np.array(list(map(int, input().split()))) P = P - X for i in range(0, X + 1): if i not in P or -i not in P: if -i not in P: ans = X - i else: ans = X + i break print(ans)
replace
7
8
7
8
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <iostream> using namespace std; #define ll long long const ll N = 2e5 + 507, N1 = 1e6 + 107; ; ll n, i, maxx, nr, j, a[N], f[N]; bitset<N1> g; int main() { cin >> n; for (i = 1; i <= n; ++i) cin >> a[i], f[a[i]]++; sort(a + 1, a + n + 1); maxx = a[n]; for (i = 1; i <= n; ++i) { for (j = 2; j <= maxx / a[i]; ++j) g[a[i] * j] = 1; } for (i = 1; i <= n; ++i) if (f[a[i]] == 1 && !g[a[i]]) nr++; cout << nr << "\n"; }
#include <algorithm> #include <bitset> #include <climits> #include <iostream> using namespace std; #define ll long long const ll N = 2e5 + 507, N1 = 1e6 + 107; ll n, i, maxx, nr, j, a[N], f[N1]; bitset<N1> g; int main() { cin >> n; for (i = 1; i <= n; ++i) cin >> a[i], f[a[i]]++; sort(a + 1, a + n + 1); maxx = a[n]; for (i = 1; i <= n; ++i) { for (j = 2; j <= maxx / a[i]; ++j) g[a[i] * j] = 1; } for (i = 1; i <= n; ++i) if (f[a[i]] == 1 && !g[a[i]]) nr++; cout << nr << "\n"; }
replace
7
9
7
8
0
p02642
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <string> using namespace std; #include <iomanip> #include <math.h> #include <queue> #include <vector> using Graph = vector<vector<int>>; const double PI = 3.14159265358979323846; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // 約数をベクトル形式で返す vector<int> vect_yakusuu(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } int main() { int N; int ans = 0; int A[100010]; int num[100010] = {}; vector<int> yakusuu; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { num[A[i]]++; } for (int i = 0; i < N; i++) { yakusuu = vect_yakusuu(A[i]); int is_undiv = 1; for (int j = 0; j < yakusuu.size() - 1; j++) { if (num[yakusuu[j]] != 0) { is_undiv = 0; } } int j = yakusuu.size() - 1; if (num[yakusuu[j]] > 1) { is_undiv = 0; } if (is_undiv == 1) { ans++; } } cout << ans << endl; cin >> ans; return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <string> using namespace std; #include <iomanip> #include <math.h> #include <queue> #include <vector> using Graph = vector<vector<int>>; const double PI = 3.14159265358979323846; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // 約数をベクトル形式で返す vector<int> vect_yakusuu(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } int main() { int N; int ans = 0; int A[1000010]; int num[1000010] = {}; vector<int> yakusuu; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { num[A[i]]++; } for (int i = 0; i < N; i++) { yakusuu = vect_yakusuu(A[i]); int is_undiv = 1; for (int j = 0; j < yakusuu.size() - 1; j++) { if (num[yakusuu[j]] != 0) { is_undiv = 0; } } int j = yakusuu.size() - 1; if (num[yakusuu[j]] > 1) { is_undiv = 0; } if (is_undiv == 1) { ans++; } } cout << ans << endl; cin >> ans; return 0; }
replace
43
45
43
45
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef int ll; vector<ll> input; vector<ll> divi[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll i, j, k, l, m, n, t; cin >> n; for (i = 0; i < n; i++) { cin >> k; input.push_back(k); } for (i = 1; i <= 1000005; i++) { for (j = i; j <= 1000005; j += i) { divi[j].push_back(i); } } // for(i=1;i<=10;i++) // for(j=0;j<divi[i].size();j++) // cout << divi[i][j] << " "; // cout << '\n'; sort(input.begin(), input.end()); ll flag = 0; ll ans = 0; for (i = 0; i < n; i++) { flag = 0; // cout << input[i] << "\n"; for (j = 0; j < divi[input[i]].size(); j++) { m = lower_bound(input.begin(), input.end(), divi[input[i]][j]) - input.begin(); l = upper_bound(input.begin(), input.end(), divi[input[i]][j]) - input.begin(); // cout << l << " " << m << '\n'; if (input[i] != divi[input[i]][j]) { if (l != m) { flag = 1; break; } } if (input[i] == divi[input[i]][j]) { if ((l - m) > 1) { flag = 1; break; } } // if(binary_search(input.begin(),input.end(),divi[input[i]][j]) == true) // { // flag = 1 // } } // cout << "flag: " << flag << '\n'; if (flag == 0) ans++; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef int ll; vector<ll> input; vector<ll> divi[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll i, j, k, l, m, n, t; cin >> n; for (i = 0; i < n; i++) { cin >> k; input.push_back(k); } for (i = 1; i < 1000001; i++) { for (j = i; j < 1000001; j += i) { divi[j].push_back(i); } } // for(i=1;i<=10;i++) // for(j=0;j<divi[i].size();j++) // cout << divi[i][j] << " "; // cout << '\n'; sort(input.begin(), input.end()); ll flag = 0; ll ans = 0; for (i = 0; i < n; i++) { flag = 0; // cout << input[i] << "\n"; for (j = 0; j < divi[input[i]].size(); j++) { m = lower_bound(input.begin(), input.end(), divi[input[i]][j]) - input.begin(); l = upper_bound(input.begin(), input.end(), divi[input[i]][j]) - input.begin(); // cout << l << " " << m << '\n'; if (input[i] != divi[input[i]][j]) { if (l != m) { flag = 1; break; } } if (input[i] == divi[input[i]][j]) { if ((l - m) > 1) { flag = 1; break; } } // if(binary_search(input.begin(),input.end(),divi[input[i]][j]) == true) // { // flag = 1 // } } // cout << "flag: " << flag << '\n'; if (flag == 0) ans++; } cout << ans << '\n'; }
replace
20
22
20
22
TLE
p02642
C++
Time Limit Exceeded
// clang-format off #include <bits/stdc++.h> using namespace std; #define int long long #define stoi stoll using pii = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; #define all(c) begin(c), end(c) #define rall(c) rbegin(c), rend(c) #define fore(x, c) for(auto &&x : c) #define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i) #define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i) #define sz(c) ((int)c.size()) #define contains(c, x) (c.find(x) != end(c)) #define inseg(l, x, r) ((l) <= (x) && (x) < (r)) #define dump(...) #define pb push_back #define eb emplace_back #define _ 0 const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL; const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0}; template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;} template<class T> istream& operator>>(istream &is, vector<T> &v) { for (auto i = begin(v); i != end(v); i++) is>>*i;return is;} template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) { is>>p.first>>p.second;return is;} template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;} template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;} template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));} template<class T> using heap = priority_queue<T, deque<T>, greater<T>>; struct before_main_function { before_main_function() { cin.tie(nullptr); ios::sync_with_stdio(0); cout << setprecision(15) << fixed; } } before_main_function; // clang-format on //------------------8<------------------------------------8<-------------------- signed main() { int N; cin >> N; vi A(N); cin >> A; map<int, int> cnt; rep(i, 0, N) cnt[A[i]]++; int ans = 0; rep(i, 0, N) { cnt[A[i]]--; int tmp = 0; rep(x, 1, A[i] + 1) { if (x * x > A[i]) break; if (A[i] % x == 0) { int d1 = x; int d2 = A[i] / x; tmp += cnt[d1]; if (d1 != d2) { tmp += cnt[d2]; } } } if (!tmp) { ans++; } cnt[A[i]]++; } cout << ans << endl; return (0 ^ _ ^ 0); }
// clang-format off #include <bits/stdc++.h> using namespace std; #define int long long #define stoi stoll using pii = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; #define all(c) begin(c), end(c) #define rall(c) rbegin(c), rend(c) #define fore(x, c) for(auto &&x : c) #define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i) #define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i) #define sz(c) ((int)c.size()) #define contains(c, x) (c.find(x) != end(c)) #define inseg(l, x, r) ((l) <= (x) && (x) < (r)) #define dump(...) #define pb push_back #define eb emplace_back #define _ 0 const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL; const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0}; template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;} template<class T> istream& operator>>(istream &is, vector<T> &v) { for (auto i = begin(v); i != end(v); i++) is>>*i;return is;} template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) { is>>p.first>>p.second;return is;} template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;} template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;} template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));} template<class T> using heap = priority_queue<T, deque<T>, greater<T>>; struct before_main_function { before_main_function() { cin.tie(nullptr); ios::sync_with_stdio(0); cout << setprecision(15) << fixed; } } before_main_function; // clang-format on //------------------8<------------------------------------8<-------------------- signed main() { int N; cin >> N; vi A(N); cin >> A; unordered_map<int, int> cnt; rep(i, 0, N) cnt[A[i]]++; int ans = 0; rep(i, 0, N) { cnt[A[i]]--; int tmp = 0; rep(x, 1, A[i] + 1) { if (x * x > A[i]) break; if (A[i] % x == 0) { int d1 = x; int d2 = A[i] / x; tmp += cnt[d1]; if (d1 != d2) { tmp += cnt[d2]; } } } if (!tmp) { ans++; } cnt[A[i]]++; } cout << ans << endl; return (0 ^ _ ^ 0); }
replace
46
47
46
47
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; bool compare(int a, int b) { return a > b; } int main() { int x, n, i, ans, j, temp, maxi, k; int flag[200100] = {0}; int mark[100100] = {0}; int flag2[100100] = {0}; cin >> n; for (i = 0; i < n; i++) { cin >> flag[i]; flag2[flag[i]]++; } sort(flag, flag + n, compare); maxi = flag[0]; ans = 0; for (i = 0; i < n; i++) { k = 2; while (flag[i] * k <= maxi) { mark[flag[i] * k] = 1; k++; } } for (i = 0; i < n; i++) { if (flag2[flag[i]] == 1) { if (mark[flag[i]] != 1) ans++; } } cout << ans << endl; }
#include <algorithm> #include <iostream> using namespace std; bool compare(int a, int b) { return a > b; } int main() { int x, n, i, ans, j, temp, maxi, k; int flag[200100] = {0}; int mark[1001000] = {0}; int flag2[1001000] = {0}; cin >> n; for (i = 0; i < n; i++) { cin >> flag[i]; flag2[flag[i]]++; } sort(flag, flag + n, compare); maxi = flag[0]; ans = 0; for (i = 0; i < n; i++) { k = 2; while (flag[i] * k <= maxi) { mark[flag[i] * k] = 1; k++; } } for (i = 0; i < n; i++) { if (flag2[flag[i]] == 1) { if (mark[flag[i]] != 1) ans++; } } cout << ans << endl; }
replace
7
9
7
9
0
p02642
C++
Runtime Error
#define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const int M = 1000000; int main() { int n; cin >> n; vector<int> A(n); rep(i, n) cin >> A[i]; vector<int> C(M); for (auto t : A) { if (C[t] != 0) { C[t] = 2; continue; } for (int j = t; j < M; j += t) { C[j]++; } } int cnt = 0; for (auto t : A) { if (C[t] == 1) cnt++; } cout << cnt << endl; return 0; }
#define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const int M = 1000010; int main() { int n; cin >> n; vector<int> A(n); rep(i, n) cin >> A[i]; vector<int> C(M); for (auto t : A) { if (C[t] != 0) { C[t] = 2; continue; } for (int j = t; j < M; j += t) { C[j]++; } } int cnt = 0; for (auto t : A) { if (C[t] == 1) cnt++; } cout << cnt << endl; return 0; }
replace
8
9
8
9
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, a[200005], ans, ada[200005]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); cin >> n; memset(ada, 0, sizeof ada); for (int i = 1; i <= n; i++) { cin >> a[i]; ada[a[i]]++; } sort(a + 1, a + n + 1); ans = 0; for (int i = 1; i <= n; i++) { if (ada[a[i]] == -1) continue; for (int j = 2 * a[i]; j <= a[n]; j += a[i]) { ada[j] = -1; } if (ada[a[i]] == 1) ans++; ada[a[i]] = -1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, a[2000005], ans, ada[2000005]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); cin >> n; memset(ada, 0, sizeof ada); for (int i = 1; i <= n; i++) { cin >> a[i]; ada[a[i]]++; } sort(a + 1, a + n + 1); ans = 0; for (int i = 1; i <= n; i++) { if (ada[a[i]] == -1) continue; for (int j = 2 * a[i]; j <= a[n]; j += a[i]) { ada[j] = -1; } if (ada[a[i]] == 1) ans++; ada[a[i]] = -1; } cout << ans << endl; }
replace
3
4
3
4
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<ll> vi; typedef vector<bool> vb; #define mp make_pair #define pb push_back #define eb emplace_back #define sq(x) ((x) * (x)) #define fo(i, n) for (int i = 0; i < n; i++) #define fp(i, k, n) for (int i = k; i < n; i++) #define Fo(i, n) for (int i = 1; i <= n; i++) #define all(x) x.begin(), x.end() #define deb(x) cout << #x << "=" << x << "\n" #define deb2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << "\n" #define fi first #define se second const double pi = 3.14159265358979323846; #define uni(c) (c).resize(unique(all(c)) - (c).begin()) #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL) // pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)}; // for // matrix movement: void cp() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } void solve() { ll n; cin >> n; ll a[n]; unordered_map<ll, ll> have; fo(i, n) { cin >> a[i]; have[a[i]]++; } sort(a, a + n); ll ma = a[n - 1]; vb vis(100006, 0); for (int i = 0; i < n; i++) { if (!vis[a[i]]) { for (int j = 2 * a[i]; j <= ma; j += a[i]) vis[j] = 1; } } ll ans = 0; for (int i = 0; i < n; i++) { if (!vis[a[i]] and have[a[i]] == 1) ans++; } cout << ans; } int main() { fast; // cp(); ll t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<ll> vi; typedef vector<bool> vb; #define mp make_pair #define pb push_back #define eb emplace_back #define sq(x) ((x) * (x)) #define fo(i, n) for (int i = 0; i < n; i++) #define fp(i, k, n) for (int i = k; i < n; i++) #define Fo(i, n) for (int i = 1; i <= n; i++) #define all(x) x.begin(), x.end() #define deb(x) cout << #x << "=" << x << "\n" #define deb2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << "\n" #define fi first #define se second const double pi = 3.14159265358979323846; #define uni(c) (c).resize(unique(all(c)) - (c).begin()) #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL) // pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)}; // for // matrix movement: void cp() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } void solve() { ll n; cin >> n; ll a[n]; unordered_map<ll, ll> have; fo(i, n) { cin >> a[i]; have[a[i]]++; } sort(a, a + n); ll ma = a[n - 1]; vb vis(1000016, 0); for (int i = 0; i < n; i++) { if (!vis[a[i]]) { for (int j = 2 * a[i]; j <= ma; j += a[i]) vis[j] = 1; } } ll ans = 0; for (int i = 0; i < n; i++) { if (!vis[a[i]] and have[a[i]] == 1) ans++; } cout << ans; } int main() { fast; // cp(); ll t = 1; // cin >> t; while (t--) solve(); return 0; }
replace
44
45
44
45
0
p02642
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<ll> b(100001, 0); rep(i, n) b[a[i]]++; ll ans = n; rep(i, n) { for (ll j = 1; j * j <= a[i]; j++) { if (a[i] % j == 0) { if (a[i] == 1) { if (b[j] > 1) { ans--; break; } } else if (j == 1) { if (b[j] > 0 || b[a[i] / j] > 1) { ans--; break; } } else if (b[j] > 0 || b[a[i] / j] > 0) { ans--; break; } } } } cout << ans << endl; }
#include <bits/stdc++.h> using ll = long long; #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<ll> b(1000001, 0); rep(i, n) b[a[i]]++; ll ans = n; rep(i, n) { for (ll j = 1; j * j <= a[i]; j++) { if (a[i] % j == 0) { if (a[i] == 1) { if (b[j] > 1) { ans--; break; } } else if (j == 1) { if (b[j] > 0 || b[a[i] / j] > 1) { ans--; break; } } else if (b[j] > 0 || b[a[i] / j] > 0) { ans--; break; } } } } cout << ans << endl; }
replace
10
11
10
11
0
p02642
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, N) for (int(i) = 0; (i) < (N); (i)++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) const double PI = 3.1415926535897932384626433832795; const int mod = 1000000007; const int INF = 1001001001; const int MAXV = 100010; int main() { int x, n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> nums(MAXV); for (int x : a) { if (nums[x] >= 1) { nums[x] = 2; continue; } for (int j = x; j < MAXV; j += x) { nums[j]++; } } int ans = 0; rep(i, n) { if (nums[a[i]] == 1) ans++; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, N) for (int(i) = 0; (i) < (N); (i)++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) const double PI = 3.1415926535897932384626433832795; const int mod = 1000000007; const int INF = 1001001001; const int MAXV = 1000010; int main() { int x, n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> nums(MAXV); for (int x : a) { if (nums[x] >= 1) { nums[x] = 2; continue; } for (int j = x; j < MAXV; j += x) { nums[j]++; } } int ans = 0; rep(i, n) { if (nums[a[i]] == 1) ans++; } cout << ans << endl; }
replace
27
28
27
28
0
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define reps(i, n) for (int i = 1; i <= (int)n; i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair #define fs first #define sc second #define lb lower_bound #define ub upper_bound #define LB(a, x) lb(all(a), x) - a.begin() #define UB(a, x) ub(all(a), x) - a.begin() #define MOD 1000000007 #define itn int #define enld endl using namespace std; typedef long long ll; const double pi = 3.141592653589793; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } int main() { cin.tie(0); ios::sync_with_stdio(false); bool flag[1001001]; // A_iの中に自分を割り切る数が存在すればfalse Fill(flag, true); int N; cin >> N; int A[200200]; int cnt[1001001]; Fill(cnt, 0); rep(i, N) { cin >> A[i]; cnt[A[i]]++; } rep(i, N) { if (cnt[A[i]] > 1) flag[A[i]] = false; // 同じ数が2回以上登場すると割り切れるのでfalse for (int j = A[i] * 2; j <= 1000000; j += A[i]) flag[j] = false; // A[i]のA[i]自身を除く倍数は全てfalse } int ans = 0; rep(i, N) { if (flag[A[i]] == true) ans++; } cout << ans << enld; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define reps(i, n) for (int i = 1; i <= (int)n; i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair #define fs first #define sc second #define lb lower_bound #define ub upper_bound #define LB(a, x) lb(all(a), x) - a.begin() #define UB(a, x) ub(all(a), x) - a.begin() #define MOD 1000000007 #define itn int #define enld endl using namespace std; typedef long long ll; const double pi = 3.141592653589793; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } int main() { cin.tie(0); ios::sync_with_stdio(false); bool flag[1001001]; // A_iの中に自分を割り切る数が存在すればfalse Fill(flag, true); int N; cin >> N; int A[200200]; int cnt[1001001]; Fill(cnt, 0); rep(i, N) { cin >> A[i]; cnt[A[i]]++; } rep(i, N) { if (flag[A[i]] == false) continue; if (cnt[A[i]] > 1) flag[A[i]] = false; // 同じ数が2回以上登場すると割り切れるのでfalse for (int j = A[i] * 2; j <= 1000000; j += A[i]) flag[j] = false; // A[i]のA[i]自身を除く倍数は全てfalse } int ans = 0; rep(i, N) { if (flag[A[i]] == true) ans++; } cout << ans << enld; return 0; }
insert
66
66
66
69
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define MP make_pair #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define DB(x) cerr << #x << " = " << x << endl #define DB2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; #define DEBUG \ int x12345; \ cin >> x12345; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; const long long MOD = 1e9 + 7; /////////////////////////////////////////////// // for template template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /// 🍈( '-' 🍈 |AC| int main() { vector<bool> B(2000002); int N; cin >> N; vector<int> A(N); REP(i, N) { cin >> A[i]; } sort(ALL(A)); REP(i, N) { if ((i != 0) and (A[i] == A[i - 1])) { B[A[i]] = true; } int D = A[i]; int k = 2; while (k * D <= 1e6) { int n = k * D; B[n] = true; k++; } } int ans = N; REP(i, N) { if (B[A[i]]) ans -= 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define MP make_pair #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define DB(x) cerr << #x << " = " << x << endl #define DB2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; #define DEBUG \ int x12345; \ cin >> x12345; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; const long long MOD = 1e9 + 7; /////////////////////////////////////////////// // for template template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /// 🍈( '-' 🍈 |AC| int main() { vector<bool> B(2000002); int N; cin >> N; vector<int> A(N); REP(i, N) { cin >> A[i]; } sort(ALL(A)); REP(i, N) { if ((i != 0) and (A[i] == A[i - 1])) { B[A[i]] = true; continue; } int D = A[i]; int k = 2; while (k * D <= 1e6) { int n = k * D; B[n] = true; k++; } } int ans = N; REP(i, N) { if (B[A[i]]) ans -= 1; } cout << ans << endl; }
insert
57
57
57
58
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } struct Unionfind { vector<int> par; Unionfind(int n) : par(n) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; const int num = 1000000; vector<int> cnt(num + 1, 0); vector<int> a(n); rep(i, n) { cin >> a[i]; if (cnt[a[i]] != 0) { cnt[a[i]] = 10; continue; } for (int j = a[i]; j <= num; j += a[i]) ++cnt[a[j]]; } int ans = 0; rep(i, n) { if (cnt[a[i]] == 1) ++ans; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } struct Unionfind { vector<int> par; Unionfind(int n) : par(n) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; const int num = 1000000; vector<int> cnt(num + 1, 0); vector<int> a(n); rep(i, n) { cin >> a[i]; if (cnt[a[i]] != 0) { cnt[a[i]] = 10; continue; } for (int j = a[i]; j <= num; j += a[i]) ++cnt[j]; } int ans = 0; rep(i, n) { if (cnt[a[i]] == 1) ++ans; } cout << ans << endl; return 0; }
replace
67
68
67
68
-11
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> int h[1000005]; int a[100005], n, ans, m; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0); std::cin >> n; for (int i = 1; i <= n; ++i) { std::cin >> a[i]; ++h[a[i]]; m = std::max(m, a[i]); } std::sort(a + 1, a + n + 1); n = std::unique(a + 1, a + n + 1) - a - 1; for (int i = 1; i <= m; ++i) { if (h[i] > 1) h[i] = false; else if (h[i] == 1) ++ans; } for (int i = 1; i <= n; ++i) { for (int j = (a[i] << 1); j <= m; j += a[i]) { if (h[j] > 0) { h[j] = false; --ans; } } } std::cout << ans; return 0; }
#include <algorithm> #include <iostream> int h[1000005]; int a[200005], n, ans, m; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0); std::cin >> n; for (int i = 1; i <= n; ++i) { std::cin >> a[i]; ++h[a[i]]; m = std::max(m, a[i]); } std::sort(a + 1, a + n + 1); n = std::unique(a + 1, a + n + 1) - a - 1; for (int i = 1; i <= m; ++i) { if (h[i] > 1) h[i] = false; else if (h[i] == 1) ++ans; } for (int i = 1; i <= n; ++i) { for (int j = (a[i] << 1); j <= m; j += a[i]) { if (h[j] > 0) { h[j] = false; --ans; } } } std::cout << ans; return 0; }
replace
3
4
3
4
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, start, count) for (int i = (start); i < (int)(count); ++i) #define rep(i, count) REP(i, 0, count) #define ALLOF(c) (c).begin(), (c).end() using ll = long long; using ull = unsigned long long; using veci = vector<int>; using vecll = vector<ll>; using vecull = vector<ull>; int main(void) { ll N; cin >> N; vecll A; rep(i, N) { ll a; cin >> a; A.emplace_back(a); } sort(ALLOF(A)); ll Amax = A[N - 1]; vector<bool> dp(A[N - 1], true); vector<bool> dirty(A[N - 1], false); for (int i = 0; i < N; ++i) { ll n = A[i]; if (dirty[n]) { dp[n] = false; continue; } if (dp[n]) { ll j = n + n; while (j <= Amax) { dp[j] = false; j += n; } } dirty[n] = true; } ll ans = 0; rep(i, N) { if (dp[A[i]]) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, start, count) for (int i = (start); i < (int)(count); ++i) #define rep(i, count) REP(i, 0, count) #define ALLOF(c) (c).begin(), (c).end() using ll = long long; using ull = unsigned long long; using veci = vector<int>; using vecll = vector<ll>; using vecull = vector<ull>; int main(void) { ll N; cin >> N; vecll A; rep(i, N) { ll a; cin >> a; A.emplace_back(a); } sort(ALLOF(A)); ll Amax = A[N - 1]; vector<bool> dp(Amax + 1, true); vector<bool> dirty(Amax + 1, false); for (int i = 0; i < N; ++i) { ll n = A[i]; if (dirty[n]) { dp[n] = false; continue; } if (dp[n]) { ll j = n + n; while (j <= Amax) { dp[j] = false; j += n; } } dirty[n] = true; } ll ans = 0; rep(i, N) { if (dp[A[i]]) ans++; } cout << ans << endl; return 0; }
replace
26
28
26
28
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, j, k) for (int i = j; i < k; i++) int main() { ll N; cin >> N; vector<ll> A(N), so(1000008, 0); rep(i, 0, N) cin >> A[i]; sort(A.begin(), A.end()); ll res = 0; rep(i, 0, N) { bool x = false; if (i && A[i - 1] == A[i]) x = true; if (i + 1 != N && A[i + 1] == A[i]) x = true; if (x) { for (int j = A[i]; j < 1000007; j += A[i]) { so[j] = 1; } continue; } if (so[A[i]] == 0) { res++; for (int j = A[i]; j < 1000007; j += A[i]) { so[j] = 1; } } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, j, k) for (int i = j; i < k; i++) int main() { ll N; cin >> N; vector<ll> A(N), so(1000008, 0); rep(i, 0, N) cin >> A[i]; sort(A.begin(), A.end()); ll res = 0; rep(i, 0, N) { bool x = false; if (i && A[i - 1] == A[i]) x = true; if (i + 1 != N && A[i + 1] == A[i]) x = true; if (x && so[A[i]] == 0) { for (int j = A[i]; j < 1000007; j += A[i]) { so[j] = 1; } continue; } if (so[A[i]] == 0) { res++; for (int j = A[i]; j < 1000007; j += A[i]) { so[j] = 1; } } } cout << res << endl; }
replace
21
22
21
22
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int M = 2 * 1e5 + 10; int main() { int n; cin >> n; vector<int> unique; vector<int> ok(M, 0); for (int i = 0; i < n; ++i) { int a; cin >> a; if (ok[a] == 0) { unique.push_back(a); ok[a] = 1; } else if (ok[a] == 1) { ok[a] = -1; } } for (int i : unique) { for (int j = i * 2; j < M; j += i) { ok[j] = 0; } } int cnt = 0; for (int i = 1; i < M; ++i) { if (ok[i] == 1) cnt++; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; const int M = 2 * 1e6 + 10; int main() { int n; cin >> n; vector<int> unique; vector<int> ok(M, 0); for (int i = 0; i < n; ++i) { int a; cin >> a; if (ok[a] == 0) { unique.push_back(a); ok[a] = 1; } else if (ok[a] == 1) { ok[a] = -1; } } for (int i : unique) { for (int j = i * 2; j < M; j += i) { ok[j] = 0; } } int cnt = 0; for (int i = 1; i < M; ++i) { if (ok[i] == 1) cnt++; } cout << cnt << endl; }
replace
2
3
2
3
0
p02642
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include "bits/stdc++.h" using namespace std; using ll = long long int; #define all(v) (v).begin(), (v).end() #define repeat(cnt, l) \ for (typename remove_const< \ typename remove_reference<decltype(l)>::type>::type cnt = {}; \ (cnt) < (l); ++(cnt)) #define rrepeat(cnt, l) for (auto cnt = (l)-1; 0 <= (cnt); --(cnt)) #define iterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); ++(cnt)) #define diterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); --(cnt)) const long long MD = 1000000007ll; const long double PI = 3.1415926535897932384626433832795L; template <typename T1, typename T2> inline ostream &operator<<(ostream &o, const pair<T1, T2> p) { o << '(' << p.first << ':' << p.second << ')'; return o; } template <typename T> inline T &chmax(T &to, const T &val) { return to = max(to, val); } template <typename T> inline T &chmin(T &to, const T &val) { return to = min(to, val); } void bye(string s, int code = 0) { cout << s << endl; exit(code); } mt19937_64 randdev(8901016); template <typename T, typename Random = decltype(randdev), typename enable_if<is_integral<T>::value>::type * = nullptr> inline T rand(T l, T h, Random &rand = randdev) { return uniform_int_distribution<T>(l, h)(rand); } template <typename T, typename Random = decltype(randdev), typename enable_if<is_floating_point<T>::value>::type * = nullptr> inline T rand(T l, T h, Random &rand = randdev) { return uniform_real_distribution<T>(l, h)(rand); } template <typename I> struct MyRangeFormat { I b, e; MyRangeFormat(I _b, I _e) : b(_b), e(_e) {} }; template <typename I> static ostream &operator<<(ostream &o, const MyRangeFormat<I> &f) { o << "[ "; iterate(i, f.b, f.e) o << *i << ' '; return o << ']'; } template <typename I> struct MyMatrixFormat { const I &p; long long n, m; MyMatrixFormat(const I &_p, long long _n, long long _m) : p(_p), n(_n), m(_m) {} }; template <typename I> static ostream &operator<<(ostream &o, const MyMatrixFormat<I> &f) { o << '\n'; repeat(i, (f.n)) { repeat(j, f.m) o << f.p[i][j] << ' '; o << '\n'; } return o; } struct LOG_t { ~LOG_t() { cout << endl; } }; #define LOG (LOG_t(), cout << 'L' << __LINE__ << ": ") #define FMTA(m, w) (MyRangeFormat<decltype(m + 0)>(m, m + w)) #define FMTR(b, e) (MyRangeFormat<decltype(e)>(b, e)) #define FMTV(v) FMTR(v.begin(), v.end()) #define FMTM(m, h, w) (MyMatrixFormat<decltype(m + 0)>(m, h, w)) #if defined(_WIN32) || defined(_WIN64) #define getc_x _getc_nolock #define putc_x _putc_nolock #elif defined(__GNUC__) #define getc_x getc_unlocked #define putc_x putc_unlocked #else #define getc_x getc #define putc_x putc #endif class MaiScanner { FILE *fp_; constexpr bool isvisiblechar(char c) noexcept { return (0x21 <= (c) && (c) <= 0x7E); } public: inline MaiScanner(FILE *fp) : fp_(fp) {} template <typename T> void input_integer(T &var) noexcept { var = 0; T sign = 1; int cc = getc_x(fp_); for (; cc < '0' || '9' < cc; cc = getc_x(fp_)) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getc_x(fp_)) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; } inline int c() noexcept { return getc_x(fp_); } template <typename T, typename enable_if<is_integral<T>::value, nullptr_t>::type = nullptr> inline MaiScanner &operator>>(T &var) noexcept { input_integer<T>(var); return *this; } inline MaiScanner &operator>>(string &var) { int cc = getc_x(fp_); for (; !isvisiblechar(cc); cc = getc_x(fp_)) ; for (; isvisiblechar(cc); cc = getc_x(fp_)) var.push_back(cc); return *this; } template <typename IT> inline void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; } }; class MaiPrinter { FILE *fp_; public: inline MaiPrinter(FILE *fp) : fp_(fp) {} template <typename T> void output_integer(T var) noexcept { if (var == 0) { putc_x('0', fp_); return; } if (var < 0) putc_x('-', fp_), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putc_x(stack[--stack_p], fp_); } inline MaiPrinter &operator<<(char c) noexcept { putc_x(c, fp_); return *this; } template <typename T, typename enable_if<is_integral<T>::value, nullptr_t>::type = nullptr> inline MaiPrinter &operator<<(T var) noexcept { output_integer<T>(var); return *this; } inline MaiPrinter &operator<<(char *str_p) noexcept { while (*str_p) putc_x(*(str_p++), fp_); return *this; } inline MaiPrinter &operator<<(const string &str) { const char *p = str.c_str(); const char *l = p + str.size(); while (p < l) putc_x(*p++, fp_); return *this; } template <typename IT> void join(IT begin, IT end, char sep = ' ') { for (bool b = 0; begin != end; ++begin, b = 1) b ? *this << sep << *begin : *this << *begin; } }; MaiScanner scanner(stdin); MaiPrinter printer(stdout); // int N; // int A[200010]; // int H = 1000001; bool V[1000010]; int U[1000010]; int main() { scanner >> N; repeat(i, N) { int a; scanner >> a; int w = 2; while (a * w < H) { V[a * w] = 1; w += 1; } ++U[a]; } int res = 0; repeat(a, H) { res += (U[a] == 1) && (V[a] == 0); } printer << res << '\n'; return 0; }
#pragma GCC optimize("O3") #include "bits/stdc++.h" using namespace std; using ll = long long int; #define all(v) (v).begin(), (v).end() #define repeat(cnt, l) \ for (typename remove_const< \ typename remove_reference<decltype(l)>::type>::type cnt = {}; \ (cnt) < (l); ++(cnt)) #define rrepeat(cnt, l) for (auto cnt = (l)-1; 0 <= (cnt); --(cnt)) #define iterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); ++(cnt)) #define diterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); --(cnt)) const long long MD = 1000000007ll; const long double PI = 3.1415926535897932384626433832795L; template <typename T1, typename T2> inline ostream &operator<<(ostream &o, const pair<T1, T2> p) { o << '(' << p.first << ':' << p.second << ')'; return o; } template <typename T> inline T &chmax(T &to, const T &val) { return to = max(to, val); } template <typename T> inline T &chmin(T &to, const T &val) { return to = min(to, val); } void bye(string s, int code = 0) { cout << s << endl; exit(code); } mt19937_64 randdev(8901016); template <typename T, typename Random = decltype(randdev), typename enable_if<is_integral<T>::value>::type * = nullptr> inline T rand(T l, T h, Random &rand = randdev) { return uniform_int_distribution<T>(l, h)(rand); } template <typename T, typename Random = decltype(randdev), typename enable_if<is_floating_point<T>::value>::type * = nullptr> inline T rand(T l, T h, Random &rand = randdev) { return uniform_real_distribution<T>(l, h)(rand); } template <typename I> struct MyRangeFormat { I b, e; MyRangeFormat(I _b, I _e) : b(_b), e(_e) {} }; template <typename I> static ostream &operator<<(ostream &o, const MyRangeFormat<I> &f) { o << "[ "; iterate(i, f.b, f.e) o << *i << ' '; return o << ']'; } template <typename I> struct MyMatrixFormat { const I &p; long long n, m; MyMatrixFormat(const I &_p, long long _n, long long _m) : p(_p), n(_n), m(_m) {} }; template <typename I> static ostream &operator<<(ostream &o, const MyMatrixFormat<I> &f) { o << '\n'; repeat(i, (f.n)) { repeat(j, f.m) o << f.p[i][j] << ' '; o << '\n'; } return o; } struct LOG_t { ~LOG_t() { cout << endl; } }; #define LOG (LOG_t(), cout << 'L' << __LINE__ << ": ") #define FMTA(m, w) (MyRangeFormat<decltype(m + 0)>(m, m + w)) #define FMTR(b, e) (MyRangeFormat<decltype(e)>(b, e)) #define FMTV(v) FMTR(v.begin(), v.end()) #define FMTM(m, h, w) (MyMatrixFormat<decltype(m + 0)>(m, h, w)) #if defined(_WIN32) || defined(_WIN64) #define getc_x _getc_nolock #define putc_x _putc_nolock #elif defined(__GNUC__) #define getc_x getc_unlocked #define putc_x putc_unlocked #else #define getc_x getc #define putc_x putc #endif class MaiScanner { FILE *fp_; constexpr bool isvisiblechar(char c) noexcept { return (0x21 <= (c) && (c) <= 0x7E); } public: inline MaiScanner(FILE *fp) : fp_(fp) {} template <typename T> void input_integer(T &var) noexcept { var = 0; T sign = 1; int cc = getc_x(fp_); for (; cc < '0' || '9' < cc; cc = getc_x(fp_)) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getc_x(fp_)) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; } inline int c() noexcept { return getc_x(fp_); } template <typename T, typename enable_if<is_integral<T>::value, nullptr_t>::type = nullptr> inline MaiScanner &operator>>(T &var) noexcept { input_integer<T>(var); return *this; } inline MaiScanner &operator>>(string &var) { int cc = getc_x(fp_); for (; !isvisiblechar(cc); cc = getc_x(fp_)) ; for (; isvisiblechar(cc); cc = getc_x(fp_)) var.push_back(cc); return *this; } template <typename IT> inline void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; } }; class MaiPrinter { FILE *fp_; public: inline MaiPrinter(FILE *fp) : fp_(fp) {} template <typename T> void output_integer(T var) noexcept { if (var == 0) { putc_x('0', fp_); return; } if (var < 0) putc_x('-', fp_), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putc_x(stack[--stack_p], fp_); } inline MaiPrinter &operator<<(char c) noexcept { putc_x(c, fp_); return *this; } template <typename T, typename enable_if<is_integral<T>::value, nullptr_t>::type = nullptr> inline MaiPrinter &operator<<(T var) noexcept { output_integer<T>(var); return *this; } inline MaiPrinter &operator<<(char *str_p) noexcept { while (*str_p) putc_x(*(str_p++), fp_); return *this; } inline MaiPrinter &operator<<(const string &str) { const char *p = str.c_str(); const char *l = p + str.size(); while (p < l) putc_x(*p++, fp_); return *this; } template <typename IT> void join(IT begin, IT end, char sep = ' ') { for (bool b = 0; begin != end; ++begin, b = 1) b ? *this << sep << *begin : *this << *begin; } }; MaiScanner scanner(stdin); MaiPrinter printer(stdout); // int N; // int A[200010]; // int H = 1000001; bool V[1000010]; int U[1000010]; int main() { scanner >> N; repeat(i, N) { int a; scanner >> a; if (U[a] >= 2) continue; int w = 2; while (a * w < H) { V[a * w] = 1; w += 1; } ++U[a]; } int res = 0; repeat(a, H) { res += (U[a] == 1) && (V[a] == 0); } printer << res << '\n'; return 0; }
insert
192
192
192
194
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long signed main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> m; for (auto &&i : a) { m[i]++; } sort(a.begin(), a.end()); int ans = 0; for (int i = 0; i < n; i++) { m[a[i]]--; bool flug = true; if (m[a[i]] > 0) flug = false; else for (int j = 1; j * j <= a[i]; j++) { if (a[i] % j == 0 && (m[j] > 0 || m[a[i] / j] > 0)) flug = false; } if (flug) ans++; m[a[i]]++; } cout << ans << endl; }
#include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long signed main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> m(1000000 + 10); for (auto &&i : a) { m[i]++; } sort(a.begin(), a.end()); int ans = 0; for (int i = 0; i < n; i++) { m[a[i]]--; bool flug = true; if (m[a[i]] > 0) flug = false; else for (int j = 1; j * j <= a[i]; j++) { if (a[i] % j == 0 && (m[j] > 0 || m[a[i] / j] > 0)) flug = false; } if (flug) ans++; m[a[i]]++; } cout << ans << endl; }
replace
21
22
21
22
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); sort(A.begin(), A.end()); vector<pair<int, int>> B; set<int> ans_check; B.push_back(make_pair(A.at(0), 1)); int index = 0; for (int i = 1; i < N; i++) { if (B.at(index).first == A.at(i)) B.at(index).second++; else { index++; B.push_back(make_pair(A.at(i), 1)); ans_check.insert(A.at(i)); } } int ans = 0; bool check; for (int i = 0; i < B.size(); i++) { check = true; if (B.at(i).second != 1) continue; else { for (int j = 0; j < i; j++) { if (B.at(i).first % B.at(j).first == 0) { check = false; break; } if (B.at(j).first > sqrt(B.at(i).first)) { int tmp = 2; while (true) { if (tmp > sqrt(B.at(i).first)) break; else if (B.at(i).first % tmp != 0) { tmp++; continue; } else { int tmp2 = B.at(i).first / tmp; if (ans_check.count(tmp2)) { check = false; break; } else { tmp++; } } } } } if (check) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); sort(A.begin(), A.end()); vector<pair<int, int>> B; set<int> ans_check; B.push_back(make_pair(A.at(0), 1)); int index = 0; for (int i = 1; i < N; i++) { if (B.at(index).first == A.at(i)) B.at(index).second++; else { index++; B.push_back(make_pair(A.at(i), 1)); ans_check.insert(A.at(i)); } } int ans = 0; bool check; for (int i = 0; i < B.size(); i++) { check = true; if (B.at(i).second != 1) continue; else { for (int j = 0; j < i; j++) { if (B.at(i).first % B.at(j).first == 0) { check = false; break; } if (B.at(j).first > sqrt(B.at(i).first)) { int tmp = 2; while (true) { if (tmp > sqrt(B.at(i).first)) break; else if (B.at(i).first % tmp != 0) { tmp++; continue; } else { int tmp2 = B.at(i).first / tmp; if (ans_check.count(tmp2)) { check = false; break; } else { tmp++; } } } break; } } if (check) ans++; } } cout << ans << endl; }
insert
53
53
53
54
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; const ll M = 1e6; int main() { int N; cin >> N; vector<ll> A(N); vector<ll> B(M + 1, 0); for (int i = 0; i < N; i++) { cin >> A[i]; for (ll j = A[i]; j <= M; j += A[i]) { B[j]++; } } int count = 0; for (ll a : A) { if (B[a] == 1) { count++; } } cout << count << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; const ll M = 1e6; int main() { int N; cin >> N; vector<ll> A(N); vector<ll> B(M + 1, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { if (B[A[i]] != 0) { B[A[i]] = 2; continue; } for (ll j = A[i]; j <= M; j += A[i]) { B[j]++; } } int count = 0; for (ll a : A) { if (B[a] == 1) { count++; } } cout << count << endl; return 0; }
insert
24
24
24
30
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 1000099; int a[N]; int t[M]; int main() { ; freopen("in.txt", "r", stdin); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); t[a[i]]++; } int mmax = *max_element(a, a + n); sort(a, a + n); int cnt = 0; for (int i = 0; i < n; i++) { int x = a[i]; if (t[x] == 0) continue; for (int j = 2 * x; j < mmax + 10; j += x) { t[j] = 0; } if (t[x] == 1) cnt++; } printf("%d\n", cnt); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 1000099; int a[N]; int t[M]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); t[a[i]]++; } int mmax = *max_element(a, a + n); sort(a, a + n); int cnt = 0; for (int i = 0; i < n; i++) { int x = a[i]; if (t[x] == 0) continue; for (int j = 2 * x; j < mmax + 10; j += x) { t[j] = 0; } if (t[x] == 1) cnt++; } printf("%d\n", cnt); return 0; }
delete
6
8
6
6
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #ifdef LOCAL #include "lib/debug.hpp" #else #define debug(...) 1 #endif #define ALL(a) (a).begin(), (a).end() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) using namespace std; using ll = int_fast64_t; using pr = pair<ll, ll>; using vll = vector<ll>; using vpr = vector<pr>; template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } else return false; } template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } else return false; } void answer() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; sort(ALL(a)); vector<bool> memo(1000005, true); vector<int> cnt(1000005, 0); rep(i, n) { cnt[a[i]]++; int b = 2 * a[i]; while (b <= 1000000) { memo[b] = false; b += a[i]; } } int ans = 0; rep(i, n) { if (cnt[a[i]] == 1 && memo[a[i]]) ans++; } cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); answer(); return 0; }
#include <bits/stdc++.h> #ifdef LOCAL #include "lib/debug.hpp" #else #define debug(...) 1 #endif #define ALL(a) (a).begin(), (a).end() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) using namespace std; using ll = int_fast64_t; using pr = pair<ll, ll>; using vll = vector<ll>; using vpr = vector<pr>; template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } else return false; } template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } else return false; } void answer() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; sort(ALL(a)); vector<bool> memo(1000005, true); vector<int> cnt(1000005, 0); rep(i, n) { cnt[a[i]]++; int b = 2 * a[i]; if (cnt[a[i]] == 1) { while (b <= 1000000) { memo[b] = false; b += a[i]; } } } int ans = 0; rep(i, n) { if (cnt[a[i]] == 1 && memo[a[i]]) ans++; } cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); answer(); return 0; }
replace
43
46
43
48
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define MOD 1000000007 using namespace std; vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } return (ret); } int main() { ll n; cin >> n; vector<ll> a(n); map<ll, ll> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } int ans = 0; for (int i = 0; i < n; i++) { if (mp[a[i]] >= 2) { continue; } auto tmp = divisor(a[i]); int flag = 0; for (auto e : tmp) { if (e != a[i] && mp[e]) { flag = 1; break; } } ans += (1 - flag); } cout << ans << endl; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define MOD 1000000007 using namespace std; vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } return (ret); } int main() { ll n; cin >> n; vector<ll> a(n); vector<ll> mp(1000001, 0); for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } int ans = 0; for (int i = 0; i < n; i++) { if (mp[a[i]] >= 2) { continue; } auto tmp = divisor(a[i]); int flag = 0; for (auto e : tmp) { if (e != a[i] && mp[e]) { flag = 1; break; } } ans += (1 - flag); } cout << ans << endl; }
replace
20
21
20
21
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define ll long long #define pb push_back #define ff first #define ss second #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mod 1000000007 #define mx 1000002 mt19937 myrand(time(0)); int main() { ios::sync_with_stdio(0); cin.tie(), cout.tie(); ll n; cin >> n; ll a[n]; map<ll, ll> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } ll ans = 0; for (int i = 0; i < n; i++) { mp[a[i]]--; bool valid = 1; for (int j = 1; (j * j) <= a[i]; j++) { if (a[i] % j == 0) { if (mp[j] > 0) { valid = 0; break; } if (mp[a[i] / j] > 0) { valid = 0; break; } } } if (valid) ans++; mp[a[i]]++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define ll long long #define pb push_back #define ff first #define ss second #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mod 1000000007 #define mx 1000002 mt19937 myrand(time(0)); int main() { ios::sync_with_stdio(0); cin.tie(), cout.tie(); ll n; cin >> n; ll a[n]; vector<ll> mp(mx, 0); for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } ll ans = 0; for (int i = 0; i < n; i++) { mp[a[i]]--; bool valid = 1; for (int j = 1; (j * j) <= a[i]; j++) { if (a[i] % j == 0) { if (mp[j] > 0) { valid = 0; break; } if (mp[a[i] / j] > 0) { valid = 0; break; } } } if (valid) ans++; mp[a[i]]++; } cout << ans << endl; return 0; }
replace
52
53
52
53
TLE
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define rep(i, j, n) for (int i = j; i < (int)(n); i++) signed main() { ll n; cin >> n; vl vec(n); map<ll, ll> mp; unordered_set<ll> s; rep(i, 0, n) { cin >> vec[i]; mp[vec[i]]++; s.insert(vec[i]); } ll ans = 0; rep(i, 0, n) { bool ok = true; if (mp[vec[i]] > 1) { continue; } for (ll j = (s.count(1) ? 1 : 2); j * j <= vec[i]; j++) { if (vec[i] == j) continue; if (vec[i] % j == 0 && s.count(j)) { ok = false; break; } else if (vec[i] % j == 0 && s.count(vec[i] / j)) { ok = false; break; } } if (ok) { ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define rep(i, j, n) for (int i = j; i < (int)(n); i++) signed main() { ll n; cin >> n; vl vec(n); map<ll, ll> mp; set<ll> s; rep(i, 0, n) { cin >> vec[i]; mp[vec[i]]++; s.insert(vec[i]); } ll ans = 0; rep(i, 0, n) { bool ok = true; if (mp[vec[i]] > 1) { continue; } for (ll j = (s.count(1) ? 1 : 2); j * j <= vec[i]; j++) { if (vec[i] == j) continue; if (vec[i] % j == 0 && s.count(j)) { ok = false; break; } else if (vec[i] % j == 0 && s.count(vec[i] / j)) { ok = false; break; } } if (ok) { ans++; } } cout << ans; return 0; }
replace
15
16
15
16
TLE
p02642
C++
Time Limit Exceeded
// KEEP GRINDING #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define ld long double #define MOD 1000000007 #define mod 998244353 #define precise(i) fixed << setprecision(10) << i #define f(i, a, b) for (int i = a; i < b; ++i) #define endl '\n' #define debug cout << "\n========================================\n" << endl; #define err1(a) cout << #a << " " << a << endl; #define err2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl; #define err3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl; #define err4(a, b, c, d) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << " " << #d << " " << d << endl; #define all(a) a.begin(), a.end() #define show(a) \ for (auto xyz : a) \ cout << xyz << " "; \ cout << endl; #define mx(a) *max_element(a) #define mn(a) *min_element(a) #define LB \ lower_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= // OUR VALUE #define UB \ upper_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > // OUR VALUE #define fr first #define sc second #define MAXN 200005 #define INF 9223372036854775807 signed main() { fastio int n, ans = 0; cin >> n; vector<int> a(n); f(i, 0, n) cin >> a[i]; sort(all(a)); vector<int> b(1000010, 0); f(i, 0, n - 1) { if (a[i] == a[i + 1]) b[a[i]] = 1; } f(i, 0, n) { for (int j = 2 * a[i]; j < 1000001; j += a[i]) b[j] = 1; } f(i, 0, n) { if (!b[a[i]]) ans++; } cout << ans; }
// KEEP GRINDING #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define ld long double #define MOD 1000000007 #define mod 998244353 #define precise(i) fixed << setprecision(10) << i #define f(i, a, b) for (int i = a; i < b; ++i) #define endl '\n' #define debug cout << "\n========================================\n" << endl; #define err1(a) cout << #a << " " << a << endl; #define err2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl; #define err3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl; #define err4(a, b, c, d) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << " " << #d << " " << d << endl; #define all(a) a.begin(), a.end() #define show(a) \ for (auto xyz : a) \ cout << xyz << " "; \ cout << endl; #define mx(a) *max_element(a) #define mn(a) *min_element(a) #define LB \ lower_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= // OUR VALUE #define UB \ upper_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > // OUR VALUE #define fr first #define sc second #define MAXN 200005 #define INF 9223372036854775807 signed main() { fastio int n, ans = 0; cin >> n; vector<int> a(n); f(i, 0, n) cin >> a[i]; sort(all(a)); vector<int> b(1000010, 0); f(i, 0, n - 1) { if (a[i] == a[i + 1]) b[a[i]] = 1; } for (int j = 2 * a[0]; j < 1000001; j += a[0]) b[j] = 1; f(i, 1, n) { if (a[i] != a[i - 1]) for (int j = 2 * a[i]; j < 1000001; j += a[i]) b[j] = 1; } f(i, 0, n) { if (!b[a[i]]) ans++; } cout << ans; }
replace
65
68
65
71
TLE
p02642
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int main() { int n; std::cin >> n; int64_t aMax = 0; std::vector<int64_t> a(n); for (int i = 0; i != n; i++) { std::cin >> a[i]; if (a[i] > aMax) aMax = a[i]; } std::vector<bool> dp(aMax, true); std::vector<bool> seen(aMax, false); std::sort(a.begin(), a.end()); int result = 0; for (int i = 0; i != n; i++) { if (dp[a[i]] == false) continue; if (seen[a[i]]) { dp[a[i]] = false; continue; } seen[a[i]] = true; for (int j = 2 * a[i]; j <= aMax; j += a[i]) { dp[j] = false; } } for (int i = 0; i != n; i++) if (dp[a[i]]) result++; std::cout << result << std::endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> int main() { int n; std::cin >> n; int64_t aMax = 0; std::vector<int64_t> a(n); for (int i = 0; i != n; i++) { std::cin >> a[i]; if (a[i] > aMax) aMax = a[i]; } std::vector<bool> dp(aMax + 1, true); std::vector<bool> seen(aMax + 1, false); std::sort(a.begin(), a.end()); int result = 0; for (int i = 0; i != n; i++) { if (dp[a[i]] == false) continue; if (seen[a[i]]) { dp[a[i]] = false; continue; } seen[a[i]] = true; for (int j = 2 * a[i]; j <= aMax; j += a[i]) { dp[j] = false; } } for (int i = 0; i != n; i++) if (dp[a[i]]) result++; std::cout << result << std::endl; return 0; }
replace
16
18
16
18
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); ++i) #define for1(i, n) for (int i = 1; i <= int(n); ++i) #define ms(a, x) memset(a, x, sizeof(a)) #define F first #define S second #define all(x) (x).begin(), (x).end() #define size(x) int(x.size()) #define pb push_back using namespace std; using ll = long long; using pii = pair<int, int>; mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); template <typename... T> void rd(T &...args) { ((cin >> args), ...); } template <typename... T> void wr(T... args) { ((cout << args << " "), ...); cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); map<int, int> mp; for (auto &it : a) cin >> it, mp[it]++; int ans = 0; for (auto it : a) { mp[it]--; for (ll f = 1; f * f <= it; f++) { if (it % f == 0) { if (mp[f] || mp[it / f]) goto next; } } ans++; next:; mp[it]++; } cout << ans; return 0; }
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); ++i) #define for1(i, n) for (int i = 1; i <= int(n); ++i) #define ms(a, x) memset(a, x, sizeof(a)) #define F first #define S second #define all(x) (x).begin(), (x).end() #define size(x) int(x.size()) #define pb push_back using namespace std; using ll = long long; using pii = pair<int, int>; mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); template <typename... T> void rd(T &...args) { ((cin >> args), ...); } template <typename... T> void wr(T... args) { ((cout << args << " "), ...); cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); unordered_map<int, int> mp; for (auto &it : a) cin >> it, mp[it]++; int ans = 0; for (auto it : a) { mp[it]--; for (ll f = 1; f * f <= it; f++) { if (it % f == 0) { if (mp[f] || mp[it / f]) goto next; } } ans++; next:; mp[it]++; } cout << ans; return 0; }
replace
27
28
27
28
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; ll nums[101010]; bool divisor(ll n) { vector<ll> div; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (nums[i] > 0) return false; if (i != n / i) { if (nums[n / i] > 0) return false; } } } return true; } int main() { ll n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; nums[a[i]]++; } ll ans = 0; for (int i = 0; i < n; i++) { nums[a[i]]--; if (divisor(a[i])) ans++; nums[a[i]]++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; ll nums[1010101]; bool divisor(ll n) { vector<ll> div; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (nums[i] > 0) return false; if (i != n / i) { if (nums[n / i] > 0) return false; } } } return true; } int main() { ll n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; nums[a[i]]++; } ll ans = 0; for (int i = 0; i < n; i++) { nums[a[i]]--; if (divisor(a[i])) ans++; nums[a[i]]++; } cout << ans << endl; }
replace
5
6
5
6
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; bool nums[1010101]; ll cnt[1010101]; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { cnt[a[i]]++; if (nums[a[i]]) continue; for (int j = 2 * a[i]; j < 1010101; j += a[i]) nums[j] = true; } ll ans = 0; for (int i = 0; i < n; i++) { if (cnt[a[i]] == 1 && !nums[a[i]]) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; bool nums[1010101]; ll cnt[1010101]; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { cnt[a[i]]++; if (nums[a[i]]) continue; if (cnt[a[i]] > 1) continue; for (int j = 2 * a[i]; j < 1010101; j += a[i]) nums[j] = true; } ll ans = 0; for (int i = 0; i < n; i++) { if (cnt[a[i]] == 1 && !nums[a[i]]) ans++; } cout << ans << endl; }
insert
19
19
19
21
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; int a_max = 0; int ans = 0; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; a.push_back(tmp); if (a_max < tmp) { a_max = tmp; } } sort(a.begin(), a.end()); vector<bool> b(a_max + 1); vector<int> cnt(a_max + 1, 0); for (int i = 0; i < n; i++) { cnt[a[i]]++; for (int j = 2; j < a_max; j++) { if (i * j > a_max) { break; } b[a[i] * j] = true; } } for (int i = 0; i < n; i++) { if (!b[a[i]] && cnt[a[i]] == 1) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; int a_max = 0; int ans = 0; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; a.push_back(tmp); if (a_max < tmp) { a_max = tmp; } } sort(a.begin(), a.end()); vector<bool> b(a_max + 1); vector<int> cnt(a_max + 1, 0); for (int i = 0; i < n; i++) { cnt[a[i]]++; for (int j = 2; j <= a_max; j++) { if (a[i] * j > a_max) { break; } b[a[i] * j] = true; } } for (int i = 0; i < n; i++) { if (!b[a[i]] && cnt[a[i]] == 1) { ans++; } } cout << ans << endl; return 0; }
replace
28
30
28
30
0
p02642
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using Int = long long; int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0); // int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv // ./prog.exe") >> 8), 0); int main() { int N; cin >> N; vector<int> A(N); for (auto &a : A) cin >> a; vector<int> B(1000010); for (auto a : A) { for (int t = a; t <= 1000000; t += a) { B[t] += 1; } } int ans = 0; for (auto a : A) { if (B[a] == 1) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long; int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0); // int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv // ./prog.exe") >> 8), 0); int main() { int N; cin >> N; vector<int> A(N); for (auto &a : A) cin >> a; vector<int> B(1000010); for (auto a : A) { if (B[a] != 0) { B[a]++; continue; } for (int t = a; t <= 1000000; t += a) { B[t] += 1; } } int ans = 0; for (auto a : A) { if (B[a] == 1) ans++; } cout << ans << endl; return 0; }
insert
15
15
15
19
TLE
p02642
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define all(x) (x).begin(), (x).end() #define uniq(x) (x).erase(unique(all(x)), (x).end())) #define bit(n) (1LL << (n)) #define cdiv(a, b) (((a)-1) / (b) + 1) #define dump(x) cerr << #x " = " << (x) << endl using vint = vector<int>; using vvint = vector<vint>; using pint = pair<int, int>; using vpint = vector<pint>; template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double PI = 3.1415926535897932384626433832795028; constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { while (b) { swap(a %= b, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template <typename T> void fin(T mes) { cout << mes << endl; exit(0); } template <typename T, typename U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template <typename T, typename U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) { os << "(" << rhs.first << ", " << rhs.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) { os << "{"; for (auto itr = rhs.begin(); itr != rhs.end(); itr++) { os << *itr << (next(itr) != rhs.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); }; } setup; std::vector<long long> get_divisors(long long n) { std::vector<long long> ret; long long i; for (i = 1; i * i < n; i++) { if (n % i == 0) { ret.push_back(i); ret.push_back(n / i); } } if (i * i == n) { ret.push_back(i); } std::sort(ret.begin(), ret.end()); return ret; } int N; int A[110000]; int ap[1100000]; signed main() { cin >> N; rep(i, N) { cin >> A[i]; } rep(i, N) { ap[A[i]]++; } int ans = 0; rep(i, N) { int cnt = 0; vint v = get_divisors(A[i]); rep(j, v.size()) { cnt += ap[v[j]]; } if (cnt == 1) { ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define all(x) (x).begin(), (x).end() #define uniq(x) (x).erase(unique(all(x)), (x).end())) #define bit(n) (1LL << (n)) #define cdiv(a, b) (((a)-1) / (b) + 1) #define dump(x) cerr << #x " = " << (x) << endl using vint = vector<int>; using vvint = vector<vint>; using pint = pair<int, int>; using vpint = vector<pint>; template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double PI = 3.1415926535897932384626433832795028; constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { while (b) { swap(a %= b, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template <typename T> void fin(T mes) { cout << mes << endl; exit(0); } template <typename T, typename U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template <typename T, typename U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) { os << "(" << rhs.first << ", " << rhs.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) { os << "{"; for (auto itr = rhs.begin(); itr != rhs.end(); itr++) { os << *itr << (next(itr) != rhs.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); }; } setup; std::vector<long long> get_divisors(long long n) { std::vector<long long> ret; long long i; for (i = 1; i * i < n; i++) { if (n % i == 0) { ret.push_back(i); ret.push_back(n / i); } } if (i * i == n) { ret.push_back(i); } std::sort(ret.begin(), ret.end()); return ret; } int N; int A[220000]; int ap[1100000]; signed main() { cin >> N; rep(i, N) { cin >> A[i]; } rep(i, N) { ap[A[i]]++; } int ans = 0; rep(i, N) { int cnt = 0; vint v = get_divisors(A[i]); rep(j, v.size()) { cnt += ap[v[j]]; } if (cnt == 1) { ans++; } } cout << ans << endl; }
replace
83
84
83
84
0
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <vector> #define rep(i, j, k) for (int i = j; i <= k; i++) #define dow(i, j, k) for (int i = j; i >= k; i--) #define fi first #define se second using namespace std; typedef long long ll; typedef pair<int, int> pi; const int N = 1e6 + 100; int cnt[N]; int a[N], n; int ans = 0; int main() { scanf("%d", &n); rep(i, 1, n) scanf("%d", &a[i]), cnt[a[i]]++; sort(a + 1, a + n + 1); rep(i, 1, n) { for (int j = 2; a[i] * j <= 1000000; j++) cnt[a[i] * j]++; if (cnt[a[i]] > 1) continue; ans++; // for (int j = 2; a[i] * j <= 1000000; j++) cnt[a[i] * j]++; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <vector> #define rep(i, j, k) for (int i = j; i <= k; i++) #define dow(i, j, k) for (int i = j; i >= k; i--) #define fi first #define se second using namespace std; typedef long long ll; typedef pair<int, int> pi; const int N = 1e6 + 100; int cnt[N]; int a[N], n; int ans = 0; int main() { scanf("%d", &n); rep(i, 1, n) scanf("%d", &a[i]), cnt[a[i]]++; sort(a + 1, a + n + 1); rep(i, 1, n) { if (a[i] == a[i - 1]) continue; for (int j = 2; a[i] * j <= 1000000; j++) cnt[a[i] * j]++; if (cnt[a[i]] > 1) continue; ans++; // for (int j = 2; a[i] * j <= 1000000; j++) cnt[a[i] * j]++; } cout << ans << endl; }
insert
27
27
27
29
TLE
p02642
C++
Time Limit Exceeded
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using ll = long long; using namespace std; const ll mod = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); vector<int> table(12345678, 0); for (int i = 0; i < n; i++) { cin >> a[i]; table[a[i]]++; } sort(a.begin(), a.end()); ll cnt = 0; for (int i = 0; i < n; i++) { for (int j = 2; j * a[i] <= 1000000; j++) { table[a[i] * j]++; } } int ans = 0; for (int i = 0; i < n; i++) { if (table[a[i]] <= 1) ans++; } cout << ans << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using ll = long long; using namespace std; const ll mod = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); vector<int> table(12345678, 0); for (int i = 0; i < n; i++) { cin >> a[i]; table[a[i]]++; } sort(a.begin(), a.end()); ll cnt = 0; for (int i = 0; i < n; i++) { for (int j = 2; a[i] * j <= a[n - 1]; j++) { table[a[i] * j]++; } } int ans = 0; for (int i = 0; i < n; i++) { if (table[a[i]] <= 1) ans++; } cout << ans << endl; return 0; }
replace
31
32
31
32
TLE