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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02971 | C++ | Runtime Error | #include <iostream>
using namespace std;
const int INFTY = 1 << 21;
int L[50000], R[50000];
void merge(int A[], int left, int mid, int right) {
int n1 = mid - left;
int n2 = right - mid;
for (int i = 0; i < n1; i++)
L[i] = A[left + i];
for (int i = 0; i < n2; i++)
R[i] = A[mid + i];
L[n1] = R[n2] = INFTY;
int i = 0, j = 0;
for (int p = left; p < right; p++) {
if (L[i] <= R[j])
A[p] = L[i++];
else
A[p] = R[j++];
}
}
void sort(int A[], int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
sort(A, left, mid);
sort(A, mid, right);
merge(A, left, mid, right);
}
}
int main() {
int n, max = 0, p;
cin >> n;
int A[200005];
for (int i = 0; i < n; i++) {
cin >> A[i];
if (A[i] > max) {
max = A[i];
p = i;
}
}
sort(A, 0, n);
for (int i = 0; i < n; i++) {
if (i == p)
cout << A[n - 2] << endl;
else
cout << A[n - 1] << endl;
}
return 0;
} | #include <iostream>
using namespace std;
const int INFTY = 1 << 21;
int L[200005], R[200005];
void merge(int A[], int left, int mid, int right) {
int n1 = mid - left;
int n2 = right - mid;
for (int i = 0; i < n1; i++)
L[i] = A[left + i];
for (int i = 0; i < n2; i++)
R[i] = A[mid + i];
L[n1] = R[n2] = INFTY;
int i = 0, j = 0;
for (int p = left; p < right; p++) {
if (L[i] <= R[j])
A[p] = L[i++];
else
A[p] = R[j++];
}
}
void sort(int A[], int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
sort(A, left, mid);
sort(A, mid, right);
merge(A, left, mid, right);
}
}
int main() {
int n, max = 0, p;
cin >> n;
int A[200005];
for (int i = 0; i < n; i++) {
cin >> A[i];
if (A[i] > max) {
max = A[i];
p = i;
}
}
sort(A, 0, n);
for (int i = 0; i < n; i++) {
if (i == p)
cout << A[n - 2] << endl;
else
cout << A[n - 1] << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAX = 1e5 + 10;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
int N, A[MAX];
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
int maxi[2];
maxi[0] = maxi[1] = 0;
for (int i = 0; i < N; i++) {
if (maxi[0] < A[i]) {
maxi[1] = maxi[0];
maxi[0] = A[i];
} else if (maxi[1] < A[i]) {
maxi[1] = A[i];
}
}
for (int i = 0; i < N; i++) {
if (maxi[0] == A[i])
cout << maxi[1] << endl;
else
cout << maxi[0] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAX = 1e6 + 10;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
int N, A[MAX];
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
int maxi[2];
maxi[0] = maxi[1] = 0;
for (int i = 0; i < N; i++) {
if (maxi[0] < A[i]) {
maxi[1] = maxi[0];
maxi[0] = A[i];
} else if (maxi[1] < A[i]) {
maxi[1] = A[i];
}
}
for (int i = 0; i < N; i++) {
if (maxi[0] == A[i])
cout << maxi[1] << endl;
else
cout << maxi[0] << endl;
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02971 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading \
zero str.erase(0, min(str.find_first_not_of('0'), str.size() - 1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
string text = "abcdefghijklmnopqrstuvwxyz";
const int maxn = 1e6 + 7;
// .--------------.
// | Try First One|
// '--------------'
// | .--------------.
// | | |
// V V |
// .--------------. |
// | AC. |<---. |
// '--------------' | |
// (True)| |(False) | |
// .--------' | | |
// | V | |
// | .--------------. | |
// | | Try Again |----' |
// | '--------------' |
// | |
// | .--------------. |
// '->| Try Next One |-------'
// '--------------'
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
multiset<int> s;
int a[n + 2];
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (int i = 0; i < n; i++) {
int x = a[i];
s.erase(s.find(x));
cout << *max_element(s.begin(), s.end()) << endl;
s.insert(x);
}
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading \
zero str.erase(0, min(str.find_first_not_of('0'), str.size() - 1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
string text = "abcdefghijklmnopqrstuvwxyz";
const int maxn = 1e6 + 7;
// .--------------.
// | Try First One|
// '--------------'
// | .--------------.
// | | |
// V V |
// .--------------. |
// | AC. |<---. |
// '--------------' | |
// (True)| |(False) | |
// .--------' | | |
// | V | |
// | .--------------. | |
// | | Try Again |----' |
// | '--------------' |
// | |
// | .--------------. |
// '->| Try Next One |-------'
// '--------------'
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
multiset<int> s;
int a[n + 2];
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (int i = 0; i < n; i++) {
int x = a[i];
s.erase(s.find(x));
cout << *s.rbegin() << endl;
s.insert(x);
}
}
| replace | 48 | 49 | 48 | 49 | TLE | |
p02971 | C++ | Runtime Error | // stringray
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*#ifndef __LOCAL__
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ost;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb emplace_back
#define F first
#define S second
#define fori(i, n) for (int i = 1; i <= n; ++i)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define error(x) cout << #x << " " << x << endl
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(0)
const int N = 100 * 1000;
const int mod = 1e9 + 7;
int min3(int a, int b, int c) { return min(a, min(b, c)); }
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int min4(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }
int max4(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
// for(int i=0;i<vec.size();++i)is>>x[i];
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); ++i) {
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
}
return os;
}
ll mpow(ll a, ll b) {
ll ret = 1;
while (b > 0) {
if (b & 1)
ret = (ret * a) % mod;
(a = a * a) %= mod;
b >>= 1LL;
}
return ret;
}
// #define int int64_t
int a[N + 2];
int pref[N + 2];
int suff[N + 2];
void solve() {
int n;
cin >> n;
fori(i, n) cin >> a[i];
fori(i, n) {
pref[i] = a[i];
if (i > 1)
pref[i] = max(pref[i - 1], a[i]);
}
for (int i = n; i >= 1; --i) {
suff[i] = a[i];
if (i != n)
suff[i] = max(suff[i], suff[i + 1]);
}
fori(i, n) {
if (i == 1)
cout << suff[2] << endl;
else if (i == n)
cout << pref[n - 1] << endl;
else
cout << max(pref[i - 1], suff[i + 1]) << endl;
}
}
int32_t main() {
IOS;
solve();
return 0;
}
| // stringray
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*#ifndef __LOCAL__
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ost;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb emplace_back
#define F first
#define S second
#define fori(i, n) for (int i = 1; i <= n; ++i)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define error(x) cout << #x << " " << x << endl
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(0)
const int N = 100 * 1000;
const int mod = 1e9 + 7;
int min3(int a, int b, int c) { return min(a, min(b, c)); }
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int min4(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }
int max4(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
// for(int i=0;i<vec.size();++i)is>>x[i];
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); ++i) {
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
}
return os;
}
ll mpow(ll a, ll b) {
ll ret = 1;
while (b > 0) {
if (b & 1)
ret = (ret * a) % mod;
(a = a * a) %= mod;
b >>= 1LL;
}
return ret;
}
// #define int int64_t
int a[2 * N + 2];
int pref[2 * N + 2];
int suff[2 * N + 2];
void solve() {
int n;
cin >> n;
fori(i, n) cin >> a[i];
fori(i, n) {
pref[i] = a[i];
if (i > 1)
pref[i] = max(pref[i - 1], a[i]);
}
for (int i = n; i >= 1; --i) {
suff[i] = a[i];
if (i != n)
suff[i] = max(suff[i], suff[i + 1]);
}
fori(i, n) {
if (i == 1)
cout << suff[2] << endl;
else if (i == n)
cout << pref[n - 1] << endl;
else
cout << max(pref[i - 1], suff[i + 1]) << endl;
}
}
int32_t main() {
IOS;
solve();
return 0;
}
| replace | 85 | 88 | 85 | 88 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define _FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define MAXX 100005
int n;
int a[MAXX];
int b[MAXX];
int main() {
_FastIO;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
for (int i = 0; i < n; i++) {
if (a[i] == b[n - 1]) {
cout << b[n - 2] << endl;
} else
cout << b[n - 1] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define _FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define MAXX 200005
int n;
int a[MAXX];
int b[MAXX];
int main() {
_FastIO;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
for (int i = 0; i < n; i++) {
if (a[i] == b[n - 1]) {
cout << b[n - 2] << endl;
} else
cout << b[n - 1] << endl;
}
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02971 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, A;
cin >> N;
vector<int> As(N);
for (int i = 0; i < N; i++) {
cin >> As.at(i);
}
for (int i = 0; i < N; i++) {
vector<int> tempAs = As;
tempAs.at(i) = 0;
sort(tempAs.begin(), tempAs.end());
cout << tempAs.at(N - 1) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, A;
cin >> N;
vector<int> As(N);
for (int i = 0; i < N; i++) {
cin >> As.at(i);
}
vector<int> tempAs = As;
sort(tempAs.begin(), tempAs.end());
if (tempAs.at(N - 1) == tempAs.at(N - 2)) {
for (int i = 0; i < N; i++) {
cout << tempAs.at(N - 1) << endl;
}
} else {
int place = 0;
for (int j = 0; j < N; j++) {
if (As.at(j) < tempAs.at(N - 1))
place++;
if (As.at(j) == tempAs.at(N - 1))
break;
}
for (int i = 0; i < place; i++) {
cout << tempAs.at(N - 1) << endl;
}
cout << tempAs.at(N - 2) << endl;
for (int i = place + 1; i < N; i++) {
cout << tempAs.at(N - 1) << endl;
}
}
} | replace | 12 | 17 | 12 | 34 | TLE | |
p02971 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
vector<int> B(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
B = A;
B[i] = 0;
sort(B.begin(), B.end());
cout << B[N - 1] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
vector<int> B(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
B = A;
sort(B.begin(), B.end());
int max = B[N - 1];
if (B[N - 2] == B[N - 1]) {
for (int i = 0; i < N; i++) {
cout << B[N - 1] << endl;
}
} else {
for (int i = 0; i < N; i++) {
if (A[i] == max) {
cout << B[N - 2] << endl;
} else {
cout << max << endl;
}
}
}
} | replace | 13 | 18 | 13 | 31 | TLE | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100010], b[100010];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
for (int i = 0; i < n; i++) {
if (a[i] == b[n - 1])
cout << b[n - 2] << endl;
else
cout << b[n - 1] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[200010], b[200010];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
for (int i = 0; i < n; i++) {
if (a[i] == b[n - 1])
cout << b[n - 2] << endl;
else
cout << b[n - 1] << endl;
}
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02971 | C++ | Time Limit Exceeded | #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;
using ll = long long;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;
int main() {
int N;
cin >> N;
vector<int> v(N);
REP(i, N) { cin >> v[i]; }
int maxNum = *max_element(ALL(v));
REP(i, N) {
int tmp = v[i];
if (tmp == maxNum && count(ALL(v), maxNum) == 1)
// if (tmp == maxNum)
{
v[i] = *min_element(ALL(v));
cout << *max_element(ALL(v)) << endl;
v[i] = tmp;
} else {
cout << maxNum << endl;
}
}
return 0;
}
| #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;
using ll = long long;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;
int main() {
int N;
cin >> N;
vector<int> v(N);
REP(i, N) { cin >> v[i]; }
int maxNum = *max_element(ALL(v));
if (count(ALL(v), maxNum) > 1) {
REP(i, N) { cout << maxNum << endl; }
} else {
REP(i, N) {
int tmp = v[i];
if (tmp == maxNum) {
v[i] = *min_element(ALL(v));
cout << *max_element(ALL(v)) << endl;
v[i] = tmp;
} else {
cout << maxNum << endl;
}
}
}
return 0;
}
| replace | 40 | 50 | 40 | 52 | TLE | |
p02971 | C++ | Runtime Error | #pragma GCC optimize(2)
#pragma warning(disable : 4996)
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define itn int
#define F(i, a, b) for (int i = a; i <= (b); ++i)
#define F2(i, a, b) for (int i = a; i < (b); ++i)
#define dF(i, a, b) for (int i = a; i >= (b); --i)
const int maxn = 1000 * 100;
const int maxa = 1000 * 1000 * 1000 + 7;
typedef long long ll;
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int t, n, m, T, d;
int main() {
#ifdef _DEBUG
freopen("E:\\input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int i, j;
std::ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n) {
itn max1 = 0, max2 = 0, a[maxn];
for (int i = 0; i < n; i++) {
cin >> a[i];
int &tmp = a[i];
if (tmp > max1) {
max2 = max1;
max1 = tmp;
} else if (tmp > max2) {
max2 = tmp;
}
}
F2(i, 0, n) {
if (a[i] == max1)
cout << max2;
else
cout << max1;
cout << "\n";
}
}
return 0;
} | #pragma GCC optimize(2)
#pragma warning(disable : 4996)
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define itn int
#define F(i, a, b) for (int i = a; i <= (b); ++i)
#define F2(i, a, b) for (int i = a; i < (b); ++i)
#define dF(i, a, b) for (int i = a; i >= (b); --i)
const int maxn = 2 * 1000 * 100;
const int maxa = 1000 * 1000 * 1000 + 7;
typedef long long ll;
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int t, n, m, T, d;
int main() {
#ifdef _DEBUG
freopen("E:\\input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int i, j;
std::ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n) {
itn max1 = 0, max2 = 0, a[maxn];
for (int i = 0; i < n; i++) {
cin >> a[i];
int &tmp = a[i];
if (tmp > max1) {
max2 = max1;
max1 = tmp;
} else if (tmp > max2) {
max2 = tmp;
}
}
F2(i, 0, n) {
if (a[i] == max1)
cout << max2;
else
cout << max1;
cout << "\n";
}
}
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reg register
#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define drep(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
char IO;
int rd() {
int s = 0, f = 0;
while (!isdigit(IO = getchar()))
if (IO == '-')
f = 1;
do
s = (s << 1) + (s << 3) + (IO ^ '0');
while (isdigit(IO = getchar()));
return f ? -s : s;
}
const int N = 1e5 + 10;
int n, a[N];
int s[N], s1[N];
int main() {
rep(i, 1, n = rd()) a[i] = rd(), s[i] = max(a[i], s[i - 1]);
drep(i, n, 1) s1[i] = max(a[i], s1[i + 1]);
rep(i, 1, n) { printf("%d\n", max(s[i - 1], s1[i + 1])); };
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reg register
#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define drep(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
char IO;
int rd() {
int s = 0, f = 0;
while (!isdigit(IO = getchar()))
if (IO == '-')
f = 1;
do
s = (s << 1) + (s << 3) + (IO ^ '0');
while (isdigit(IO = getchar()));
return f ? -s : s;
}
const int N = 5e5 + 10;
int n, a[N];
int s[N], s1[N];
int main() {
rep(i, 1, n = rd()) a[i] = rd(), s[i] = max(a[i], s[i - 1]);
drep(i, n, 1) s1[i] = max(a[i], s1[i + 1]);
rep(i, 1, n) { printf("%d\n", max(s[i - 1], s1[i + 1])); };
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n, a[N];
multiset<int> m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
m.insert(a[i]);
}
for (int i = 1; i <= n; i++) {
m.erase(m.find(a[i]));
auto it = m.end();
it--;
cout << *it << "\n";
m.insert(a[i]);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n, a[N];
multiset<int> m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
m.insert(a[i]);
}
for (int i = 1; i <= n; i++) {
m.erase(m.find(a[i]));
auto it = m.end();
it--;
cout << *it << "\n";
m.insert(a[i]);
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define ppb pop_back
#define ppf pop_front
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define Sort(name) sort(name.begin(), name.end())
#define For(name, start, finish) for (int name = start; name < finish; name++)
#define fast_in_out \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
// int row[]={-1,0,1,0};
// int col[]={0,1,0,-1};
const ll N = 1e5 + 10;
const ll M = 1e9 + 7;
ll Max(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll Min(ll a, ll b) {
if (a > b)
return b;
return a;
}
ll big_mul(ll a, ll b, ll m) {
ll x = 0, y = a % m;
while (b > 0) {
if (b & 1)
x = (x + y) % m;
y = (2 * y) % m;
b >>= 1;
}
return x % m;
}
ll big_mod(ll a, ll b, ll m) {
ll x = 1, y = a % m;
while (b > 0) {
if (b & 1)
x = (x * y) % m;
y = (y * y) % m;
b >>= 1;
}
return x % m;
}
ll Big_mod(ll a, ll b, ll m) {
ll x = 1, y = a % m;
while (b > 0) {
if (b & 1)
x = big_mul(x, y, m);
y = big_mul(y, y, m);
b >>= 1;
}
return x % m;
}
ll mod_inverse(ll a, ll m) {
return big_mod(a, m - 2, m);
} // a^-1 mod m = a^(m-2) mod m
vector<ll> vec;
vector<pair<ll, pair<ll, ll>>> tree(5 * N);
void build_tree(ll index, ll l, ll r) {
if (l == r) {
tree[index] = make_pair(vec[l], make_pair(l, r));
return;
}
int mid = (l + r) / 2;
build_tree(2 * index + 1, l, mid);
build_tree(2 * index + 2, mid + 1, r);
tree[index].second.first = l;
tree[index].second.second = r;
tree[index].first = Max(tree[2 * index + 1].first, tree[2 * index + 2].first);
}
ll ans(ll index, ll a, ll b) {
ll l = tree[index].second.first;
ll r = tree[index].second.second;
if (a > r || b < l)
return 0;
if (a <= l && b >= r)
return tree[index].first;
return Max(ans(2 * index + 1, a, b), ans(2 * index + 2, a, b));
}
int main() {
fast_in_out;
int n;
cin >> n;
For(i, 0, n) {
ll a;
cin >> a;
vec.pb(a);
}
build_tree(0, 0, n - 1);
For(i, 0, n) {
ll p = ans(0, 0, i - 1);
ll q = ans(0, i + 1, n - 1);
cout << Max(p, q) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define ppb pop_back
#define ppf pop_front
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define Sort(name) sort(name.begin(), name.end())
#define For(name, start, finish) for (int name = start; name < finish; name++)
#define fast_in_out \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
// int row[]={-1,0,1,0};
// int col[]={0,1,0,-1};
const ll N = 2e5 + 10;
const ll M = 1e9 + 7;
ll Max(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll Min(ll a, ll b) {
if (a > b)
return b;
return a;
}
ll big_mul(ll a, ll b, ll m) {
ll x = 0, y = a % m;
while (b > 0) {
if (b & 1)
x = (x + y) % m;
y = (2 * y) % m;
b >>= 1;
}
return x % m;
}
ll big_mod(ll a, ll b, ll m) {
ll x = 1, y = a % m;
while (b > 0) {
if (b & 1)
x = (x * y) % m;
y = (y * y) % m;
b >>= 1;
}
return x % m;
}
ll Big_mod(ll a, ll b, ll m) {
ll x = 1, y = a % m;
while (b > 0) {
if (b & 1)
x = big_mul(x, y, m);
y = big_mul(y, y, m);
b >>= 1;
}
return x % m;
}
ll mod_inverse(ll a, ll m) {
return big_mod(a, m - 2, m);
} // a^-1 mod m = a^(m-2) mod m
vector<ll> vec;
vector<pair<ll, pair<ll, ll>>> tree(5 * N);
void build_tree(ll index, ll l, ll r) {
if (l == r) {
tree[index] = make_pair(vec[l], make_pair(l, r));
return;
}
int mid = (l + r) / 2;
build_tree(2 * index + 1, l, mid);
build_tree(2 * index + 2, mid + 1, r);
tree[index].second.first = l;
tree[index].second.second = r;
tree[index].first = Max(tree[2 * index + 1].first, tree[2 * index + 2].first);
}
ll ans(ll index, ll a, ll b) {
ll l = tree[index].second.first;
ll r = tree[index].second.second;
if (a > r || b < l)
return 0;
if (a <= l && b >= r)
return tree[index].first;
return Max(ans(2 * index + 1, a, b), ans(2 * index + 2, a, b));
}
int main() {
fast_in_out;
int n;
cin >> n;
For(i, 0, n) {
ll a;
cin >> a;
vec.pb(a);
}
build_tree(0, 0, n - 1);
For(i, 0, n) {
ll p = ans(0, 0, i - 1);
ll q = ans(0, i + 1, n - 1);
cout << Max(p, q) << endl;
}
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define rev(i, s, e) for (i64(i) = (s); (i)-- > (e);)
#define all(x) x.begin(), x.end()
int main() {
i64 N;
cin >> N;
vector<i64> A(N);
rep(i, 0, N) cin >> A[i];
multiset<i64> st;
rep(i, 0, N) st.insert(A[i]);
rep(i, 0, N) {
st.erase(A[i]);
cout << *(--st.end()) << endl;
st.insert(A[i]);
}
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define rev(i, s, e) for (i64(i) = (s); (i)-- > (e);)
#define all(x) x.begin(), x.end()
int main() {
i64 N;
cin >> N;
vector<i64> A(N);
rep(i, 0, N) cin >> A[i];
multiset<i64> st;
rep(i, 0, N) st.insert(A[i]);
rep(i, 0, N) {
st.erase(st.lower_bound(A[i]));
cout << *(--st.end()) << endl;
st.insert(A[i]);
}
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ii pair<int, int>
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);
const int N = 100100;
ll n, q, a[N], seg[N << 2];
ll mrg(ll x1, ll x2) { return max(x1, x2); }
void build(int idx, int from, int to) {
if (from == to) {
seg[idx] = a[from];
return;
}
int mid = (from + to) >> 1;
build(idx << 1, from, mid);
build(idx << 1 | 1, mid + 1, to);
seg[idx] = mrg(seg[idx << 1], seg[idx << 1 | 1]);
}
ll query(int idx, int from, int to, int l, int r) {
if (from >= l && to <= r)
return seg[idx];
if (from > r || to < l)
return 0LL;
int mid = (from + to) >> 1;
ll x1 = query(idx << 1, from, mid, l, r);
ll x2 = query(idx << 1 | 1, mid + 1, to, l, r);
return mrg(x1, x2);
}
int main() {
SPEED
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
build(1, 1, n);
cout << query(1, 1, n, 2, n) << endl;
for (int i = 2; i < n; i++) {
cout << max(query(1, 1, n, 1, i - 1), query(1, 1, n, i + 1, n)) << endl;
}
cout << query(1, 1, n, 1, n - 1);
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ii pair<int, int>
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);
const int N = 200100;
ll n, q, a[N], seg[N << 2];
ll mrg(ll x1, ll x2) { return max(x1, x2); }
void build(int idx, int from, int to) {
if (from == to) {
seg[idx] = a[from];
return;
}
int mid = (from + to) >> 1;
build(idx << 1, from, mid);
build(idx << 1 | 1, mid + 1, to);
seg[idx] = mrg(seg[idx << 1], seg[idx << 1 | 1]);
}
ll query(int idx, int from, int to, int l, int r) {
if (from >= l && to <= r)
return seg[idx];
if (from > r || to < l)
return 0LL;
int mid = (from + to) >> 1;
ll x1 = query(idx << 1, from, mid, l, r);
ll x2 = query(idx << 1 | 1, mid + 1, to, l, r);
return mrg(x1, x2);
}
int main() {
SPEED
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
build(1, 1, n);
cout << query(1, 1, n, 2, n) << endl;
for (int i = 2; i < n; i++) {
cout << max(query(1, 1, n, 1, i - 1), query(1, 1, n, i + 1, n)) << endl;
}
cout << query(1, 1, n, 1, n - 1);
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02971 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v, v2;
int counter, tmp, max, second, result;
cin >> counter;
for (int i = 0; i < counter; i++) {
cin >> tmp;
v.emplace_back(tmp);
}
max = *max_element(v.begin(), v.end());
v2 = v;
sort(v2.begin(), v2.end(), greater<int>());
second = v2[1];
for (int i = 0; i < counter; i++) {
if (v[i] == max) {
cout << second << endl;
continue;
}
cout << *max_element(v.begin(), v.end()) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v, v2;
int counter, tmp, max, second, result;
cin >> counter;
for (int i = 0; i < counter; i++) {
cin >> tmp;
v.emplace_back(tmp);
}
max = *max_element(v.begin(), v.end());
v2 = v;
sort(v2.begin(), v2.end(), greater<int>());
second = v2[1];
for (int i = 0; i < counter; i++) {
if (v[i] == max) {
cout << second << endl;
continue;
}
cout << max << endl;
}
return 0;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p02971 | 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;
const int maxM = 2e5 + 7;
const int maxV = 90010;
const int MOD = 1e9 + 7;
int T;
const int maxN = 1e2 + 8;
const ll INF = 1000000000000000010LL;
const int K = 15;
int n;
int a[maxN];
int b[maxN];
int c[maxN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
b[1] = a[1];
for (int i = 2; i <= n; i++) {
b[i] = max(b[i - 1], a[i]);
}
c[n] = a[n];
for (int i = n - 1; i >= 1; i--) {
c[i] = max(c[i + 1], a[i]);
}
for (int i = 1; i <= n; i++) {
int L = 0, R = 0;
if (i - 1 >= 1)
L = b[i - 1];
if (R + 1 <= n)
R = c[i + 1];
int ans = max(L, R);
cout << ans << endl;
}
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;
const int maxM = 2e5 + 7;
const int maxV = 90010;
const int MOD = 1e9 + 7;
int T;
const int maxN = 2e5 + 8;
const ll INF = 1000000000000000010LL;
const int K = 15;
int n;
int a[maxN];
int b[maxN];
int c[maxN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
b[1] = a[1];
for (int i = 2; i <= n; i++) {
b[i] = max(b[i - 1], a[i]);
}
c[n] = a[n];
for (int i = n - 1; i >= 1; i--) {
c[i] = max(c[i + 1], a[i]);
}
for (int i = 1; i <= n; i++) {
int L = 0, R = 0;
if (i - 1 >= 1)
L = b[i - 1];
if (R + 1 <= n)
R = c[i + 1];
int ans = max(L, R);
cout << ans << endl;
}
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02971 | Python | Time Limit Exceeded | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy
def main():
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
tmp = copy(A)
tmp[i] = 0
print(max(tmp))
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy
def main():
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = copy(A)
A_max.sort(reverse=True)
for a in A:
if a == A_max[0]:
print(A_max[1])
else:
print(A_max[0])
if __name__ == "__main__":
main()
| replace | 8 | 12 | 8 | 16 | TLE | |
p02971 | Python | Runtime Error | n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = sorted(set(a))[n - 2 :]
if a.count(m1) > 1:
for _ in range(n):
print(m1)
else:
for x in a:
print(m1) if x == m2 else print(m2)
| n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
for x in a:
print(b[(x < b[-1]) - 2])
| replace | 2 | 9 | 2 | 5 | 0 | |
p02971 | Python | Time Limit Exceeded | n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
for i in range(n):
_a = a.copy()
_a.pop(i)
print(max(_a))
| n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]
if len(idxs) > 1:
for i in range(n):
print(m)
if len(idxs) == 1:
idx = idxs[0]
for i in range(n):
if idx == i:
_a = a.copy()
_a.pop(i)
print(max(_a))
else:
print(m)
| replace | 5 | 9 | 5 | 21 | TLE | |
p02971 | Python | Runtime Error | import itertools
n = int(input())
a = [int(input()) for i in range(n)]
max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = [0, *itertools.accumulate(reversed(a), func=max)][::-1]
# print(max_list)
# print(max_list_r)
for i in range(n):
print(max(max_list[i], max_list_r[i + 1]))
| import itertools
n = int(input())
a = [int(input()) for i in range(n)]
max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = ([0] + list(itertools.accumulate(reversed(a), func=max)))[::-1]
for i in range(n):
print(max(max_list[i], max_list_r[i + 1]))
| replace | 6 | 9 | 6 | 7 | 0 | |
p02971 | C++ | Runtime Error |
#include <bits/stdc++.h>
class kin {
public:
inline void open(FILE *, int);
inline void close(void);
inline void scan(void);
inline kin &operator>(char &);
inline kin &operator>(int &);
inline kin &operator>(long long &);
inline kin &operator>(double &);
inline kin &operator>(long double &);
inline kin &operator>(char *);
template <class T> inline void get(T *, int);
private:
FILE *fp;
char *buf;
int siz;
int idx;
} in;
class kout {
public:
inline void open(FILE *, int);
inline void close(void);
inline void print(void);
inline kout &operator<(char);
inline kout &operator<(int);
inline kout &operator<(long long);
inline kout &operator<(double);
inline kout &operator<(long double);
inline kout &operator<(const char *);
template <class T> inline void put(T *, int, char, char);
private:
FILE *fp;
char *buf;
int siz;
int idx;
} out;
int main(int argc, char **argv) {
in.open(stdin, 512);
out.open(stdout, 512);
in.scan();
int n;
in > n;
int ama[2] = {0, 0};
int a[100000];
for (int i = 0; i < n; ++i) {
in > a[i];
if (a[i] >= ama[0]) {
ama[1] = ama[0];
ama[0] = a[i];
} else if (a[i] >= ama[1])
ama[1] = a[i];
}
for (int i = 0; i < n; ++i)
out < (a[i] == ama[0] ? ama[1] : ama[0]) < '\n';
out.print();
in.close();
out.close();
return 0;
}
inline void kin::open(FILE *fparg, int sizarg) {
fp = fparg;
buf = new char[sizarg];
siz = sizarg;
idx = 0;
return;
}
inline void kin::close(void) {
fp = nullptr;
delete[] buf;
buf = nullptr;
siz = 0;
idx = 0;
return;
}
inline void kin::scan(void) {
int readsiz =
(int)std::fread((void *)buf, (std::size_t)1, (std::size_t)siz, fp);
if (readsiz != siz)
buf[readsiz] = '\x00';
idx = 0;
return;
}
inline kin &kin::operator>(char &var) {
if (!buf[idx]) {
var = '\x00';
return *this;
}
var = buf[idx];
if (++idx == siz)
scan();
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(int &var) {
if (!buf[idx]) {
var = 0;
return *this;
}
int sign = -1;
if (buf[idx] == '-') {
sign = 1;
if (++idx == siz)
scan();
}
var = 0;
while (buf[idx] >= '0') {
var = var * 10 - (int)(buf[idx] - '0');
if (++idx == siz)
scan();
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(long long &var) {
if (!buf[idx]) {
var = 0LL;
return *this;
}
long long sign = -1LL;
if (buf[idx] == '-') {
sign = 1LL;
if (++idx == siz)
scan();
};
var = 0LL;
while (buf[idx] >= '0') {
var = var * 10LL - (long long)(buf[idx] - '0');
if (++idx == siz)
scan();
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(double &var) {
if (!buf[idx]) {
var = 0.0;
return *this;
}
double sign = -1.0;
if (buf[idx] == '-') {
sign = 1.0;
if (++idx == siz)
scan();
}
var = 0.0;
while (buf[idx] >= '0') {
var = var * 10.0 - (double)(buf[idx] - '0');
if (++idx == siz)
scan();
}
if (buf[idx] == '.') {
if (++idx == siz)
scan();
double dig = 1.0;
while (buf[idx] >= '0') {
var -= (double)(buf[idx] - '0') * (dig /= 10.0);
if (++idx == siz)
scan();
}
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(long double &var) {
if (!buf[idx]) {
var = 0.0L;
return *this;
}
long double sign = -1.0L;
if (buf[idx] == '-') {
sign = 1.0L;
if (++idx == siz)
scan();
}
var = 0.0L;
while (buf[idx] >= '0') {
var = var * 10.0L - (long double)(buf[idx] - '0');
if (++idx == siz)
scan();
}
if (buf[idx] == '.') {
if (++idx == siz)
scan();
long double dig = 1.0L;
while (buf[idx] >= '0') {
var -= (long double)(buf[idx] - '0') * (dig /= 10.0L);
if (++idx == siz)
scan();
}
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(char *str) {
if (!buf[idx]) {
str[0] = '\x00';
return *this;
}
int ptr = 0;
while (buf[idx] >= '!') {
str[ptr++] = buf[idx];
if (++idx == siz)
scan();
}
str[ptr] = '\x00';
if (++idx == siz)
scan();
return *this;
}
template <class T> inline void kin::get(T *arr, int num) {
for (int i = 0; i < num; ++i)
(*this) > arr[i];
return;
}
inline void kout::open(FILE *fparg, int sizarg) {
fp = fparg;
buf = new char[sizarg];
siz = sizarg;
idx = 0;
return;
}
inline void kout::close(void) {
fp = nullptr;
delete[] buf;
buf = nullptr;
siz = 0;
idx = 0;
return;
}
inline void kout::print(void) {
std::fwrite((void *)buf, (std::size_t)1, (std::size_t)idx, fp);
idx = 0;
return;
}
inline kout &kout::operator<(char val) {
buf[idx] = val;
if (++idx == siz)
print();
return *this;
}
inline kout &kout::operator<(int val) {
if (val < 0) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1;
char dig[10];
int ptr = 0;
do {
int tmp = val / 10;
dig[ptr++] = (char)-(val - tmp * 10) + '0';
val = tmp;
} while (val);
while (ptr--) {
buf[idx] = dig[ptr];
if (++idx == siz)
print();
}
return *this;
}
inline kout &kout::operator<(long long val) {
if (val < 0LL) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1LL;
char dig[19];
int ptr = 0;
do {
long long tmp = val / 10LL;
dig[ptr++] = (char)-(val - tmp * 10LL) + '0';
val = tmp;
} while (val);
while (ptr--) {
buf[idx] = dig[ptr];
if (++idx == siz)
print();
}
return *this;
}
inline kout &kout::operator<(double val) {
if (val < 0.0) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1.0;
double dig = 1.0;
while (val / dig <= -10.0)
dig *= 10.0;
int tmp;
while (dig >= 1.0) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (double)tmp * dig;
dig /= 10.0;
}
buf[idx] = '.';
if (++idx == siz)
print();
for (int i = 0; i < 12; ++i) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (double)tmp * dig;
dig /= 10.0;
}
return *this;
}
inline kout &kout::operator<(long double val) {
if (val < 0.0L) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1.0L;
long double dig = 1.0L;
while (val / dig <= -10.0L)
dig *= 10.0L;
int tmp;
while (dig >= 1.0L) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (long double)tmp * dig;
dig /= 10.0L;
}
buf[idx] = '.';
if (++idx == siz)
print();
for (int i = 0; i < 16; ++i) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (long double)tmp * dig;
dig /= 10.0L;
}
return *this;
}
inline kout &kout::operator<(const char *str) {
for (int i = 0; str[i]; ++i) {
buf[idx] = str[i];
if (++idx == siz)
print();
}
return *this;
}
template <class T> inline void kout::put(T *arr, int num, char dlm, char end) {
--num;
for (int i = 0; i < num; ++i)
(*this) < arr[i] < dlm;
(*this) < arr[num] < end;
return;
}
|
#include <bits/stdc++.h>
class kin {
public:
inline void open(FILE *, int);
inline void close(void);
inline void scan(void);
inline kin &operator>(char &);
inline kin &operator>(int &);
inline kin &operator>(long long &);
inline kin &operator>(double &);
inline kin &operator>(long double &);
inline kin &operator>(char *);
template <class T> inline void get(T *, int);
private:
FILE *fp;
char *buf;
int siz;
int idx;
} in;
class kout {
public:
inline void open(FILE *, int);
inline void close(void);
inline void print(void);
inline kout &operator<(char);
inline kout &operator<(int);
inline kout &operator<(long long);
inline kout &operator<(double);
inline kout &operator<(long double);
inline kout &operator<(const char *);
template <class T> inline void put(T *, int, char, char);
private:
FILE *fp;
char *buf;
int siz;
int idx;
} out;
int main(int argc, char **argv) {
in.open(stdin, 512);
out.open(stdout, 512);
in.scan();
int n;
in > n;
int ama[2] = {0, 0};
int a[200000];
for (int i = 0; i < n; ++i) {
in > a[i];
if (a[i] >= ama[0]) {
ama[1] = ama[0];
ama[0] = a[i];
} else if (a[i] >= ama[1])
ama[1] = a[i];
}
for (int i = 0; i < n; ++i)
out < (a[i] == ama[0] ? ama[1] : ama[0]) < '\n';
out.print();
in.close();
out.close();
return 0;
}
inline void kin::open(FILE *fparg, int sizarg) {
fp = fparg;
buf = new char[sizarg];
siz = sizarg;
idx = 0;
return;
}
inline void kin::close(void) {
fp = nullptr;
delete[] buf;
buf = nullptr;
siz = 0;
idx = 0;
return;
}
inline void kin::scan(void) {
int readsiz =
(int)std::fread((void *)buf, (std::size_t)1, (std::size_t)siz, fp);
if (readsiz != siz)
buf[readsiz] = '\x00';
idx = 0;
return;
}
inline kin &kin::operator>(char &var) {
if (!buf[idx]) {
var = '\x00';
return *this;
}
var = buf[idx];
if (++idx == siz)
scan();
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(int &var) {
if (!buf[idx]) {
var = 0;
return *this;
}
int sign = -1;
if (buf[idx] == '-') {
sign = 1;
if (++idx == siz)
scan();
}
var = 0;
while (buf[idx] >= '0') {
var = var * 10 - (int)(buf[idx] - '0');
if (++idx == siz)
scan();
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(long long &var) {
if (!buf[idx]) {
var = 0LL;
return *this;
}
long long sign = -1LL;
if (buf[idx] == '-') {
sign = 1LL;
if (++idx == siz)
scan();
};
var = 0LL;
while (buf[idx] >= '0') {
var = var * 10LL - (long long)(buf[idx] - '0');
if (++idx == siz)
scan();
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(double &var) {
if (!buf[idx]) {
var = 0.0;
return *this;
}
double sign = -1.0;
if (buf[idx] == '-') {
sign = 1.0;
if (++idx == siz)
scan();
}
var = 0.0;
while (buf[idx] >= '0') {
var = var * 10.0 - (double)(buf[idx] - '0');
if (++idx == siz)
scan();
}
if (buf[idx] == '.') {
if (++idx == siz)
scan();
double dig = 1.0;
while (buf[idx] >= '0') {
var -= (double)(buf[idx] - '0') * (dig /= 10.0);
if (++idx == siz)
scan();
}
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(long double &var) {
if (!buf[idx]) {
var = 0.0L;
return *this;
}
long double sign = -1.0L;
if (buf[idx] == '-') {
sign = 1.0L;
if (++idx == siz)
scan();
}
var = 0.0L;
while (buf[idx] >= '0') {
var = var * 10.0L - (long double)(buf[idx] - '0');
if (++idx == siz)
scan();
}
if (buf[idx] == '.') {
if (++idx == siz)
scan();
long double dig = 1.0L;
while (buf[idx] >= '0') {
var -= (long double)(buf[idx] - '0') * (dig /= 10.0L);
if (++idx == siz)
scan();
}
}
var *= sign;
if (++idx == siz)
scan();
return *this;
}
inline kin &kin::operator>(char *str) {
if (!buf[idx]) {
str[0] = '\x00';
return *this;
}
int ptr = 0;
while (buf[idx] >= '!') {
str[ptr++] = buf[idx];
if (++idx == siz)
scan();
}
str[ptr] = '\x00';
if (++idx == siz)
scan();
return *this;
}
template <class T> inline void kin::get(T *arr, int num) {
for (int i = 0; i < num; ++i)
(*this) > arr[i];
return;
}
inline void kout::open(FILE *fparg, int sizarg) {
fp = fparg;
buf = new char[sizarg];
siz = sizarg;
idx = 0;
return;
}
inline void kout::close(void) {
fp = nullptr;
delete[] buf;
buf = nullptr;
siz = 0;
idx = 0;
return;
}
inline void kout::print(void) {
std::fwrite((void *)buf, (std::size_t)1, (std::size_t)idx, fp);
idx = 0;
return;
}
inline kout &kout::operator<(char val) {
buf[idx] = val;
if (++idx == siz)
print();
return *this;
}
inline kout &kout::operator<(int val) {
if (val < 0) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1;
char dig[10];
int ptr = 0;
do {
int tmp = val / 10;
dig[ptr++] = (char)-(val - tmp * 10) + '0';
val = tmp;
} while (val);
while (ptr--) {
buf[idx] = dig[ptr];
if (++idx == siz)
print();
}
return *this;
}
inline kout &kout::operator<(long long val) {
if (val < 0LL) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1LL;
char dig[19];
int ptr = 0;
do {
long long tmp = val / 10LL;
dig[ptr++] = (char)-(val - tmp * 10LL) + '0';
val = tmp;
} while (val);
while (ptr--) {
buf[idx] = dig[ptr];
if (++idx == siz)
print();
}
return *this;
}
inline kout &kout::operator<(double val) {
if (val < 0.0) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1.0;
double dig = 1.0;
while (val / dig <= -10.0)
dig *= 10.0;
int tmp;
while (dig >= 1.0) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (double)tmp * dig;
dig /= 10.0;
}
buf[idx] = '.';
if (++idx == siz)
print();
for (int i = 0; i < 12; ++i) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (double)tmp * dig;
dig /= 10.0;
}
return *this;
}
inline kout &kout::operator<(long double val) {
if (val < 0.0L) {
buf[idx] = '-';
if (++idx == siz)
print();
} else
val *= -1.0L;
long double dig = 1.0L;
while (val / dig <= -10.0L)
dig *= 10.0L;
int tmp;
while (dig >= 1.0L) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (long double)tmp * dig;
dig /= 10.0L;
}
buf[idx] = '.';
if (++idx == siz)
print();
for (int i = 0; i < 16; ++i) {
buf[idx] = (char)-(tmp = (int)(val / dig)) + '0';
if (++idx == siz)
print();
val -= (long double)tmp * dig;
dig /= 10.0L;
}
return *this;
}
inline kout &kout::operator<(const char *str) {
for (int i = 0; str[i]; ++i) {
buf[idx] = str[i];
if (++idx == siz)
print();
}
return *this;
}
template <class T> inline void kout::put(T *arr, int num, char dlm, char end) {
--num;
for (int i = 0; i < num; ++i)
(*this) < arr[i] < dlm;
(*this) < arr[num] < end;
return;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p02971 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
int main() {
ll N;
cin >> N;
vector<ll> A(N);
vector<ll> B(N);
REP(i, N) {
cin >> A[i];
B[i] = A[i];
}
sort(A.begin(), A.end());
REP(i, N) {
sort(A.begin(), A.end());
if (A[N - 1] == B[i]) {
cout << A[N - 2] << endl;
} else {
cout << A[N - 1] << endl;
}
}
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
int main() {
ll N;
cin >> N;
vector<ll> A(N);
vector<ll> B(N);
REP(i, N) {
cin >> A[i];
B[i] = A[i];
}
sort(A.begin(), A.end());
REP(i, N) {
if (A[N - 1] == B[i]) {
cout << A[N - 2] << endl;
} else {
cout << A[N - 1] << endl;
}
}
} | delete | 42 | 43 | 42 | 42 | TLE | |
p02971 | C++ | Runtime Error | /*
lakshaygpt28
Lakshay Gupta
*/
#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;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = vector<ll>;
template <typename T>
using OrderedSet =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using MinPriorityQueue = priority_queue<T, vector<T>, greater<T>>;
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std ::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define fast_io() \
ios_base ::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;
ll a[N];
multiset<ll> s;
int main() {
fast_io();
ll n;
cin >> n;
for (ll i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (ll i = 0; i < n; i++) {
s.erase(s.find(a[i]));
cout << *s.rbegin() << "\n";
s.insert(a[i]);
}
return 0;
}
| /*
lakshaygpt28
Lakshay Gupta
*/
#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;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = vector<ll>;
template <typename T>
using OrderedSet =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using MinPriorityQueue = priority_queue<T, vector<T>, greater<T>>;
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std ::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define fast_io() \
ios_base ::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 2e5 + 10;
ll a[N];
multiset<ll> s;
int main() {
fast_io();
ll n;
cin >> n;
for (ll i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (ll i = 0; i < n; i++) {
s.erase(s.find(a[i]));
cout << *s.rbegin() << "\n";
s.insert(a[i]);
}
return 0;
}
| replace | 51 | 52 | 51 | 52 | 0 | |
p02971 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int i, ans = 0, n, j, x, max;
int kari = 0;
vector<int> a;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
max = *max_element(a.begin(), a.end());
for (i = 0; i < n; i++) {
if (a[i] == max) {
for (j = 0; j < n; j++) {
if (i != j and kari < a[j]) {
kari = a[j];
}
}
cout << kari << "\n";
kari = 0;
} else
cout << max << "\n";
}
}
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int i, ans = 0, n, j, x, max;
int kari = 0;
vector<int> a;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
max = *max_element(a.begin(), a.end());
for (i = 0; i < n; i++) {
if (a[i] == max) {
for (j = 0; j < n; j++) {
if (i != j and kari < a[j]) {
kari = a[j];
if (kari == max)
break;
}
}
cout << kari << "\n";
kari = 0;
} else
cout << max << "\n";
}
}
| insert | 27 | 27 | 27 | 29 | TLE | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
int main() {
int n, a[MAX_N], f, s;
cin >> n;
REP(i, n) {
cin >> a[i];
if (f < a[i]) {
s = f;
f = a[i];
} else if (s < a[i]) {
s = a[i];
}
}
REP(i, n) {
if (a[i] < f) {
cout << f << endl;
} else {
cout << s << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
int main() {
int n, a[MAX_N], f, s;
cin >> n;
REP(i, n) {
cin >> a[i];
if (f < a[i]) {
s = f;
f = a[i];
} else if (s < a[i]) {
s = a[i];
}
}
REP(i, n) {
if (a[i] < f) {
cout << f << endl;
} else {
cout << s << endl;
}
}
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02971 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;
int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int tmp[SIZE], a[SIZE];
for (int i = 0; i < n; ++i) {
cin >> a[i];
tmp[i] = a[i];
}
sort(tmp, tmp + n, greater<>());
int tmx = tmp[1];
int mx = tmp[0];
for (int i = 0; i < n; ++i) {
if (a[i] == mx)
cout << tmx;
else
cout << mx;
cout << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;
int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int tmp[SIZE], a[SIZE];
for (int i = 0; i < n; ++i) {
cin >> a[i];
tmp[i] = a[i];
}
sort(tmp, tmp + n, greater<>());
int tmx = tmp[1];
int mx = tmp[0];
for (int i = 0; i < n; ++i) {
if (a[i] == mx)
cout << tmx;
else
cout << mx;
cout << endl;
}
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02971 | Python | Time Limit Exceeded | # -*- coding: utf-8 -*-
n = int(input())
a = list()
for i in range(n):
a.append(int(input()))
a_sorted = sorted(a, reverse=True)
for i in range(n):
index = a_sorted.index(a[i])
if a[i] == a_sorted[0]:
print(a_sorted[1])
continue
print(a_sorted[0])
| # -*- coding: utf-8 -*-
n = int(input())
a = list()
for i in range(n):
a.append(int(input()))
a_sorted = sorted(a, reverse=True)
for i in range(n):
if a[i] == a_sorted[0]:
print(a_sorted[1])
continue
print(a_sorted[0])
| delete | 11 | 12 | 11 | 11 | TLE | |
p02971 | Python | Time Limit Exceeded | n = int(input())
a = []
for i in range(n):
a.append(int(input()))
k = max(a)
for i in range(n):
if a[i] < k:
print(k)
else:
tmp = a[i]
a[i] = 0
print(max(a))
a[i] = tmp
| n = int(input())
a = []
for i in range(n):
a.append(int(input()))
bl = [0 for i in range(n)]
bl[0] = a[0]
br = [0 for i in range(n)]
br[0] = a[n - 1]
for i in range(1, n):
bl[i] = max(bl[i - 1], a[i])
a.reverse()
for i in range(1, n):
br[i] = max(br[i - 1], a[i])
br.reverse()
print(br[1])
for i in range(1, n - 1):
print(max(bl[i - 1], br[i + 1]))
print(bl[n - 2])
| replace | 4 | 13 | 4 | 18 | TLE | |
p02971 | Python | Time Limit Exceeded | n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
sa = sorted(a)
for i in range(n):
val = a[i]
idx = sa.index(val)
sa.pop(idx)
print(sa[-1])
sa.insert(idx, val)
| n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
sa = sorted(a)
mx = sa[-1]
for val in a:
if val != mx:
print(sa[-1])
else:
print(sa[-2])
| replace | 6 | 12 | 6 | 12 | TLE | |
p02971 | Python | Time Limit Exceeded | N = int(input())
A = [int(input()) for i in range(N)]
for j in range(N):
p = A.pop(j)
print(max(A))
A.insert(j, p)
| N = int(input())
A = [int(input()) for i in range(N)]
max1 = [A.index(max(A)), max(A)]
p = A.pop(A.index(max(A)))
max2 = max(A)
ans = [max2 if j == max1[0] else max1[1] for j in range(N)]
for k in range(N):
print(ans[k])
| replace | 3 | 7 | 3 | 9 | TLE | |
p02971 | Python | Time Limit Exceeded | N = int(input())
A = [int(input()) for i in range(N)]
# maxA = max(A)
for x in range(len(A)):
a_tmp = A[x]
A[x] = 0
print(max(A))
A[x] = a_tmp
| N = int(input())
A = [int(input()) for i in range(N)]
maxA = max(A)
copy_A = A[:]
copy_A.remove(maxA)
secondA = max(copy_A)
for x in A:
if x == maxA:
print(secondA)
else:
print(maxA)
| replace | 2 | 8 | 2 | 11 | TLE | |
p02971 | Python | Time Limit Exceeded | import copy
N = int(input())
A = []
for i in range(N):
A.append(int(input()))
chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)
for i in range(N):
if i == A.index(max(A)):
print(chinchin)
else:
print(chinpo)
| import copy
N = int(input())
A = []
for i in range(N):
A.append(int(input()))
chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)
for i in range(A.index(max(A))):
print(chinpo)
print(chinchin)
for i in range(A.index(max(A)) + 1, N):
print(chinpo)
| replace | 12 | 17 | 12 | 17 | TLE | |
p02971 | Python | Time Limit Exceeded | n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
for _ in range(n):
val = a.pop(0)
print(max(a))
a.append(val)
| n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
desc = sorted(list(set(a)), reverse=True)
max = desc[0]
large_2 = desc[1] if len(desc) > 1 else 0
if a.count(max) == 1:
for val in a:
if val == max:
print(large_2)
else:
print(max)
else:
for _ in range(n):
print(max)
| replace | 5 | 9 | 5 | 18 | TLE | |
p02971 | Python | Runtime Error | from heapq import heappush, heappop
N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
heappush(hq, -A[i])
max1 = -heappop(hq)
while True:
max2 = -heappop(hq)
if max2 != max1:
break
ans = [0] * N
for i in range(N):
if A[i] == max1:
ans[i] = max2
else:
ans[i] = max1
print(*ans, sep="\n")
| from heapq import heappush, heappop
N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
heappush(hq, -A[i])
max1 = -heappop(hq)
max2 = -heappop(hq)
ans = [0] * N
for i in range(N):
if A[i] == max1:
ans[i] = max2
else:
ans[i] = max1
print(*ans, sep="\n")
| replace | 8 | 12 | 8 | 9 | 0 | |
p02971 | Python | Time Limit Exceeded | #!/usr/bin/env python3
def main():
N = int(input())
As = [int(input()) for _ in range(N)]
for i in range(N):
tmp = As[:]
tmp.pop(i)
print(max(tmp))
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
def main():
N = int(input())
As = [int(input()) for _ in range(N)]
max1 = max(As)
max_idx = As.index(max1)
As.remove(max1)
max2 = max(As)
max_list = [max1] * N
max_list[max_idx] = max2
for m in max_list:
print(m)
if __name__ == "__main__":
main()
| replace | 6 | 10 | 6 | 14 | TLE | |
p02971 | Python | Time Limit Exceeded | N = int(input())
a = []
for _ in range(N):
a.append(int(input()))
tmp = 0
idx = 0
while idx < N:
tmp, a[idx] = a[idx], tmp
print(max(a))
tmp, a[idx] = a[idx], tmp
idx += 1
| N = int(input())
a = []
for _ in range(N):
a.append(int(input()))
a_sorted = sorted(a)
max_a = a_sorted.pop()
second_a = a_sorted.pop()
if max_a == second_a:
for _ in range(N):
print(max_a)
else:
idx = 0
while idx < N:
if a[idx] == max_a:
print(second_a)
else:
print(max_a)
idx += 1
| replace | 4 | 11 | 4 | 18 | TLE | |
p02971 | Python | Time Limit Exceeded | N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
temp = A[:i] + A[i + 1 :]
print(max(temp))
| N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A)
[print(sorted_A[-2] if sorted_A[-1] == A[i] else sorted_A[-1]) for i in range(N)]
| replace | 2 | 6 | 2 | 4 | TLE | |
p02971 | Python | Runtime Error | def main():
N = int(input())
A = [int(input()) for _ in range(N)]
max_value = max(A)
max_index = A.index(max_value)
for i in range(N):
if i != max_index:
print(max_value)
else:
if i == 0:
print(max(A[1:]))
elif i == N:
print(max(A[:N]))
else:
print(max(max(A[:i]), max(A[i + 1 :])))
return
if __name__ == "__main__":
main()
| def main():
N = int(input())
A = [int(input()) for _ in range(N)]
max_value = max(A)
max_index = A.index(max_value)
for i in range(N):
if i != max_index:
print(max_value)
else:
if i == 0:
print(max(A[1:]))
elif i == N - 1:
print(max(A[: N - 1]))
else:
print(max(max(A[:i]), max(A[i + 1 :])))
return
if __name__ == "__main__":
main()
| replace | 13 | 15 | 13 | 15 | 0 | |
p02972 | C++ | Memory Limit Exceeded | #include <iostream>
using namespace std;
long long head[200001];
long long save[200001][1000];
int main() {
long long N;
long long a[200001];
long long b[200001];
long long size = 0;
cin >> N;
for (int i = 1; i <= N; i++)
cin >> a[i];
for (int i = 1; i <= N; i++) {
for (int j = 2; i * j <= N; j++) {
save[i * j][head[i * j]] = i;
head[i * j]++;
}
}
for (int i = N; i >= 1; i--) {
b[i] = a[i];
if (b[i] == 1)
size++;
for (int jh = 0; jh < head[i]; jh++) {
a[save[i][jh]] ^= b[i];
}
}
cout << size << endl;
for (int i = 1; i <= N; i++) {
if (b[i] == 1) {
cout << i;
size--;
if (size > 0)
cout << " ";
else
cout << endl;
}
}
return 0;
}
| #include <iostream>
using namespace std;
int head[200001];
int save[200001][200];
int main() {
long long N;
long long a[200001];
long long b[200001];
long long size = 0;
cin >> N;
for (int i = 1; i <= N; i++)
cin >> a[i];
for (int i = 1; i <= N; i++) {
for (int j = 2; i * j <= N; j++) {
save[i * j][head[i * j]] = i;
head[i * j]++;
}
}
for (int i = N; i >= 1; i--) {
b[i] = a[i];
if (b[i] == 1)
size++;
for (int jh = 0; jh < head[i]; jh++) {
a[save[i][jh]] ^= b[i];
}
}
cout << size << endl;
for (int i = 1; i <= N; i++) {
if (b[i] == 1) {
cout << i;
size--;
if (size > 0)
cout << " ";
else
cout << endl;
}
}
return 0;
}
| replace | 3 | 5 | 3 | 5 | MLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<ll>>;
int main() {
int N;
cin >> N;
vector<int> A(N + 1);
rep1(i, N) cin >> A.at(i);
int M = 0;
vector<int> B(N + 1, 0);
for (int i = N; i >= 1; i--) {
int tmp = 0;
for (int j = 2 * i; i * j <= N; j++) {
tmp += B.at(j);
}
if (tmp % 2 != A.at(i)) {
B.at(i)++;
M++;
}
}
cout << M << endl;
rep1(i, N) if (B.at(i)) cout << i << " ";
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<ll>>;
int main() {
int N;
cin >> N;
vector<int> A(N + 1);
rep1(i, N) cin >> A.at(i);
int M = 0;
vector<int> B(N + 1, 0);
for (int i = N; i >= 1; i--) {
int tmp = 0;
for (int j = 2; i * j <= N; j++) {
tmp += B.at(j * i);
}
if (tmp % 2 != A.at(i)) {
B.at(i)++;
M++;
}
}
cout << M << endl;
rep1(i, N) if (B.at(i)) cout << i << " ";
cout << endl;
} | replace | 19 | 21 | 19 | 21 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
#define ll long long
int main() {
ll N, M = 0;
ll i, j;
ll tmp;
cin >> N;
ll a[N + 1], b[N + 1];
for (i = 1; i <= N; i++) {
cin >> a[i];
b[i] = 0;
}
for (i = N; i > 0; i--) {
tmp = 0;
j = i;
while (tmp <= N) {
tmp = (tmp + b[j]) % 2;
j += i;
}
b[i] = (tmp + a[i]) % 2;
if (b[i] == 1)
M++;
}
cout << M << endl;
for (i = 1; i <= N; i++) {
if (b[i] == 1)
cout << i << " ";
}
return 0;
} | #include <iostream>
using namespace std;
#define ll long long
int main() {
ll N, M = 0;
ll i, j;
ll tmp;
cin >> N;
ll a[N + 1], b[N + 1];
for (i = 1; i <= N; i++) {
cin >> a[i];
b[i] = 0;
}
for (i = N; i > 0; i--) {
tmp = 0;
j = i;
while (j <= N) {
tmp = (tmp + b[j]) % 2;
j += i;
}
b[i] = (tmp + a[i]) % 2;
if (b[i] == 1)
M++;
}
cout << M << endl;
for (i = 1; i <= N; i++) {
if (b[i] == 1)
cout << i << " ";
}
return 0;
} | replace | 16 | 17 | 16 | 17 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// DAME:
int main() {
ll n;
cin >> n;
vector<int> a(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> ans(n + 1);
for (ll i = n; i >= 1; i--) {
ll tmp = i;
int sum = 0;
while (tmp <= n) {
tmp += i;
sum += ans[tmp];
}
if (sum % 2 != a[i]) {
ans[i] = 1;
}
}
int size = 0;
for (ll i = 1; i <= n; i++) {
if (ans[i]) {
size++;
}
}
cout << size << endl;
for (ll i = 1; i <= n; i++) {
if (ans[i]) {
cout << i << ' ';
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// DAME:
int main() {
ll n;
cin >> n;
vector<int> a(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> ans(n + 1);
for (ll i = n; i >= 1; i--) {
ll tmp = i;
int sum = 0;
while (tmp + i <= n) {
tmp += i;
sum += ans[tmp];
}
if (sum % 2 != a[i]) {
ans[i] = 1;
}
}
int size = 0;
for (ll i = 1; i <= n; i++) {
if (ans[i]) {
size++;
}
}
cout << size << endl;
for (ll i = 1; i <= n; i++) {
if (ans[i]) {
cout << i << ' ';
}
}
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
int main() {
int N;
cin >> N;
vector<int> a(N + 1);
rep(i, 1, N + 1) cin >> a[i];
vector<int> ans(N + 1);
rem(i, N, 0) if (a[i]) {
ans[i] = 1;
rep(j, 1, i) if (i % j == 0) a[j] ^= 1;
}
int cnt = 0;
rep(i, 1, N + 1) if (ans[i]) cnt++;
cout << cnt << endl;
rep(i, 1, N + 1) if (ans[i]) cout << i << " ";
if (cnt)
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
int main() {
int N;
cin >> N;
vector<int> a(N + 1);
rep(i, 1, N + 1) cin >> a[i];
vector<int> ans(N + 1);
rem(i, N, 0) {
ans[i] = a[i];
for (int j = 2 * i; j <= N; j += i) {
ans[i] ^= ans[j];
}
}
int cnt = 0;
rep(i, 1, N + 1) if (ans[i]) cnt++;
cout << cnt << endl;
rep(i, 1, N + 1) if (ans[i]) cout << i << " ";
if (cnt)
cout << endl;
return 0;
}
| replace | 11 | 14 | 11 | 16 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
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;
}
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 1; i <= n; i++)
cin >> v[i];
vector<int> ans(n + 1);
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = i; j <= n; j += i) {
sum += ans[j];
}
if (sum % 2 != v[i])
ans[i]++;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += ans[i];
cout << cnt << endl;
for (int i = 1; i <= n; i++) {
if (ans[i] == 1)
cout << i << " ";
}
cout << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
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;
}
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
vector<int> ans(n + 1);
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = i; j <= n; j += i) {
sum += ans[j];
}
if (sum % 2 != v[i])
ans[i]++;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += ans[i];
cout << cnt << endl;
for (int i = 1; i <= n; i++) {
if (ans[i] == 1)
cout << i << " ";
}
cout << endl;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
// max=({});
// 条件式が真ならwhileの中身を回し続ける
// printf("%d\n", ans);
// pairの入力
// vector<pair<ll, ll>>work(n);
// rep(i, n) {
// ll a, b;
// cin >> a >> b;
// work[i] = make_pair(a, b);
// for(auto p:mp)(mapの探索)
// printf("%.10f\n",なんちゃら)
// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)
return 0;
return (x / gcd(x, y) * y);
}
// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};
ll dp[101010];
// union-find木について
ll par[101010];
ll rank2[101010];
void init(ll n) {
rep(i, n) {
par[i] = i;
rank2[i] = 0;
}
}
ll find(ll x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank2[x] < rank2[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank2[x] == rank2[y]) {
rank2[x]++;
}
}
}
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;
}
// long longしか使わない
// 素数は1より大きい
int main() {
ll n;
cin >> n;
vector<ll> a(n + 1);
vector<ll> box(n + 1);
for (ll i = 1; i <= n; ++i) {
cin >> a[i];
}
ll ans = 0;
for (ll i = n; i >= 1; --i) {
ll target = i;
ll count = 0;
while (target <= n) {
count += box[target];
}
count %= 2;
if (a[i] != count) {
box[i]++;
ans++;
}
}
cout << ans << endl;
rep(i, n + 1) {
if (box[i]) {
cout << i << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
// max=({});
// 条件式が真ならwhileの中身を回し続ける
// printf("%d\n", ans);
// pairの入力
// vector<pair<ll, ll>>work(n);
// rep(i, n) {
// ll a, b;
// cin >> a >> b;
// work[i] = make_pair(a, b);
// for(auto p:mp)(mapの探索)
// printf("%.10f\n",なんちゃら)
// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)
return 0;
return (x / gcd(x, y) * y);
}
// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};
ll dp[101010];
// union-find木について
ll par[101010];
ll rank2[101010];
void init(ll n) {
rep(i, n) {
par[i] = i;
rank2[i] = 0;
}
}
ll find(ll x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank2[x] < rank2[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank2[x] == rank2[y]) {
rank2[x]++;
}
}
}
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;
}
// long longしか使わない
// 素数は1より大きい
int main() {
ll n;
cin >> n;
vector<ll> a(n + 1);
vector<ll> box(n + 1);
for (ll i = 1; i <= n; ++i) {
cin >> a[i];
}
ll ans = 0;
for (ll i = n; i >= 1; --i) {
ll target = i;
ll count = 0;
ll j = 1;
while (target * j <= n) {
count += box[target * j];
j++;
}
count %= 2;
if (a[i] != count) {
box[i]++;
ans++;
}
}
cout << ans << endl;
rep(i, n + 1) {
if (box[i]) {
cout << i << endl;
}
}
return 0;
}
| replace | 125 | 127 | 125 | 129 | TLE | |
p02972 | C++ | Runtime Error | #define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N + 1), b(N + 1, 0);
for (int i = 1; i <= N; i++)
cin >> a[i];
int cnt = 0;
vector<int> ans;
for (int i = N; i >= 1; i--) {
// ballの個数を数える
int ball = 0;
int now = 2 * i;
while (now <= N) {
ball += b[now];
now += i;
}
// 偶奇が違ったら追加
if (ball % 2 != a[i]) {
b[i] = 1;
cnt++;
ans.push_back(i);
}
}
cout << cnt << endl;
for (int i = 0; i < b.size(); i++)
cout << ans[i] << " ";
}
| #define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N + 1), b(N + 1, 0);
for (int i = 1; i <= N; i++)
cin >> a[i];
int cnt = 0;
vector<int> ans;
for (int i = N; i >= 1; i--) {
// ballの個数を数える
int ball = 0;
int now = 2 * i;
while (now <= N) {
ball += b[now];
now += i;
}
// 偶奇が違ったら追加
if (ball % 2 != a[i]) {
b[i] = 1;
cnt++;
ans.push_back(i);
}
}
cout << cnt << endl;
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " ";
}
| replace | 44 | 45 | 44 | 45 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
rep(i, n) cin >> a[i + 1];
vector<int> b(n + 1);
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = i + i; j <= n; j += i) {
sum ^= b[j];
}
b[i] = sum ^ a[i];
}
vector<int> ans;
for (int i = 1; i <= n; i++) {
if (b[i])
ans.push_back(i);
}
cout << ans.size() << endl;
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
rep(i, n) cin >> a[i + 1];
vector<int> b(n + 1);
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = i + i; j <= n; j += i) {
sum ^= b[j];
}
b[i] = sum ^ a[i];
}
vector<int> ans;
for (int i = 1; i <= n; i++) {
if (b[i])
ans.push_back(i);
}
cout << ans.size() << endl;
rep(i, ans.size()) cout << ans[i] << endl;
} | replace | 24 | 27 | 24 | 25 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int a[N + 1];
int b[N + 1];
int ans[N + 1];
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = N; i >= 1; i--) {
int cnt = 0;
for (int j = i + 1; j <= N; j++) {
if (j % i == 0) {
if (b[j] == 1)
cnt++;
}
}
if (a[i] == 1) {
if (cnt % 2 == 0) {
b[i] = 1;
} else {
b[i] = 0;
}
} else {
if (cnt % 2 == 1) {
b[i] = 1;
} else {
b[i] = 0;
}
}
}
int m = 0;
for (int i = 1; i <= N; i++) {
if (b[i] == 1) {
m++;
}
}
cout << m << endl;
for (int i = 1; i <= N; i++) {
if (b[i] == 1) {
cout << i << ' ';
}
}
cout << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int a[N + 1];
int b[N + 1];
int ans[N + 1];
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = N; i >= 1; i--) {
int cnt = 0;
for (int j = i + i; j <= N; j += i) {
if (j % i == 0) {
if (b[j] == 1)
cnt++;
}
}
if (a[i] == 1) {
if (cnt % 2 == 0) {
b[i] = 1;
} else {
b[i] = 0;
}
} else {
if (cnt % 2 == 1) {
b[i] = 1;
} else {
b[i] = 0;
}
}
}
int m = 0;
for (int i = 1; i <= N; i++) {
if (b[i] == 1) {
m++;
}
}
cout << m << endl;
for (int i = 1; i <= N; i++) {
if (b[i] == 1) {
cout << i << ' ';
}
}
cout << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin()) // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) { return x == 0 ? 1 : log10(x) + 1; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
signed main() {
ll N;
cin >> N;
vector<ll> A;
A.pb(0);
rep(i, N) {
ll a;
cin >> a;
A.pb(a);
}
vector<ll> ans(N);
repr(i, N) {
ll sum = 0;
// debug(i);
if (i == 0) {
continue;
}
rep(j, N / i) {
// debug(j);
ll index = j + 1;
if (j == 0) {
sum += A[i];
} else {
sum += ans[i * index];
}
}
// debug(sum);
ans[i] = sum % 2;
}
ll count = 0;
vector<ll> outputs;
rep(i, N + 1) {
if (i == 0) {
continue;
}
if (ans[i] == 1) {
count++;
outputs.pb(i);
}
}
COUT(count);
rep(i, outputs.size()) {
if (i == 0) {
cout << outputs[i];
} else {
cout << " " << outputs[i];
}
}
if (count != 0) {
ENDL;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin()) // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) { return x == 0 ? 1 : log10(x) + 1; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
signed main() {
ll N;
cin >> N;
vector<ll> A;
A.pb(0);
rep(i, N) {
ll a;
cin >> a;
A.pb(a);
}
vector<ll> ans(N + 1);
repr(i, N) {
ll sum = 0;
// debug(i);
if (i == 0) {
continue;
}
rep(j, N / i) {
// debug(j);
ll index = j + 1;
if (j == 0) {
sum += A[i];
} else {
sum += ans[i * index];
}
}
// debug(sum);
ans[i] = sum % 2;
}
ll count = 0;
vector<ll> outputs;
rep(i, N + 1) {
if (i == 0) {
continue;
}
if (ans[i] == 1) {
count++;
outputs.pb(i);
}
}
COUT(count);
rep(i, outputs.size()) {
if (i == 0) {
cout << outputs[i];
} else {
cout << " " << outputs[i];
}
}
if (count != 0) {
ENDL;
}
return 0;
} | replace | 58 | 59 | 58 | 59 | -6 | free(): invalid pointer
|
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T> using uset = unordered_set<T>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return (a > b && (a = b, true));
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return (a < b && (a = b, true));
}
template <typename T> vector<T> makeVector(size_t a, T b) {
return (vector<T>(a, b));
}
template <typename... Ts> auto makeVector(size_t a, Ts... ts) {
return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}
template <typename T> bool isin(T y, T x, T h, T w) {
return (0 <= y && 0 <= x && y < h && x < w);
}
template <typename T> bool isin1(T y, T x, T h, T w) {
return (0 < y && 0 < x && y <= h && x <= w);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
os << v[0];
for (int i = 1; i < v.size(); i++)
os << " " << v[i];
return (os);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &u : v)
is >> u;
return (is);
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return (is >> p.first >> p.second);
}
void Main() {
int N;
cin >> N;
vint A(N + 1);
for (int i = 1; i <= N; i++)
cin >> A[i];
vector<bool> used(N + 1, false);
for (int i = N; i > 0; i--) {
int cnt = 0;
for (int j = i + i; j <= N; j += i) {
if (used[j])
cnt++;
}
if ((cnt + A[i]) % 2 == 1) {
used[i] = true;
}
}
vint ans;
for (int i = 1; i <= N; i++) {
if (used[i])
ans.push_back(i);
}
cout << ans.size() << endl;
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
Main();
return (0);
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T> using uset = unordered_set<T>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return (a > b && (a = b, true));
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return (a < b && (a = b, true));
}
template <typename T> vector<T> makeVector(size_t a, T b) {
return (vector<T>(a, b));
}
template <typename... Ts> auto makeVector(size_t a, Ts... ts) {
return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}
template <typename T> bool isin(T y, T x, T h, T w) {
return (0 <= y && 0 <= x && y < h && x < w);
}
template <typename T> bool isin1(T y, T x, T h, T w) {
return (0 < y && 0 < x && y <= h && x <= w);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
if (v.size() == 0)
return (os);
os << v[0];
for (int i = 1; i < v.size(); i++)
os << " " << v[i];
return (os);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &u : v)
is >> u;
return (is);
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return (is >> p.first >> p.second);
}
void Main() {
int N;
cin >> N;
vint A(N + 1);
for (int i = 1; i <= N; i++)
cin >> A[i];
vector<bool> used(N + 1, false);
for (int i = N; i > 0; i--) {
int cnt = 0;
for (int j = i + i; j <= N; j += i) {
if (used[j])
cnt++;
}
if ((cnt + A[i]) % 2 == 1) {
used[i] = true;
}
}
vint ans;
for (int i = 1; i <= N; i++) {
if (used[i])
ans.push_back(i);
}
cout << ans.size() << endl;
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
Main();
return (0);
} | insert | 52 | 52 | 52 | 54 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
vector<int> out;
for (int i = n; i > 0; --i) {
for (int j = 2 * i; j <= n; j += i)
a[i] ^= a[j];
if (a[i])
out.push_back(i);
}
printf("%d\n", (int)out.size());
reverse(out.begin(), out.end());
for (int i : out)
printf("%d ", i);
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
vector<int> out;
for (int i = n; i > 0; --i) {
for (int j = 2 * i; j <= n; j += i)
a[i] ^= a[j];
if (a[i])
out.push_back(i);
}
printf("%d\n", (int)out.size());
reverse(out.begin(), out.end());
for (int i : out)
printf("%d ", i);
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
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 true;
} else {
return false;
}
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else {
return false;
}
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int a[20005];
int b[20005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int j;
for (int i = n; i * 2 > n; i--) {
if (a[i] == 0) {
b[i] = 0;
} else {
b[i] = 1;
}
j = i;
}
for (int k = j - 1; k > 0; k--) {
int sum = 0;
for (int m = 2; k * m <= n; m++) {
sum += b[k * m];
}
if (a[k] == 1) {
if (sum % 2 == 0)
b[k] = 1;
else
b[k] = 0;
} else {
if (sum % 2 == 0)
b[k] = 0;
else
b[k] = 1;
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (b[i] == 1)
cnt++;
}
cout << cnt << endl;
for (int i = 1; i <= n; i++) {
if (b[i] == 1)
cout << i << endl;
}
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
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 true;
} else {
return false;
}
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else {
return false;
}
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int a[200005];
int b[200005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int j;
for (int i = n; i * 2 > n; i--) {
if (a[i] == 0) {
b[i] = 0;
} else {
b[i] = 1;
}
j = i;
}
for (int k = j - 1; k > 0; k--) {
int sum = 0;
for (int m = 2; k * m <= n; m++) {
sum += b[k * m];
}
if (a[k] == 1) {
if (sum % 2 == 0)
b[k] = 1;
else
b[k] = 0;
} else {
if (sum % 2 == 0)
b[k] = 0;
else
b[k] = 1;
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (b[i] == 1)
cnt++;
}
cout << cnt << endl;
for (int i = 1; i <= n; i++) {
if (b[i] == 1)
cout << i << endl;
}
} | replace | 33 | 35 | 33 | 35 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int arr[N], n, val[N];
vector<int> v;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = i; j <= n; j += i)
sum += val[j];
if (sum % 2 != arr[i]) {
v.push_back(i);
val[i]++;
}
}
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int arr[N], n, val[N];
vector<int> v;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = i; j <= n; j += i)
sum += val[j];
if (sum % 2 != arr[i]) {
v.push_back(i);
val[i]++;
}
}
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
void Main() {
int n;
cin >> n;
int a[200010];
rep(i, n) cin >> a[i + 1];
int res[200010];
int cnt = 0;
for (int i = n; i > 0; --i) {
int other = 0;
for (int j = i + 1; j <= n; ++j) {
if (j % i == 0 && res[j] == 1) {
++other;
}
}
if (a[i] == 0) {
if (other % 2 == 0) {
res[i] = 0;
} else {
res[i] = 1;
++cnt;
}
} else {
if (other % 2 == 0) {
res[i] = 1;
++cnt;
} else {
res[i] = 0;
}
}
}
cout << cnt << endl;
rep(i, n) {
if (res[i + 1] == 1) {
cout << (i + 1);
if (i == n - 1) {
cout << endl;
} else {
cout << " ";
}
}
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
Main();
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
void Main() {
int n;
cin >> n;
int a[200010];
rep(i, n) cin >> a[i + 1];
int res[200010];
int cnt = 0;
for (int i = n; i > 0; --i) {
int other = 0;
for (int j = 2; true; ++j) {
if (j * i > n) {
break;
}
if (res[j * i] == 1) {
++other;
}
}
if (a[i] == 0) {
if (other % 2 == 0) {
res[i] = 0;
} else {
res[i] = 1;
++cnt;
}
} else {
if (other % 2 == 0) {
res[i] = 1;
++cnt;
} else {
res[i] = 0;
}
}
}
cout << cnt << endl;
rep(i, n) {
if (res[i + 1] == 1) {
cout << (i + 1);
if (i == n - 1) {
cout << endl;
} else {
cout << " ";
}
}
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
Main();
}
| replace | 29 | 31 | 29 | 34 | TLE | |
p02972 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> // setprecision
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h> // sqrt
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
int main() {
int N;
cin >> N;
vi data(N);
for (int i = 0; i < N; i++) {
cin >> data[i];
}
vi ans(N, 0);
int ansa = 0;
for (int i = N - 1; i >= 0; i--) {
int count = 0;
for (int j = N - 1; j >= i; j--) {
if ((j + 1) % (i + 1) == 0) {
count += ans[j];
}
}
count %= 2;
if (count != data[i]) {
ans[i]++;
ansa++;
}
}
cout << ansa << endl;
for (int i = 0; i < N; i++) {
if (ans[i] == 1) {
cout << i + 1 << " ";
}
}
cout << endl;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> // setprecision
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h> // sqrt
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
int main() {
int N;
cin >> N;
vi data(N);
for (int i = 0; i < N; i++) {
cin >> data[i];
}
vi ans(N, 0);
int ansa = 0;
for (int i = N - 1; i >= 0; i--) {
int count = 0;
int max = floor(N / (i + 1)) * (i + 1) - 1;
for (int j = max; j >= i; j -= i + 1) {
count += ans[j];
}
count %= 2;
if (count != data[i]) {
ans[i]++;
ansa++;
}
}
cout << ansa << endl;
for (int i = 0; i < N; i++) {
if (ans[i] == 1) {
cout << i + 1 << " ";
}
}
cout << endl;
}
| replace | 36 | 40 | 36 | 39 | TLE | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define print(x) cerr << (#x) << "is " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e5 + 10;
ll sum[N], a[N];
vector<ll> factor[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
f(i, 1, n + 1) { cin >> a[i]; }
vector<int> res;
f(i, 1, n + 1) {
for (int j = i; j <= n; j++) {
factor[j].pb(i);
}
}
// f(i,1,n+1){
// for(auto &el : factor[i]){
// cout << el << " ";
// }
// cout << "\n";
// }
for (int i = n; i >= 1; i--) {
if (sum[i] % 2 != a[i] % 2) {
res.pb(i);
for (auto &el : factor[i]) {
sum[el]++;
}
}
}
f(i, 1, n + 1) {
if (sum[i] % 2 != a[i] % 2) {
cout << "-1\n";
return 0;
}
}
sort(all(res));
cout << (int)res.size() << '\n';
for (auto &el : res) {
cout << el << ' ';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define print(x) cerr << (#x) << "is " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e5 + 10;
ll sum[N], a[N];
vector<ll> factor[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
f(i, 1, n + 1) { cin >> a[i]; }
vector<int> res;
f(i, 1, n + 1) {
for (int j = i; j <= n; j += i) {
factor[j].pb(i);
}
}
// f(i,1,n+1){
// for(auto &el : factor[i]){
// cout << el << " ";
// }
// cout << "\n";
// }
for (int i = n; i >= 1; i--) {
if (sum[i] % 2 != a[i] % 2) {
res.pb(i);
for (auto &el : factor[i]) {
sum[el]++;
}
}
}
f(i, 1, n + 1) {
if (sum[i] % 2 != a[i] % 2) {
cout << "-1\n";
return 0;
}
}
sort(all(res));
cout << (int)res.size() << '\n';
for (auto &el : res) {
cout << el << ' ';
}
return 0;
} | replace | 24 | 25 | 24 | 25 | TLE | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int a[1000000];
int b[1000000];
int c[1000000];
int main() {
ll cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
b[i] = 0;
// cerr << " end in" << endl;
for (ll i = n; i > 0; i--) {
ll sum = 0;
// for( ll j=i; j<=n; j+=i) sum+=b[j];
for (ll j = 0; j < cnt; j++)
if (c[j] % i == 0)
sum++;
if (a[i] != (sum % 2)) {
b[i] = 1;
c[cnt] = i;
cnt++;
} else
b[i] = 0;
}
/*
for(ll i=1; i<=n; i++){
cout << b[i] << endl;
}
*/
// cerr << "end calc" << endl;
cout << cnt << endl;
for (ll i = 0; i < cnt; i++) {
cout << c[i] << " ";
}
if (cnt != 0)
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int a[1000000];
int b[1000000];
int c[1000000];
int main() {
ll cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
b[i] = 0;
// cerr << " end in" << endl;
for (ll i = n; i > 0; i--) {
ll sum = 0;
for (ll j = i; j <= n; j += i)
sum += b[j];
// for( ll j=0; j<cnt; j++) if( c[j]%i == 0) sum++;
if (a[i] != (sum % 2)) {
b[i] = 1;
c[cnt] = i;
cnt++;
} else
b[i] = 0;
}
/*
for(ll i=1; i<=n; i++){
cout << b[i] << endl;
}
*/
// cerr << "end calc" << endl;
cout << cnt << endl;
for (ll i = 0; i < cnt; i++) {
cout << c[i] << " ";
}
if (cnt != 0)
cout << endl;
return 0;
}
| replace | 18 | 22 | 18 | 21 | TLE | |
p02972 | C++ | Runtime Error | #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[i];
}
int count = 0;
for (int i = n - 1; i >= 0; i--) {
for (int j = i * 2 + 1; j < n; j += i + 1) {
a[i] ^= a[j];
}
count += a[i];
}
cout << count << endl;
for (int i = 0; i < n; i++) {
if (a[i])
cout << i + " ";
}
}
| #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[i];
}
int count = 0;
for (int i = n - 1; i >= 0; i--) {
for (int j = i * 2 + 1; j < n; j += i + 1) {
a[i] ^= a[j];
}
count += a[i];
}
cout << count << endl;
for (int i = 0; i < n; i++) {
if (a[i])
cout << i + 1 << " ";
}
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <time.h>
#include <tuple>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
// #define M_PI 3.1415926535
#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);
ll bur(ll N, ll X);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
// UF木
class UnionFind {
public:
// 親
vector<int> Parent;
// 初期状態
UnionFind(int N) { Parent = vector<int>(N, -1); }
int root(int A) {
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
// サイズ確認
int size(int A) { return -Parent[root(A)]; }
int connect(int A, int B) {
// root同氏をくっつける
A = root(A);
B = root(B);
// 結合済み
if (A == B) {
return false;
}
// 大きいほうに小さいほうをくっつける
if (size(A) < size(B))
swap(A, B);
// Aのサイズ更新
Parent[A] += Parent[B];
// Bの親をAに
Parent[B] = A;
return true;
}
};
int main(void) {
int N = 0;
ll A = 0;
ll B = 0;
ll C = 0;
ll D = 0;
ll E = 0;
ll W = 0;
ll H = 0;
// ll T = 0;
// ll M = 0;
// ll h[400][400] = {};
ll b[9] = {1, 7, 4, 5, 3, 2, 9, 6, 8}; // 順番の配列
// ll b2[9] = { 2,3,4,5,5,5,6,6,7 };//順番の配列
// ll aa[20][20] = {};//sortaf
// ll c2[9] = {};
ll d[10] = {}; // 要素数
// ll v[3] = {};
// ll *c, *s, *n;
string S, T, U[52];
char fi[50], fv[50];
ll count = 0;
double count2 = 0;
ll min = 3000;
ll max = 1;
ll dist1 = 0;
ll dist2 = 0;
ll dist3 = 0;
ll now = 0;
int tmax = 10000;
int tmax2 = 0;
// int flag = 0;
// char temp, head, state;
// int is = 0;
bool start = false;
// char p;
float all = 0, all2 = 0, all3 = 0;
ll amr = 0;
ll first = 0;
ll second = 0;
// ll keep = 0;
// ll head = 0;
// ll tail = 0;
// ll lgh = 10000;
// ll state = 0;
char col = NULL;
// ll aa[3] = {10000,10000,10000}, bb[3] = { 10000,10000,10000 }, cc[3] = {
// 10000,10000,10000 }; ll an[3] = { 10000,10000,10000 }, bn[3] = {
// 10000,10000,10000 }, cn[3] = { 10000,10000,10000 };
cin >> N;
// vector<ll> mo(A+1);
vector<ll> dam(N + 1);
vector<ll> dam2(N);
rep(i, 0, N) { cin >> dam[i + 1]; }
for (int i = N; i > 0; --i) {
amr = i;
while (amr + i <= N) {
amr += i;
if (dam2[amr] == 1)
first++;
}
if (first % 2 != dam[i]) {
dam2[i] = 1;
dist1++;
} else
dam2[i] = 0;
// cout << first << " " << dam[i] <<endl;
first = 0;
}
cout << dist1 << endl;
if (dist1 == 0)
return 0;
rep(i, 1, N + 1) {
if (dam2[i] == 1) {
cout << i << " ";
}
}
cout << endl;
// cout << first << " " << second << endl;
// cout << min << endl;
/*if (amr % count == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;*/
return 0;
}
ll bur(ll N, ll X) {
ll pan = 1;
ll pat = 1;
ll burg = 0;
if (X > burg) {
if (N == 0)
return pat;
burg += pan;
burg += bur(N - 1, X);
burg += pat;
burg += bur(N - 1, X);
burg += pan;
}
return burg;
}
ll gcd(ll a, ll b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll x = b;
ll y = a;
/* ユークリッドの互除法 */
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return y / b * x;
}
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
// 最大公約数を求める関数
ll lcm(ll x, ll y) {
if (x == 0 || y == 0) // 引数チェック
{
// fprintf(stderr, "引数エラーです。\n");
return 0;
}
return (x * y / gcd(x, y));
}
// combination
long long comb(int n, int r) {
std::vector<std::vector<long long>> v(n + 1,
std::vector<long long>(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v[n][r];
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <time.h>
#include <tuple>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
// #define M_PI 3.1415926535
#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);
ll bur(ll N, ll X);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
// UF木
class UnionFind {
public:
// 親
vector<int> Parent;
// 初期状態
UnionFind(int N) { Parent = vector<int>(N, -1); }
int root(int A) {
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
// サイズ確認
int size(int A) { return -Parent[root(A)]; }
int connect(int A, int B) {
// root同氏をくっつける
A = root(A);
B = root(B);
// 結合済み
if (A == B) {
return false;
}
// 大きいほうに小さいほうをくっつける
if (size(A) < size(B))
swap(A, B);
// Aのサイズ更新
Parent[A] += Parent[B];
// Bの親をAに
Parent[B] = A;
return true;
}
};
int main(void) {
int N = 0;
ll A = 0;
ll B = 0;
ll C = 0;
ll D = 0;
ll E = 0;
ll W = 0;
ll H = 0;
// ll T = 0;
// ll M = 0;
// ll h[400][400] = {};
ll b[9] = {1, 7, 4, 5, 3, 2, 9, 6, 8}; // 順番の配列
// ll b2[9] = { 2,3,4,5,5,5,6,6,7 };//順番の配列
// ll aa[20][20] = {};//sortaf
// ll c2[9] = {};
ll d[10] = {}; // 要素数
// ll v[3] = {};
// ll *c, *s, *n;
string S, T, U[52];
char fi[50], fv[50];
ll count = 0;
double count2 = 0;
ll min = 3000;
ll max = 1;
ll dist1 = 0;
ll dist2 = 0;
ll dist3 = 0;
ll now = 0;
int tmax = 10000;
int tmax2 = 0;
// int flag = 0;
// char temp, head, state;
// int is = 0;
bool start = false;
// char p;
float all = 0, all2 = 0, all3 = 0;
ll amr = 0;
ll first = 0;
ll second = 0;
// ll keep = 0;
// ll head = 0;
// ll tail = 0;
// ll lgh = 10000;
// ll state = 0;
char col = NULL;
// ll aa[3] = {10000,10000,10000}, bb[3] = { 10000,10000,10000 }, cc[3] = {
// 10000,10000,10000 }; ll an[3] = { 10000,10000,10000 }, bn[3] = {
// 10000,10000,10000 }, cn[3] = { 10000,10000,10000 };
cin >> N;
// vector<ll> mo(A+1);
vector<ll> dam(N + 1);
vector<ll> dam2(N + 1);
rep(i, 0, N) { cin >> dam[i + 1]; }
for (int i = N; i > 0; --i) {
amr = i;
while (amr + i <= N) {
amr += i;
if (dam2[amr] == 1)
first++;
}
if (first % 2 != dam[i]) {
dam2[i] = 1;
dist1++;
} else
dam2[i] = 0;
// cout << first << " " << dam[i] <<endl;
first = 0;
}
cout << dist1 << endl;
if (dist1 == 0)
return 0;
rep(i, 1, N + 1) {
if (dam2[i] == 1) {
cout << i << " ";
}
}
cout << endl;
// cout << first << " " << second << endl;
// cout << min << endl;
/*if (amr % count == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;*/
return 0;
}
ll bur(ll N, ll X) {
ll pan = 1;
ll pat = 1;
ll burg = 0;
if (X > burg) {
if (N == 0)
return pat;
burg += pan;
burg += bur(N - 1, X);
burg += pat;
burg += bur(N - 1, X);
burg += pan;
}
return burg;
}
ll gcd(ll a, ll b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll x = b;
ll y = a;
/* ユークリッドの互除法 */
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return y / b * x;
}
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
// 最大公約数を求める関数
ll lcm(ll x, ll y) {
if (x == 0 || y == 0) // 引数チェック
{
// fprintf(stderr, "引数エラーです。\n");
return 0;
}
return (x * y / gcd(x, y));
}
// combination
long long comb(int n, int r) {
std::vector<std::vector<long long>> v(n + 1,
std::vector<long long>(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v[n][r];
} | replace | 134 | 135 | 134 | 135 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#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 pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int)x.size())
#define rd(type, ...) \
type __VA_ARGS__; \
sc(__VA_ARGS__)
#define rdv(type, v, n) \
vector<type> v(n); \
rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) \
vector<vector<type>>(h, vector<type>(w)) v; \
rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed;
cout.precision(12);
solve();
return 0;
}
template <typename T> void prv(vector<T> v) {
rep(__ii, 0, sz(v)) {
if (__ii)
cout << ' ';
cout << v[__ii];
}
cout << '\n';
}
template <typename T> void prm(vector<vector<T>> v) {
rep(__ii, 0, sz(v)) {
rep(__jj, 0, v[__ii].size()) {
if (__jj)
cout << ' ';
cout << v[__ii][__jj];
}
cout << '\n';
}
}
template <typename T> void sc(T &x) { cin >> x; }
template <typename Head, typename... Tail> void sc(Head &head, Tail &...tail) {
cin >> head;
sc(tail...);
}
template <typename T> void pr(const T &x) { cout << x << '\n'; }
template <typename Head, typename... Tail>
void pr(const Head &head, const Tail &...tail) {
cout << head << ' ';
pr(tail...);
}
template <typename... T> void err(const T &...cod) {
pr(cod...);
exit(0);
}
const int N = 1e5 + 10;
int a[N], b[N];
void solve() {
rd(int, n);
rep(i, 1, n + 1) cin >> a[i];
per(i, n, n / 2 + 1) b[i] = a[i];
per(i, n / 2, 1) {
int sum = 0;
for (int j = i + i; j <= n; j += i)
sum += b[j];
sum %= 2;
if (a[i])
b[i] = (sum ? 0 : 1);
else
b[i] = (sum ? 1 : 0);
}
vector<int> ans;
rep(i, 1, n + 1) if (b[i]) ans.pb(i);
pr(sz(ans));
prv(ans);
} | #include <bits/stdc++.h>
using namespace std;
#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 pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int)x.size())
#define rd(type, ...) \
type __VA_ARGS__; \
sc(__VA_ARGS__)
#define rdv(type, v, n) \
vector<type> v(n); \
rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) \
vector<vector<type>>(h, vector<type>(w)) v; \
rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed;
cout.precision(12);
solve();
return 0;
}
template <typename T> void prv(vector<T> v) {
rep(__ii, 0, sz(v)) {
if (__ii)
cout << ' ';
cout << v[__ii];
}
cout << '\n';
}
template <typename T> void prm(vector<vector<T>> v) {
rep(__ii, 0, sz(v)) {
rep(__jj, 0, v[__ii].size()) {
if (__jj)
cout << ' ';
cout << v[__ii][__jj];
}
cout << '\n';
}
}
template <typename T> void sc(T &x) { cin >> x; }
template <typename Head, typename... Tail> void sc(Head &head, Tail &...tail) {
cin >> head;
sc(tail...);
}
template <typename T> void pr(const T &x) { cout << x << '\n'; }
template <typename Head, typename... Tail>
void pr(const Head &head, const Tail &...tail) {
cout << head << ' ';
pr(tail...);
}
template <typename... T> void err(const T &...cod) {
pr(cod...);
exit(0);
}
const int N = 2e5 + 10;
int a[N], b[N];
void solve() {
rd(int, n);
rep(i, 1, n + 1) cin >> a[i];
per(i, n, n / 2 + 1) b[i] = a[i];
per(i, n / 2, 1) {
int sum = 0;
for (int j = i + i; j <= n; j += i)
sum += b[j];
sum %= 2;
if (a[i])
b[i] = (sum ? 0 : 1);
else
b[i] = (sum ? 1 : 0);
}
vector<int> ans;
rep(i, 1, n + 1) if (b[i]) ans.pb(i);
pr(sz(ans));
prv(ans);
} | replace | 62 | 63 | 62 | 63 | 0 | |
p02972 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
using namespace std;
const int M = 2e5 + 5;
int a[M];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int cnt = 0;
for (int i = n; i >= 1; i--) {
for (int j = 2; j <= n; j++)
a[i] = (a[i] + a[i * j]) % 2;
if (a[i])
cnt++;
}
printf("%d\n", cnt);
for (int i = 1; i <= n; i++)
if (a[i])
printf("%d ", i);
printf("\n");
return 0;
} | #include <iostream>
#include <stdio.h>
using namespace std;
const int M = 2e5 + 5;
int a[M];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int cnt = 0;
for (int i = n; i >= 1; i--) {
for (int j = 2; i * j <= n; j++)
a[i] = (a[i] + a[i * j]) % 2;
if (a[i])
cnt++;
}
printf("%d\n", cnt);
for (int i = 1; i <= n; i++)
if (a[i])
printf("%d ", i);
printf("\n");
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
#define all(v) (v).begin(), (v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
// typedef vector<vector<ll>> mat;
typedef vector<int> vec;
// 繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)
res = res * a % m;
a = a * a % m;
n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() : n(0) { ; }
modint(ll m) : n(m) {
if (n >= mod)
n %= mod;
else if (n < 0)
n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
a.n += b.n;
if (a.n >= mod)
a.n -= mod;
return a;
}
modint operator-=(modint &a, modint b) {
a.n -= b.n;
if (a.n < 0)
a.n += mod;
return a;
}
modint operator*=(modint &a, modint b) {
a.n = ((ll)a.n * b.n) % mod;
return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0)
return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)
res = res * a;
return res;
}
// 逆元(Eucledean algorithm)
ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); }
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)
return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
int N;
cin >> N;
vec a(N);
rep(i, N) { cin >> a[i + 1]; }
vec res(N + 1);
for (int i = N; i >= 1; i--) {
int p = 0;
for (int j = i * 2; j <= N; j += i)
p += res[j];
int s = p % 2;
if (a[i] == s)
res[i] = 0;
else
res[i] = 1;
}
vec ans;
rep(i, N + 1) {
if (res[i])
ans.push_back(i);
}
cout << ans.size() << endl;
rep(i, ans.size()) {
cout << ans[i];
if (i != ans.size() - 1)
cout << " ";
else
cout << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout << fixed << setprecision(10);
// init_f();
// init();
// int t; cin >> t; rep(i, t)solve();
solve();
// stop
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
#define all(v) (v).begin(), (v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
// typedef vector<vector<ll>> mat;
typedef vector<int> vec;
// 繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)
res = res * a % m;
a = a * a % m;
n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() : n(0) { ; }
modint(ll m) : n(m) {
if (n >= mod)
n %= mod;
else if (n < 0)
n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
a.n += b.n;
if (a.n >= mod)
a.n -= mod;
return a;
}
modint operator-=(modint &a, modint b) {
a.n -= b.n;
if (a.n < 0)
a.n += mod;
return a;
}
modint operator*=(modint &a, modint b) {
a.n = ((ll)a.n * b.n) % mod;
return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0)
return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)
res = res * a;
return res;
}
// 逆元(Eucledean algorithm)
ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); }
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)
return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
int N;
cin >> N;
vec a(N + 1);
rep(i, N) { cin >> a[i + 1]; }
vec res(N + 1);
for (int i = N; i >= 1; i--) {
int p = 0;
for (int j = i * 2; j <= N; j += i)
p += res[j];
int s = p % 2;
if (a[i] == s)
res[i] = 0;
else
res[i] = 1;
}
vec ans;
rep(i, N + 1) {
if (res[i])
ans.push_back(i);
}
cout << ans.size() << endl;
rep(i, ans.size()) {
cout << ans[i];
if (i != ans.size() - 1)
cout << " ";
else
cout << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout << fixed << setprecision(10);
// init_f();
// init();
// int t; cin >> t; rep(i, t)solve();
solve();
// stop
return 0;
}
| replace | 111 | 112 | 111 | 112 | 0 | |
p02972 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N;
bool A[2010], C[2010];
vector<int> B;
cin >> N;
for (int i = 1; i <= N; ++i) {
bool a;
cin >> a;
A[i] = (a > 0 ? true : false);
}
int sum = 0;
for (int i = N; i >= 1; --i) {
int j = i;
bool c = A[i];
while (j + i <= N) {
j += i;
c ^= C[j];
}
C[i] = c;
if (c) {
sum++;
B.push_back(i);
}
}
cout << sum << endl;
for (auto b : B) {
cout << b << endl;
}
}
| #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N;
bool A[200010], C[200010];
vector<int> B;
cin >> N;
for (int i = 1; i <= N; ++i) {
bool a;
cin >> a;
A[i] = (a > 0 ? true : false);
}
int sum = 0;
for (int i = N; i >= 1; --i) {
int j = i;
bool c = A[i];
while (j + i <= N) {
j += i;
c ^= C[j];
}
C[i] = c;
if (c) {
sum++;
B.push_back(i);
}
}
cout << sum << endl;
for (auto b : B) {
cout << b << endl;
}
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
int a[2100];
int b[2100];
vector<int> x;
int c = 0;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = N; i > 0; i--) {
int z = 2;
int sum = 0;
while (z * i <= N) {
sum += b[z * i];
z++;
}
if (sum % 2 == a[i])
b[i] = 0;
else {
b[i] = 1;
x.push_back(i);
c++;
}
}
cout << c << endl;
for (int i = 0; i < c; i++) {
cout << x[i] << " ";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
int a[210000];
int b[210000];
vector<int> x;
int c = 0;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = N; i > 0; i--) {
int z = 2;
int sum = 0;
while (z * i <= N) {
sum += b[z * i];
z++;
}
if (sum % 2 == a[i])
b[i] = 0;
else {
b[i] = 1;
x.push_back(i);
c++;
}
}
cout << c << endl;
for (int i = 0; i < c; i++) {
cout << x[i] << " ";
}
} | replace | 10 | 12 | 10 | 12 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
if (a > b) {
return b;
} else {
return a;
}
}
ll max(ll a, ll b) {
if (a > b) {
return a;
} else {
return b;
}
}
ll power(ll a, ll b) {
ll ans = 1;
for (ll i = 1; i <= b; i++) {
ans *= a;
}
return ans;
}
ll gcd(ll m, ll n) {
if (n == 0) {
return m;
}
return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / gcd(a, b) * b;
}
int main() {
ll N;
cin >> N;
vector<ll> a(N);
ll sum = 0;
rep(i, N) { cin >> a[i]; }
vector<bool> ans(N);
ll num = 0;
for (ll i = N - 1; i >= 0; i--) {
if (i == N - 1) {
if (a[i] == 1) {
ans[i] = true;
num++;
} else {
ans[i] = false;
}
} else {
ll sum = 0;
for (ll j = i + 1; j <= N - 1; j++) {
if (ans[j]) {
if ((j + 1) % (i + 1) == 0) {
sum++;
}
}
}
if ((sum % 2 == 1 && a[i] == 0) || (sum % 2 == 0 && a[i] == 1)) {
ans[i] = true;
num++;
} else {
ans[i] = false;
}
}
}
cout << num << endl;
rep(i, N) {
if (ans[i]) {
cout << i + 1 << " ";
}
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
if (a > b) {
return b;
} else {
return a;
}
}
ll max(ll a, ll b) {
if (a > b) {
return a;
} else {
return b;
}
}
ll power(ll a, ll b) {
ll ans = 1;
for (ll i = 1; i <= b; i++) {
ans *= a;
}
return ans;
}
ll gcd(ll m, ll n) {
if (n == 0) {
return m;
}
return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / gcd(a, b) * b;
}
int main() {
ll N;
cin >> N;
vector<ll> a(N);
ll sum = 0;
rep(i, N) { cin >> a[i]; }
vector<bool> ans(N);
ll num = 0;
for (ll i = N - 1; i >= 0; i--) {
if (i == N - 1) {
if (a[i] == 1) {
ans[i] = true;
num++;
} else {
ans[i] = false;
}
} else {
ll sum = 0;
ll X = N / (i + 1);
for (ll j = 2; j <= X; j++) {
if (ans[j * (i + 1) - 1]) {
sum++;
}
}
if ((sum % 2 == 1 && a[i] == 0) || (sum % 2 == 0 && a[i] == 1)) {
ans[i] = true;
num++;
} else {
ans[i] = false;
}
}
}
cout << num << endl;
rep(i, N) {
if (ans[i]) {
cout << i + 1 << " ";
}
}
cout << endl;
}
| replace | 63 | 68 | 63 | 68 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005], b[100005];
int main() {
int n, num = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
int j = i * 2;
b[i] = a[i];
while (j <= n) {
b[i] ^= b[j];
j += i;
}
if (b[i])
num++;
}
cout << num << endl;
for (int i = 1; i <= n; i++) {
if (b[i])
cout << i << " ";
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005], b[200005];
int main() {
int n, num = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
int j = i * 2;
b[i] = a[i];
while (j <= n) {
b[i] ^= b[j];
j += i;
}
if (b[i])
num++;
}
cout << num << endl;
for (int i = 1; i <= n; i++) {
if (b[i])
cout << i << " ";
}
cout << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
long long n, sum = 0, mod = 2019;
cin >> n;
vector<bool> vec(n + 1, 0);
vector<int> ans;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
int j = i;
sum = 0;
while (j + i <= n) {
j += i;
sum += vec[j];
}
if (sum % 2 != a[i]) {
vec[i] = 1;
ans.push_back(i);
}
}
cout << ans.size() << endl;
for (int i = ans.size(); i >= 0; i--)
cout << ans[i] << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
long long n, sum = 0, mod = 2019;
cin >> n;
vector<bool> vec(n + 1, 0);
vector<int> ans;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
int j = i;
sum = 0;
while (j + i <= n) {
j += i;
sum += vec[j];
}
if (sum % 2 != a[i]) {
vec[i] = 1;
ans.push_back(i);
}
}
cout << ans.size() << endl;
for (int i = ans.size() - 1; i >= 0; i--)
cout << ans[i] << endl;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
REP(i, n) { cin >> a[i]; }
vector<int> ans(n + 1, 0);
for (int i = n; i >= 1; --i) {
int count = 0;
for (int j = i; j <= n; ++j) {
if (j % i == 0) {
count += ans[j];
}
}
if (count % 2 == a[i]) {
ans[i] = 0;
} else {
ans[i] = 1;
}
}
int hako = 0;
REP(i, n) {
if (ans[i] == 1)
hako++;
}
cout << hako << endl;
REP(i, n) {
if (ans[i] != 0)
cout << i << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
REP(i, n) { cin >> a[i]; }
vector<int> ans(n + 1, 0);
for (int i = n; i >= 1; --i) {
int count = 0;
for (int j = 1; j * i <= n; ++j) {
count += ans[j * i];
}
if (count % 2 == a[i]) {
ans[i] = 0;
} else {
ans[i] = 1;
}
}
int hako = 0;
REP(i, n) {
if (ans[i] == 1)
hako++;
}
cout << hako << endl;
REP(i, n) {
if (ans[i] != 0)
cout << i << " ";
}
cout << endl;
return 0;
}
| replace | 15 | 19 | 15 | 17 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> a(N);
REP(i, N) { cin >> a[i]; }
vector<int> ans(N + 1);
ans.assign(N + 1, 0);
for (int i = N; i >= 1; --i) {
int count = 1;
int temp = 0;
while (i * count <= N) {
temp += ans[i * count];
count++;
}
if (temp % 2 == a[i] % 2) {
ans[i] = 0;
} else {
ans[i] = 1;
}
}
int num = 0;
REP(i, N) { num += ans[i]; }
cout << num << endl;
REP(i, N) {
if (ans[i] != 0) {
cout << i << " ";
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> a(N + 1);
REP(i, N) { cin >> a[i]; }
vector<int> ans(N + 1);
ans.assign(N + 1, 0);
for (int i = N; i >= 1; --i) {
int count = 1;
int temp = 0;
while (i * count <= N) {
temp += ans[i * count];
count++;
}
if (temp % 2 == a[i] % 2) {
ans[i] = 0;
} else {
ans[i] = 1;
}
}
int num = 0;
REP(i, N) { num += ans[i]; }
cout << num << endl;
REP(i, N) {
if (ans[i] != 0) {
cout << i << " ";
}
}
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02972 | C++ | Runtime Error | #include <iostream>
using namespace std;
unsigned int a[100001];
bool ans[100001];
int main(void) {
int N;
cin >> N;
for (int i = 0; i <= N; i++)
ans[i] = false;
for (int i = 1; i <= N; i++)
cin >> a[i];
int ans_cnt = 0;
for (int i = N; i > 0; i--) {
unsigned int sum = 0;
for (int j = i; j <= N; j += i) {
if (ans[j])
sum++;
}
if ((sum & 1u) == a[i])
; // 何もしない
else { // 入れる
ans[i] = true;
ans_cnt++;
}
}
cout << ans_cnt << endl;
for (int i = 1; i <= N; i++) {
if (ans[i])
cout << i << " ";
}
return 0;
}
| #include <iostream>
using namespace std;
unsigned int a[200001];
bool ans[200001];
int main(void) {
int N;
cin >> N;
for (int i = 0; i <= N; i++)
ans[i] = false;
for (int i = 1; i <= N; i++)
cin >> a[i];
int ans_cnt = 0;
for (int i = N; i > 0; i--) {
unsigned int sum = 0;
for (int j = i; j <= N; j += i) {
if (ans[j])
sum++;
}
if ((sum & 1u) == a[i])
; // 何もしない
else { // 入れる
ans[i] = true;
ans_cnt++;
}
}
cout << ans_cnt << endl;
for (int i = 1; i <= N; i++) {
if (ans[i])
cout << i << " ";
}
return 0;
}
| replace | 3 | 5 | 3 | 5 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> a(n);
for (long i = 0; i < n; ++i) {
cin >> a[i];
}
vector<long> ans;
for (long i = n - 1; i >= n / 2 + 1; --i) {
ans.push_back(a[i]);
}
for (long i = n / 2; i >= 0; --i) {
long sum = 0;
for (long j = i + 1 + i + 1; j <= n; j += i + 1) {
sum += ans[j - 1];
}
ans.push_back((sum + a[i]) % 2);
}
long sum = accumulate(ans.begin(), ans.end(), 0L);
cout << sum << endl;
if (sum != 0) {
long last_1;
for (long i = n - 1; i >= 0; --i) {
if (ans[i] == 1) {
last_1 = i;
break;
}
}
for (long i = 0; i < last_1; ++i) {
if (ans[i] == 1) {
cout << n - i;
cout << ' ';
}
}
cout << n - last_1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> a(n);
for (long i = 0; i < n; ++i) {
cin >> a[i];
}
vector<long> ans;
for (long i = n - 1; i >= n / 2 + 1; --i) {
ans.push_back(a[i]);
}
for (long i = n / 2; i >= 0; --i) {
long sum = 0;
for (long j = i + 1 + i + 1; j <= n; j += i + 1) {
sum += ans[n - j];
}
ans.push_back((sum + a[i]) % 2);
}
long sum = accumulate(ans.begin(), ans.end(), 0L);
cout << sum << endl;
if (sum != 0) {
long last_1;
for (long i = n - 1; i >= 0; --i) {
if (ans[i] == 1) {
last_1 = i;
break;
}
}
for (long i = 0; i < last_1; ++i) {
if (ans[i] == 1) {
cout << n - i;
cout << ' ';
}
}
cout << n - last_1 << endl;
}
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02972 | C++ | Runtime Error | /*
Original problem: https://atcoder.jp/contests/abc134/tasks/abc134_d
Author: sammochen
*/
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RREP(x, l, u) for (ll x = l; x >= u; x--)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const ll mod = 1e9 + 7;
namespace SOLVE {
void main() {
int n;
cin >> n;
VI A(n + 1);
REP(i, 1, n + 1) { cin >> A[i]; }
int onecount = 0;
VI ans(n);
RREP(i, n, 1) {
int c = 0;
// check forward and see what had been set
for (int mult = 2 * i; mult <= n; mult += i) {
c += ans[mult];
}
c %= 2;
ans[i] = c != A[i];
if (ans[i] == 1) {
onecount++;
}
}
cout << onecount << endl;
REP(i, 1, n + 1) {
if (ans[i] == 1) {
cout << i << ' ';
}
}
cout << endl;
}
} // namespace SOLVE
signed main() {
int t;
t = 1;
// cin >> t;
while (t--) {
SOLVE::main();
}
return 0;
} | /*
Original problem: https://atcoder.jp/contests/abc134/tasks/abc134_d
Author: sammochen
*/
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RREP(x, l, u) for (ll x = l; x >= u; x--)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;
const ll mod = 1e9 + 7;
namespace SOLVE {
void main() {
int n;
cin >> n;
VI A(n + 1);
REP(i, 1, n + 1) { cin >> A[i]; }
int onecount = 0;
VI ans(n + 1);
RREP(i, n, 1) {
int c = 0;
// check forward and see what had been set
for (int mult = 2 * i; mult <= n; mult += i) {
c += ans[mult];
}
c %= 2;
ans[i] = c != A[i];
if (ans[i] == 1) {
onecount++;
}
}
cout << onecount << endl;
REP(i, 1, n + 1) {
if (ans[i] == 1) {
cout << i << ' ';
}
}
cout << endl;
}
} // namespace SOLVE
signed main() {
int t;
t = 1;
// cin >> t;
while (t--) {
SOLVE::main();
}
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, a[200005], b[200005];
vector<int> ans;
inline void dd() {
for (int i = 1; i <= n; ++i)
printf("%d ", b[i]);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = n; i >= 1; --i) {
int t = 0;
for (int j = i; j >= 1; j += i) {
t += b[j];
}
if ((t % 2) != a[i]) {
b[i] = 1;
ans.push_back(i);
}
}
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); ++i)
printf("%d ", ans[i]);
return 0;
} | #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, a[200005], b[200005];
vector<int> ans;
inline void dd() {
for (int i = 1; i <= n; ++i)
printf("%d ", b[i]);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = n; i >= 1; --i) {
int t = 0;
for (int j = i; j <= n; j += i) {
t += b[j];
}
if ((t % 2) != a[i]) {
b[i] = 1;
ans.push_back(i);
}
}
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); ++i)
printf("%d ", ans[i]);
return 0;
} | replace | 16 | 17 | 16 | 17 | TLE | |
p02972 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) {
cin >> a.at(i);
}
vector<long long int> pre(n, 0);
vector<long long int> hoge;
long long int ans = 0;
for (long long int i = n - 1; i >= 0; i--) {
long long int now = 0;
long long int step = 1;
long long int start = n - 1;
if (i + 1 > n / 2)
start = n / 2;
for (long long int j = start; j > i; j -= step) {
if ((j + 1) % (i + 1) == 0) {
step = i + 1;
now += pre.at(j);
}
}
if (now % 2 != a.at(i)) {
ans++;
hoge.push_back(i + 1);
pre.at(i) = 1;
}
}
cout << ans << endl;
for (long long int i = 0; i < hoge.size(); i++) {
cout << hoge.at(i) << endl;
}
} | #include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) {
cin >> a.at(i);
}
vector<long long int> pre(n, 0);
vector<long long int> hoge;
long long int ans = 0;
for (long long int i = n - 1; i >= 0; i--) {
long long int now = 0;
long long int step = 1;
long long int start = n - n % (i + 1) - 1;
for (long long int j = start; j > i; j -= step) {
if ((j + 1) % (i + 1) == 0) {
step = i + 1;
now += pre.at(j);
}
}
if (now % 2 != a.at(i)) {
ans++;
hoge.push_back(i + 1);
pre.at(i) = 1;
}
}
cout << ans << endl;
for (long long int i = 0; i < hoge.size(); i++) {
cout << hoge.at(i) << endl;
}
} | replace | 24 | 27 | 24 | 25 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
int a[N], b[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
// freopen("", "r", stdin);
// freopen("", "w", stdout);
#endif
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<int> v;
for (int i = n; i >= 1; i--) {
int total = 0;
for (int j = i + i; j <= n; j += i)
total += b[j];
if (total % 2 != a[i] % 2)
v.push_back(i), b[i] = 1;
}
cout << v.size() << '\n';
for (auto &x : v)
cout << x << ' ';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 5;
int a[N], b[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
// freopen("", "r", stdin);
// freopen("", "w", stdout);
#endif
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<int> v;
for (int i = n; i >= 1; i--) {
int total = 0;
for (int j = i + i; j <= n; j += i)
total += b[j];
if (total % 2 != a[i] % 2)
v.push_back(i), b[i] = 1;
}
cout << v.size() << '\n';
for (auto &x : v)
cout << x << ' ';
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02972 | C++ | Runtime Error | // D.
#include <algorithm>
#include <bitset>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
typedef long long LL;
typedef bitset<100002> BS;
int main(int argc, char *argv[]) {
int n;
cin >> n;
BS a, r;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x) {
a[i] = true;
}
}
for (int i = n; i >= 1; --i) {
bool c = a[i];
for (int j = i + i; j <= n; j += i) {
c ^= r[j];
}
r[i] = c;
}
vector<int> res;
for (int i = 1; i <= n; ++i) {
if (r[i]) {
res.push_back(i);
}
}
cout << res.size() << endl;
if (res.size()) {
for (int i = 0; i < (int)res.size(); ++i) {
if (i)
cout << " ";
cout << res[i];
}
cout << endl;
}
return 0;
}
| // D.
#include <algorithm>
#include <bitset>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
typedef long long LL;
typedef bitset<200002> BS;
int main(int argc, char *argv[]) {
int n;
cin >> n;
BS a, r;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x) {
a[i] = true;
}
}
for (int i = n; i >= 1; --i) {
bool c = a[i];
for (int j = i + i; j <= n; j += i) {
c ^= r[j];
}
r[i] = c;
}
vector<int> res;
for (int i = 1; i <= n; ++i) {
if (r[i]) {
res.push_back(i);
}
}
cout << res.size() << endl;
if (res.size()) {
for (int i = 0; i < (int)res.size(); ++i) {
if (i)
cout << " ";
cout << res[i];
}
cout << endl;
}
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
vector<ll> a(n), b(n, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
int ans = 0;
for (ll j = i; j <= n; j += i) {
ans += b[j];
}
if (ans % 2 != a[i])
b[i] = 1;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
if (b[i] > 0) {
cnt++;
}
cout << cnt << endl;
ll k = 0;
for (ll i = 1; i <= n; i++) {
if (b[i] && k == 0) {
cout << i << endl;
k++;
} else if (b[i]) {
cout << i << endl;
}
}
}
| #include <algorithm>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
vector<ll> a(2 * n), b(2 * n, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
int ans = 0;
for (ll j = i; j <= n; j += i) {
ans += b[j];
}
if (ans % 2 != a[i])
b[i] = 1;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
if (b[i] > 0) {
cnt++;
}
cout << cnt << endl;
ll k = 0;
for (ll i = 1; i <= n; i++) {
if (b[i] && k == 0) {
cout << i << endl;
k++;
} else if (b[i]) {
cout << i << endl;
}
}
}
| replace | 18 | 19 | 18 | 19 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9 + 7;
Int INF = 1e18;
double EPS = 0.00000001;
// Int mod = 998244353;
int main() {
Int n;
cin >> n;
vector<bool> a(n + 1);
for (Int i = 1; i <= n; i++) {
Int x;
cin >> x;
a[i] = (x == 1);
}
vector<bool> b(n, false);
vector<bool> res(n, false);
for (Int i = n; i >= 1; i--) {
if (a[i] != b[i]) {
res[i] = true;
for (Int j = 1; j * j <= i; j++) {
if (i % j == 0) {
if (j * j == i) {
b[j] = !b[j];
} else {
b[j] = !b[j];
b[i / j] = !b[i / j];
}
}
}
}
}
// else {
Int cnt = 0;
for (Int i = 1; i <= n; i++) {
if (res[i])
cnt++;
}
dump(cnt);
if (cnt == 0) {
return 0;
}
for (Int i = 1; i <= n; i++) {
if (res[i])
cout << i << " ";
}
cout << endl;
//}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9 + 7;
Int INF = 1e18;
double EPS = 0.00000001;
// Int mod = 998244353;
int main() {
Int n;
cin >> n;
vector<bool> a(n + 1);
for (Int i = 1; i <= n; i++) {
Int x;
cin >> x;
a[i] = (x == 1);
}
vector<bool> b(n + 1, false);
vector<bool> res(n + 1, false);
for (Int i = n; i >= 1; i--) {
if (a[i] != b[i]) {
res[i] = true;
for (Int j = 1; j * j <= i; j++) {
if (i % j == 0) {
if (j * j == i) {
b[j] = !b[j];
} else {
b[j] = !b[j];
b[i / j] = !b[i / j];
}
}
}
}
}
// else {
Int cnt = 0;
for (Int i = 1; i <= n; i++) {
if (res[i])
cnt++;
}
dump(cnt);
if (cnt == 0) {
return 0;
}
for (Int i = 1; i <= n; i++) {
if (res[i])
cout << i << " ";
}
cout << endl;
//}
return 0;
} | replace | 20 | 22 | 20 | 22 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm> //sort()
#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <tuple>
#include <vector> //vector
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;
typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;
template <class T> inline bool chmin(T &a, T b);
template <class T> inline bool chmax(T &a, T b);
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v);
template <class T> lint sum(vector<T> a);
template <class T> double ave(vector<T> a);
lint n, k;
lint h, w;
int main() {
//////////////////////////////////////////////////////
cin >> n;
vector<lint> a(n);
// fpair<lint,lint> p = make_pair(1,2);
// tuple<lint,lint,lint> t = make_tuple(1,2,3);
rep(i, n) { cin >> a[i]; }
// 入力自動生成始まり
// n = 10000;
// vector<lint> a(n,1);
// 入力自動生成終わり
// debug(i);
vector<char> ball(n, 0); // 入れた位置をtrueに
lint ballnum = 0;
// debug(9991);
for (lint k = n; k >= 1; k--) {
// debug(k);
lint sumb = 0;
// 倍数の探索
for (lint j = k; j <= n; j += k) {
sumb += ball[j];
}
// debug(a[k-1]);
// debug(sumb);
// debug((sumb + a[k-1])%2);
// if(k == 5000)
// {
// debug(sumb);
// debug(a[k-1]);
// }
ball[k] = (sumb + a[k - 1]) % 2; // 入れたり入れなかったり
ballnum += ball[k];
}
// debug(9992);
cout << ballnum << endl;
rep(i, n) {
if (ball[i + 1] == 1)
cout << i + 1 << " ";
}
if (ballnum > 0)
cout << endl;
// debug(ball);
// 昇順ソート
// sort(all(a));
// sort(input.begin() , input.end());
// uint64_t max = numeric_limits<uint64_t>::max();
//////////////////////////////////////////////////////
// DP
// // 無限大の値
// const uint64_t INF = (uint64_t)1 << 60;
// //const int64_t NINF = -1 * ((int64_t)1 << 60 );
// // DP テーブル
// uint64_t dp[100010];
// //DPテーブル初期化(最小化用)
// for (int i = 0; i < 100010; ++i)
// {
// //dp[i] = INF;
// dp[i] = 0;
// }
// // 初期条件
// dp[0] = 0;
// // ループ
// for (int i = 1; i <= n; ++i) {
// //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
// //if (i < 2)continue;
// //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));
// // chmax ( dp [i] , dp[i - 1]);
// // chmax ( dp [i] , dp[i - 1] + input[i]);
// // cout << "dp[" << i <<"] = " << dp[i] << endl;
// }
// //////////////////////////////////////////////////////
// cout << dp[n] << endl;
//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
return 0;
}
// 最小化用関数
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;
}
// vectorprint用
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
// //合計
// template<class T> lint sum(vector<T> a)
// {
// return std::accumulate(a.begin(), a.end(), 0);
// }
// //平均
// template<class T> double ave(vector<T> a)
// {
// return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }
| #include <algorithm> //sort()
#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <tuple>
#include <vector> //vector
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;
typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;
template <class T> inline bool chmin(T &a, T b);
template <class T> inline bool chmax(T &a, T b);
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v);
template <class T> lint sum(vector<T> a);
template <class T> double ave(vector<T> a);
lint n, k;
lint h, w;
int main() {
//////////////////////////////////////////////////////
cin >> n;
vector<lint> a(n);
// fpair<lint,lint> p = make_pair(1,2);
// tuple<lint,lint,lint> t = make_tuple(1,2,3);
rep(i, n) { cin >> a[i]; }
// 入力自動生成始まり
// n = 10000;
// vector<lint> a(n,1);
// 入力自動生成終わり
// debug(i);
vector<char> ball(n + 1, 0); // 入れた位置をtrueに
lint ballnum = 0;
// debug(9991);
for (lint k = n; k >= 1; k--) {
// debug(k);
lint sumb = 0;
// 倍数の探索
for (lint j = k; j <= n; j += k) {
sumb += ball[j];
}
// debug(a[k-1]);
// debug(sumb);
// debug((sumb + a[k-1])%2);
// if(k == 5000)
// {
// debug(sumb);
// debug(a[k-1]);
// }
ball[k] = (sumb + a[k - 1]) % 2; // 入れたり入れなかったり
ballnum += ball[k];
}
// debug(9992);
cout << ballnum << endl;
rep(i, n) {
if (ball[i + 1] == 1)
cout << i + 1 << " ";
}
if (ballnum > 0)
cout << endl;
// debug(ball);
// 昇順ソート
// sort(all(a));
// sort(input.begin() , input.end());
// uint64_t max = numeric_limits<uint64_t>::max();
//////////////////////////////////////////////////////
// DP
// // 無限大の値
// const uint64_t INF = (uint64_t)1 << 60;
// //const int64_t NINF = -1 * ((int64_t)1 << 60 );
// // DP テーブル
// uint64_t dp[100010];
// //DPテーブル初期化(最小化用)
// for (int i = 0; i < 100010; ++i)
// {
// //dp[i] = INF;
// dp[i] = 0;
// }
// // 初期条件
// dp[0] = 0;
// // ループ
// for (int i = 1; i <= n; ++i) {
// //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
// //if (i < 2)continue;
// //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));
// // chmax ( dp [i] , dp[i - 1]);
// // chmax ( dp [i] , dp[i - 1] + input[i]);
// // cout << "dp[" << i <<"] = " << dp[i] << endl;
// }
// //////////////////////////////////////////////////////
// cout << dp[n] << endl;
//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
return 0;
}
// 最小化用関数
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;
}
// vectorprint用
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
// //合計
// template<class T> lint sum(vector<T> a)
// {
// return std::accumulate(a.begin(), a.end(), 0);
// }
// //平均
// template<class T> double ave(vector<T> a)
// {
// return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }
| replace | 44 | 45 | 44 | 45 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
int main() {
ll n;
cin >> n;
vector<ll> a(n + 1);
a[0] = -1;
for (ll i = 1; i <= n; i++)
cin >> a[i];
vector<ll> b(n + 1);
b[0] = -1;
for (ll i = n; i >= n / 2 + 1; i--)
b[i] = a[i];
for (ll i = n / 2; i >= 1; i--) {
int g = 2, t = 0;
ll j = i;
while (j <= n) {
j = i;
j *= g;
if (b[j] == 1)
t++;
g++;
}
if (t % 2 == a[i])
b[i] = 0;
else
b[i] = 1;
}
ll count = 0;
for (ll i = 1; i <= n; i++) {
if (b[i] == 1)
count++;
}
cout << count << endl;
for (ll i = 1; i <= n; i++) {
if (b[i] == 1)
cout << i << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
int main() {
ll n;
cin >> n;
vector<ll> a(n + 1);
a[0] = -1;
for (ll i = 1; i <= n; i++)
cin >> a[i];
vector<ll> b(n + 1);
b[0] = -1;
for (ll i = n; i >= n / 2 + 1; i--)
b[i] = a[i];
for (ll i = n / 2; i >= 1; i--) {
int g = 2, t = 0;
ll j = i;
while (1) {
ll h = j * g;
if (h > n)
break;
if (b[h] == 1)
t++;
g++;
}
if (t % 2 == a[i])
b[i] = 0;
else
b[i] = 1;
}
ll count = 0;
for (ll i = 1; i <= n; i++) {
if (b[i] == 1)
count++;
}
cout << count << endl;
for (ll i = 1; i <= n; i++) {
if (b[i] == 1)
cout << i << endl;
}
} | replace | 22 | 26 | 22 | 27 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
int main() {
ll n;
cin >> n;
vll vec(n);
REP(i, n) cin >> vec.at(i);
vll ans(n);
for (int i = n - 1; i >= 0; i--) {
ll total = 0;
for (int j = i + 1; j <= n; j += i + 1) {
total += ans.at(j);
}
if (vec.at(i) != total % 2)
ans.at(i) = 1;
}
cout << count(ALL(ans), 1) << endl;
if (count(ALL(ans), 1) == 0) {
return 0;
}
vll out;
REP(i, n) {
if (ans.at(i) == 1)
out.push_back(i + 1);
}
REP(i, out.size() - 1) { cout << out.at(i) << " "; }
cout << out.at(out.size() - 1) << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
int main() {
ll n;
cin >> n;
vll vec(n);
REP(i, n) cin >> vec.at(i);
vll ans(n);
for (int i = n - 1; i >= 0; i--) {
ll total = 0;
for (int j = i + 1; j <= n; j += i + 1) {
total += ans.at(j - 1);
}
if (vec.at(i) != total % 2)
ans.at(i) = 1;
}
cout << count(ALL(ans), 1) << endl;
if (count(ALL(ans), 1) == 0) {
return 0;
}
vll out;
REP(i, n) {
if (ans.at(i) == 1)
out.push_back(i + 1);
}
REP(i, out.size() - 1) { cout << out.at(i) << " "; }
cout << out.at(out.size() - 1) << endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02972 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a - MOD);
}
int a[100100], b[100100];
vector<int> ans;
int main(void) {
int n, i, j, t, m;
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> a[i];
}
for (i = n; i > 0; --i) {
t = 0;
for (j = i * 2; j <= n; j += i) {
t += b[j];
}
t %= 2;
b[i] = (t ^ a[i]);
}
for (i = 1; i <= n; ++i) {
if (b[i]) {
ans.push_back(i);
}
}
m = ans.l_ength();
cout << m << endl;
if (!m) {
return 0;
}
for (i = 0; i < m; ++i) {
cout << ((i) ? " " : "") << ans[i];
}
cout << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a - MOD);
}
int a[225816], b[225816];
vector<int> ans;
int main(void) {
int n, i, j, t, m;
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> a[i];
}
for (i = n; i > 0; --i) {
t = 0;
for (j = i * 2; j <= n; j += i) {
t += b[j];
}
t %= 2;
b[i] = (t ^ a[i]);
}
for (i = 1; i <= n; ++i) {
if (b[i]) {
ans.push_back(i);
}
}
m = ans.l_ength();
cout << m << endl;
if (!m) {
return 0;
}
for (i = 0; i < m; ++i) {
cout << ((i) ? " " : "") << ans[i];
}
cout << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
vector<int> divisor(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;
cin >> n;
vector<int> la(n);
la[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> la[i];
}
vector<int> ans;
for (int i = n; i > 0; --i) {
if (la[i] == 0)
continue;
ans.push_back(i);
vector<int> div = divisor(i);
for (int d : div) {
la[d] = 1 - la[d];
}
}
cout << ans.size() << endl;
for (int a : ans) {
cout << a << " ";
}
cout << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
vector<int> divisor(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;
cin >> n;
vector<int> la(n + 1);
la[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> la[i];
}
vector<int> ans;
for (int i = n; i > 0; --i) {
if (la[i] == 0)
continue;
ans.push_back(i);
vector<int> div = divisor(i);
for (int d : div) {
la[d] = 1 - la[d];
}
}
cout << ans.size() << endl;
for (int a : ans) {
cout << a << " ";
}
cout << endl;
}
| replace | 51 | 52 | 51 | 52 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int a[200001] = {};
int b[200001] = {};
int main() {
long N;
cin >> N;
for (long i = 1; i <= N; i++) {
cin >> a[i];
}
long M = 0;
if (a[N] == 1) {
M++;
b[N] = 1;
}
for (long i = N - 1; i >= 1; i--) {
long c = 0;
for (long j = i; j <= N; j++) {
if (j % i == 0 && b[j] == 1)
c++;
}
if (c % 2 != a[i]) {
b[i] = 1;
M++;
}
}
cout << M << endl;
if (M != 0) {
for (long i = 1; i <= N; i++) {
if (b[i] == 1)
cout << i << " ";
}
cout << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int a[200001] = {};
int b[200001] = {};
int main() {
long N;
cin >> N;
for (long i = 1; i <= N; i++) {
cin >> a[i];
}
long M = 0;
if (a[N] == 1) {
M++;
b[N] = 1;
}
for (long i = N - 1; i >= 1; i--) {
long c = 0;
for (long j = i; j <= N; j += i) {
if (b[j] == 1)
c++;
}
if (c % 2 != a[i]) {
b[i] = 1;
M++;
}
}
cout << M << endl;
if (M != 0) {
for (long i = 1; i <= N; i++) {
if (b[i] == 1)
cout << i << " ";
}
cout << endl;
}
return 0;
} | replace | 19 | 21 | 19 | 21 | TLE | |
p02972 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
auto a = vec(int, n);
rep(i, n + 1) {
if (i == 0)
a[0] = 0;
else
cin >> a[i];
}
auto b = vec(int, n + 1);
int i = n;
int sum = 0;
while (i) {
if (n < 2 * i)
b[i] = a[i];
else if (n >= 2 * i && i > 1) {
int memo = 0, j = 2;
while (n >= i * j) {
memo += b[i * j];
j++;
}
b[i] = (memo + a[i]) % 2;
} else
b[1] = (a[1] + sum) % 2;
sum += b[i];
i--;
}
cout << sum << endl;
REP(i, 1, n) if (b[i]) cout << i << " ";
}
| #include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
auto a = vec(int, n + 1);
REP(i, 1, n) cin >> a[i];
auto b = vec(int, n + 1);
int i = n;
int sum = 0;
while (i) {
if (n < 2 * i)
b[i] = a[i];
else if (n >= 2 * i && i > 1) {
int memo = 0, j = 2;
while (n >= i * j) {
memo += b[i * j];
j++;
}
b[i] = (memo + a[i]) % 2;
} else
b[1] = (a[1] + sum) % 2;
sum += b[i];
i--;
}
cout << sum << endl;
REP(i, 1, n) if (b[i]) cout << i << " ";
}
| replace | 36 | 43 | 36 | 38 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> res(n + 1), a(n);
int cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a.at(i);
if (i >= n / 2) {
res.at(i + 1) = a.at(i);
if (res.at(i + 1) == 1)
cnt++;
}
}
for (int i = n / 2; i > 0; i--) {
int cnt1 = 2;
while (cnt1 * i <= n) {
res.at(i) += res.at(i * cnt1);
cnt1++;
res.at(i) %= 2;
}
if ((a.at(i - 1) + res.at(i)) % 2 == 0)
res.at(i) = 0;
else {
res.at(i) = 1;
cnt++;
}
}
cout << cnt << endl;
for (int i = 1; i <= 10; i++) {
if (res.at(i))
cout << i << " ";
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> res(n + 1), a(n);
int cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a.at(i);
if (i >= n / 2) {
res.at(i + 1) = a.at(i);
if (res.at(i + 1) == 1)
cnt++;
}
}
for (int i = n / 2; i > 0; i--) {
int cnt1 = 2;
while (cnt1 * i <= n) {
res.at(i) += res.at(i * cnt1);
cnt1++;
res.at(i) %= 2;
}
if ((a.at(i - 1) + res.at(i)) % 2 == 0)
res.at(i) = 0;
else {
res.at(i) = 1;
cnt++;
}
}
cout << cnt << endl;
for (int i = 1; i <= n; i++) {
if (res.at(i))
cout << i << " ";
}
} | replace | 31 | 32 | 31 | 32 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p02972 | C++ | Runtime Error | // C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;
// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
// alias declaration
using ll = long long;
using str = string;
using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;
// loops
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]
// for debug
#define dbg(a) cerr << " " << (#a) << ": " << (a) << "\n";
// procon common constants
const ll MOD_BIG = 1e9 + 7;
int main(void) {
ll N;
cin >> N;
vll a(N + 1), b(N + 1);
a[0] = 0;
b[0] = 0;
bool f;
FOR(i, 1, N) { cin >> a[i]; }
// b[N/2+1] ~ b[N]は確定
FOR(i, N / 2 + 1, N) { b[i] = a[i]; }
rFOR(i, N / 2, 1) {
f = 0;
FOR(j, 2, N / i) { f ^= a[j * i]; }
b[i] = !f;
}
ll balls = count(b.begin(), b.end(), 1);
cout << balls << endl;
if (balls > 0) {
FOR(i, 1, N) {
if (b[i] == 1) {
cout << i << endl;
}
}
}
} | // C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;
// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
// alias declaration
using ll = long long;
using str = string;
using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;
// loops
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]
// for debug
#define dbg(a) cerr << " " << (#a) << ": " << (a) << "\n";
// procon common constants
const ll MOD_BIG = 1e9 + 7;
int main(void) {
ll N;
cin >> N;
vll a(N + 1), b(N + 1);
a[0] = 0;
b[0] = 0;
bool f;
FOR(i, 1, N) { cin >> a[i]; }
if (N > 2) {
// b[N/2+1] ~ b[N]は確定
FOR(i, N / 2 + 1, N) { b[i] = a[i]; }
// puts("a");
rFOR(i, 1, N / 2) {
f = 0;
FOR(j, 2, N / i) { f ^= b[j * i]; }
b[i] = f ^ a[i];
// cout << "b[" << i << "]=" << b[i] << endl;;
}
} else if (N == 1) {
b[1] = a[1];
} else { // N==2
b[2] = a[2];
b[1] = a[1] ^ a[2];
}
ll balls = count(b.begin(), b.end(), 1);
cout << balls << endl;
if (balls > 0) {
FOR(i, 1, N) {
if (b[i] == 1) {
cout << i << endl;
}
}
}
} | replace | 36 | 42 | 36 | 51 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
vector<int> A(N, 0);
// reverse(a.begin(),a.end());
int tmp = 0;
for (int i = 0; i < N; i++) {
int j = N - i - 1;
tmp = 0;
for (int l = 1; l <= N % (j + 1); l++) {
int L = l * (j + 1);
tmp += A.at(L - 1);
}
tmp = tmp % 2;
if (tmp != a.at(j)) {
A.at(j) = 1;
}
}
int ans = accumulate(A.begin(), A.end(), 0);
cout << ans << endl;
for (int i = 0; i < N; i++) {
if (A.at(i) == 1) {
if (ans != 1) {
cout << i + 1 << " ";
} else {
cout << i + 1 << endl;
}
ans -= 1;
}
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
vector<int> A(N, 0);
// reverse(a.begin(),a.end());
int tmp = 0;
for (int i = 0; i < N; i++) {
int j = N - i - 1;
tmp = 0;
for (int l = 1; l <= N / (j + 1); l++) {
int L = l * (j + 1);
tmp += A.at(L - 1);
}
tmp = tmp % 2;
if (tmp != a.at(j)) {
A.at(j) = 1;
}
}
int ans = accumulate(A.begin(), A.end(), 0);
cout << ans << endl;
for (int i = 0; i < N; i++) {
if (A.at(i) == 1) {
if (ans != 1) {
cout << i + 1 << " ";
} else {
cout << i + 1 << endl;
}
ans -= 1;
}
}
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i > ll(b); i--)
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
// sort(a, a + N, greater<ll>()) // descend
// sort(a, a+N) // ascend
/*
void comb(vector<vector <ll> > &v) {
ll mod=1000000007;
rep (i,0,v.size()) {
v[i][0] = 1;
v[i][i] = 1;
}
rep (k,1,v.size()) {
rep (j,1,k) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
}
}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/
int main() {
ll n;
cin >> n;
ll a[220000];
rep(i, 1, n + 1) cin >> a[i];
ll b[220000] = {0};
ll cnt = 0;
ll m = 0;
irep(i, n, 0) {
irep(j, n, i) {
if (j % i == 0)
cnt += b[j];
}
cnt = cnt % 2;
if (a[i] != cnt) {
b[i] = 1;
m++;
}
cnt = 0;
}
cout << m << endl;
rep(i, 1, n + 1) if (b[i] == 1) cout << i << endl;
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i > ll(b); i--)
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
// sort(a, a + N, greater<ll>()) // descend
// sort(a, a+N) // ascend
/*
void comb(vector<vector <ll> > &v) {
ll mod=1000000007;
rep (i,0,v.size()) {
v[i][0] = 1;
v[i][i] = 1;
}
rep (k,1,v.size()) {
rep (j,1,k) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
}
}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/
int main() {
ll n;
cin >> n;
ll a[220000];
rep(i, 1, n + 1) cin >> a[i];
ll b[220000] = {0};
ll cnt = 0;
ll m = 0;
irep(i, n, 0) {
for (ll j = i; j <= n; j += i)
cnt += b[j];
cnt = cnt % 2;
if (a[i] != cnt) {
b[i] = 1;
m++;
}
cnt = 0;
}
cout << m << endl;
rep(i, 1, n + 1) if (b[i] == 1) cout << i << endl;
}
| replace | 37 | 41 | 37 | 39 | TLE | |
p02972 | C++ | Runtime Error | #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;
#ifndef bhartiya
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target
// ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
// not that imp
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)
#define pb push_back
#define bitc __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar))
#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
int begtime = clock();
#define end_routine() \
cout << "\n\nTime elapsed: " << (clock() - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll modpow(ll b, ll e) {
ll ans = 1;
for (; e; b = b * b % mod, e /= 2)
if (e & 1)
ans = ans * b % mod;
return ans;
}
const int maxn = 100005;
vi factors[maxn];
int cnt[maxn], a[maxn];
vi ans;
void solve() {
fr(i, 1, maxn - 1) {
for (int j = i; j < maxn; j += i) {
factors[j].pb(i);
}
}
int n;
cin >> n;
fr(i, 1, n) cin >> a[i];
frr(i, n, 1) {
if (cnt[i] % 2 != a[i]) {
for (auto ch : factors[i]) {
cnt[ch]++;
}
ans.pb(i);
}
if (cnt[i] % 2 != a[i]) {
cout << "-1";
return;
}
}
cout << sz(ans) << endl;
for (auto ch : ans) {
cout << ch << " ";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0), cout.precision(10); // cout<<fixed;
cin.exceptions(cin.failbit);
#ifdef bhartiya
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
end_routine();
} | #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;
#ifndef bhartiya
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target
// ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
// not that imp
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)
#define pb push_back
#define bitc __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar))
#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
int begtime = clock();
#define end_routine() \
cout << "\n\nTime elapsed: " << (clock() - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll modpow(ll b, ll e) {
ll ans = 1;
for (; e; b = b * b % mod, e /= 2)
if (e & 1)
ans = ans * b % mod;
return ans;
}
const int maxn = 300005;
vi factors[maxn];
int cnt[maxn], a[maxn];
vi ans;
void solve() {
fr(i, 1, maxn - 1) {
for (int j = i; j < maxn; j += i) {
factors[j].pb(i);
}
}
int n;
cin >> n;
fr(i, 1, n) cin >> a[i];
frr(i, n, 1) {
if (cnt[i] % 2 != a[i]) {
for (auto ch : factors[i]) {
cnt[ch]++;
}
ans.pb(i);
}
if (cnt[i] % 2 != a[i]) {
cout << "-1";
return;
}
}
cout << sz(ans) << endl;
for (auto ch : ans) {
cout << ch << " ";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0), cout.precision(10); // cout<<fixed;
cin.exceptions(cin.failbit);
#ifdef bhartiya
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
end_routine();
} | replace | 79 | 80 | 79 | 80 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
ll N;
cin >> N;
vector<int> a(N + 1);
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
vector<int> box(N);
ll ans = 0;
vector<ll> ans_arr;
for (ll i = N / 2 + 1; i <= N; i++) {
box[i] = a[i];
if (box[i] == 1) {
ans++;
ans_arr.push_back(i);
}
}
for (ll i = N / 2; i > 0; i--) {
ll ball_num = 0;
ll loop_count = N / i;
for (ll j = 2; j <= loop_count; j++) {
if (box[i * j] == 1) {
ball_num++;
}
}
if (ball_num % 2 == a[i]) {
box[i] = 0;
} else {
box[i] = 1;
ans++;
ans_arr.push_back(i);
}
}
sort(ans_arr.begin(), ans_arr.end());
cout << ans << endl;
ll arr_size = ans_arr.size();
for (ll i = 0; i < arr_size; i++) {
if (i != arr_size - 1) {
cout << ans_arr[i] << " ";
} else {
cout << ans_arr[i] << endl;
}
}
// for(int bit = 0; bit < (1 << N); bit++)
// {
// ll ans = 0;
// vector<ll> ans_arr;
// bool isAns = true;
// for(int i = 1; i <= N; i++)
// {
// ll loop_count = N / i;
// ll ball_count = 0;
// for (int j = 1; j <= loop_count; j++)
// {
// if (bit & (1 << i * j - 1))
// {
// ball_count++;
// if(i == 1)
// {
// ans++;
// ans_arr.push_back(j);
// }
// }
// }
// if(ball_count % 2 != a[i - 1])
// {
// isAns = false;
// break;
// }
// }
// if (isAns)
// {
// cout << ans << endl;
// for (int i = 0; i < ans_arr.size(); i++)
// {
// if (i != ans_arr.size() - 1)
// {
// cout << ans_arr[i] << " ";
// }
// else
// {
// cout << ans_arr[i] << endl;
// }
// }
// return 0;
// }
// }
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
ll N;
cin >> N;
vector<int> a(N + 1);
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
vector<int> box(N + 1);
ll ans = 0;
vector<ll> ans_arr;
for (ll i = N / 2 + 1; i <= N; i++) {
box[i] = a[i];
if (box[i] == 1) {
ans++;
ans_arr.push_back(i);
}
}
for (ll i = N / 2; i > 0; i--) {
ll ball_num = 0;
ll loop_count = N / i;
for (ll j = 2; j <= loop_count; j++) {
if (box[i * j] == 1) {
ball_num++;
}
}
if (ball_num % 2 == a[i]) {
box[i] = 0;
} else {
box[i] = 1;
ans++;
ans_arr.push_back(i);
}
}
sort(ans_arr.begin(), ans_arr.end());
cout << ans << endl;
ll arr_size = ans_arr.size();
for (ll i = 0; i < arr_size; i++) {
if (i != arr_size - 1) {
cout << ans_arr[i] << " ";
} else {
cout << ans_arr[i] << endl;
}
}
// for(int bit = 0; bit < (1 << N); bit++)
// {
// ll ans = 0;
// vector<ll> ans_arr;
// bool isAns = true;
// for(int i = 1; i <= N; i++)
// {
// ll loop_count = N / i;
// ll ball_count = 0;
// for (int j = 1; j <= loop_count; j++)
// {
// if (bit & (1 << i * j - 1))
// {
// ball_count++;
// if(i == 1)
// {
// ans++;
// ans_arr.push_back(j);
// }
// }
// }
// if(ball_count % 2 != a[i - 1])
// {
// isAns = false;
// break;
// }
// }
// if (isAns)
// {
// cout << ans << endl;
// for (int i = 0; i < ans_arr.size(); i++)
// {
// if (i != ans_arr.size() - 1)
// {
// cout << ans_arr[i] << " ";
// }
// else
// {
// cout << ans_arr[i] << endl;
// }
// }
// return 0;
// }
// }
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int, int> II;
typedef tuple<int, int, int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int, int> MAPII;
typedef unordered_set<int> SETI;
template <class T> using VV = vector<vector<T>>;
// minmax
template <class T> inline T SMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
template <class T> inline T SMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
// repetition
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define REPE(i, n) for (int i = 0; i <= (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FORR(x, arr) for (auto &x : arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(), (c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args), putchar('\n');
// debug cerr
template <class Iter> void __kumaerrc(Iter begin, Iter end) {
for (; begin != end; ++begin) {
cerr << *begin << ',';
}
cerr << endl;
}
void __kumaerr(istream_iterator<string> it) {
(void)it;
cerr << endl;
}
template <typename T, typename... Args>
void __kumaerr(istream_iterator<string> it, T a, Args... args) {
cerr << *it << "=" << a << ", ", __kumaerr(++it, args...);
}
template <typename S, typename T>
std::ostream &operator<<(std::ostream &_os, const std::pair<S, T> &_p) {
return _os << "{" << _p.first << ',' << _p.second << "}";
}
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
__kumaerr(_it, args); \
}
#define dumpc(ar) \
{ \
cerr << #ar << ": "; \
FORR(x, (ar)) { cerr << x << ','; } \
cerr << endl; \
}
#define dumpC(beg, end) \
{ \
cerr << "~" << #end << ": "; \
__kumaerrc(beg, end); \
}
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg, end)
#endif
// $ cp-batch PreparingBoxes | diff PreparingBoxes.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address
// PreparingBoxes.cpp && ./a.out
/*
7/20/2019
5:12-5:28 WA
8:35 AC
*/
const int MAX_N = 1e6 + 1;
int A[MAX_N];
int N;
int X[MAX_N];
void solve() {
ZERO(X);
int sufn = (N + 1) / 2;
int i = N;
while (sufn--) {
X[i] = A[i];
--i;
}
while (i >= 1) {
int sum = 0;
for (int j = 2 * i; j <= N; j += i)
sum += X[j];
X[i] = sum ^ A[i];
--i;
}
// dumpC(X+1,X+N+1);
FORE(i, 1, N) {
int sum = 0;
for (int j = i; j <= N; j += i)
sum ^= X[j];
// dump(i,A[i],sum);
assert(A[i] == sum);
}
VI res;
FORE(i, 1, N) if (X[i]) res.push_back(i);
println("%d", SZ(res));
REP(i, SZ(res)) println("%d", res[i]);
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int genRandNum(int lb, int ub) {
assert(lb < ub);
// Helper to generate random integer in range [lb, ub)
int x = rnd() % (int)(ub - lb);
return x + lb;
}
vector<int> genRandSeq(int size, int lb, int ub) {
if (size == 0)
return {};
vector<int> res(size);
generate(res.begin(), res.end(), [&]() { return genRandNum(lb, ub); });
return res;
}
void test() {
N = genRandNum(1, (int)2e5);
VI AA = genRandSeq(N, 0, 2);
REP(i, N) A[i + 1] = AA[i];
dumpc(AA);
solve();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(12) << fixed;
// while(true) test();
cin >> N;
REP(i, N) cin >> A[i + 1];
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int, int> II;
typedef tuple<int, int, int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int, int> MAPII;
typedef unordered_set<int> SETI;
template <class T> using VV = vector<vector<T>>;
// minmax
template <class T> inline T SMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
template <class T> inline T SMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
// repetition
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define REPE(i, n) for (int i = 0; i <= (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FORR(x, arr) for (auto &x : arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(), (c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args), putchar('\n');
// debug cerr
template <class Iter> void __kumaerrc(Iter begin, Iter end) {
for (; begin != end; ++begin) {
cerr << *begin << ',';
}
cerr << endl;
}
void __kumaerr(istream_iterator<string> it) {
(void)it;
cerr << endl;
}
template <typename T, typename... Args>
void __kumaerr(istream_iterator<string> it, T a, Args... args) {
cerr << *it << "=" << a << ", ", __kumaerr(++it, args...);
}
template <typename S, typename T>
std::ostream &operator<<(std::ostream &_os, const std::pair<S, T> &_p) {
return _os << "{" << _p.first << ',' << _p.second << "}";
}
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
__kumaerr(_it, args); \
}
#define dumpc(ar) \
{ \
cerr << #ar << ": "; \
FORR(x, (ar)) { cerr << x << ','; } \
cerr << endl; \
}
#define dumpC(beg, end) \
{ \
cerr << "~" << #end << ": "; \
__kumaerrc(beg, end); \
}
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg, end)
#endif
// $ cp-batch PreparingBoxes | diff PreparingBoxes.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address
// PreparingBoxes.cpp && ./a.out
/*
7/20/2019
5:12-5:28 WA
8:35 AC
*/
const int MAX_N = 1e6 + 1;
int A[MAX_N];
int N;
int X[MAX_N];
void solve() {
ZERO(X);
int sufn = (N + 1) / 2;
int i = N;
while (sufn--) {
X[i] = A[i];
--i;
}
while (i >= 1) {
int sum = 0;
for (int j = 2 * i; j <= N; j += i)
sum ^= X[j];
X[i] = sum ^ A[i];
--i;
}
// dumpC(X+1,X+N+1);
FORE(i, 1, N) {
int sum = 0;
for (int j = i; j <= N; j += i)
sum ^= X[j];
// dump(i,A[i],sum);
assert(A[i] == sum);
}
VI res;
FORE(i, 1, N) if (X[i]) res.push_back(i);
println("%d", SZ(res));
REP(i, SZ(res)) println("%d", res[i]);
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int genRandNum(int lb, int ub) {
assert(lb < ub);
// Helper to generate random integer in range [lb, ub)
int x = rnd() % (int)(ub - lb);
return x + lb;
}
vector<int> genRandSeq(int size, int lb, int ub) {
if (size == 0)
return {};
vector<int> res(size);
generate(res.begin(), res.end(), [&]() { return genRandNum(lb, ub); });
return res;
}
void test() {
N = genRandNum(1, (int)2e5);
VI AA = genRandSeq(N, 0, 2);
REP(i, N) A[i + 1] = AA[i];
dumpc(AA);
solve();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(12) << fixed;
// while(true) test();
cin >> N;
REP(i, N) cin >> A[i + 1];
solve();
return 0;
}
| replace | 107 | 108 | 107 | 108 | 0 | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int m = 0;
int main() {
int N;
cin >> N;
vector<int> a(N);
vector<int> b(N);
for (int i = 1; i <= N; i++) {
cin >> a[i];
b[i] = a[i];
}
for (int i = N; i >= 1; i--) {
for (int j = 2; j * i <= N; j++) {
b[i] += b[j * i];
}
}
for (int i = 1; i <= N; i++) {
b[i] = b[i] % 2;
}
for (int i = 1; i <= N; i++) {
m += b[i];
}
cout << m << endl;
for (int i = 1; i <= N; i++) {
if (b[i]) {
cout << i << " ";
}
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int m = 0;
int main() {
int N;
cin >> N;
vector<int> a(N + 1);
vector<int> b(N + 1);
for (int i = 1; i <= N; i++) {
cin >> a[i];
b[i] = a[i];
}
for (int i = N; i >= 1; i--) {
for (int j = 2; j * i <= N; j++) {
b[i] += b[j * i];
}
}
for (int i = 1; i <= N; i++) {
b[i] = b[i] % 2;
}
for (int i = 1; i <= N; i++) {
m += b[i];
}
cout << m << endl;
for (int i = 1; i <= N; i++) {
if (b[i]) {
cout << i << " ";
}
}
}
| replace | 9 | 11 | 9 | 11 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
const ll mod = 1e9 + 7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
int a[100001];
int d[100001];
vector<int> v;
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = 2; j * i <= n; j++)
sum += d[j * i];
d[i] = (a[i] ^ (sum % 2));
}
for (int i = 1; i <= n; i++) {
if (d[i])
v.push_back(i);
}
printf("%d\n", v.size());
for (int i = 0; i < v.size(); i++)
printf("%d ", v[i]);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
const ll mod = 1e9 + 7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
int a[200001];
int d[200001];
vector<int> v;
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i >= 1; i--) {
int sum = 0;
for (int j = 2; j * i <= n; j++)
sum += d[j * i];
d[i] = (a[i] ^ (sum % 2));
}
for (int i = 1; i <= n; i++) {
if (d[i])
v.push_back(i);
}
printf("%d\n", v.size());
for (int i = 0; i < v.size(); i++)
printf("%d ", v[i]);
return 0;
} | replace | 27 | 29 | 27 | 29 | 0 | |
p02972 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int out_print(vector<int> b, int N, int num) {
cout << num << endl;
if (num == 0)
return 0;
for (int i = 0; i < N; i++) {
if (b[i] == 1) {
cout << (i + 1) << " ";
}
}
return 0;
}
int is_odd(vector<int> b, int N, int k) {
int sum = 0;
for (int j = 1;; j++) {
int index = k * j;
if (index > N)
break;
sum += b[index - 1];
}
return sum % 2;
}
int main(void) {
int N;
cin >> N;
vector<int> a(N);
vector<int> b(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
b[i] = 0;
}
if (N == 1) {
b[N - 1] = a[N - 1];
out_print(b, N, b[N - 1]);
return 0;
}
int num = 0;
for (int i = N - 1; i >= 0; i--) {
int _is_odd = is_odd(b, N, i + 1);
b[i] = _is_odd ^ a[i];
num += b[i];
}
out_print(b, N, num);
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int out_print(vector<int> b, int N, int num) {
cout << num << endl;
if (num == 0)
return 0;
for (int i = 0; i < N; i++) {
if (b[i] == 1) {
cout << (i + 1) << " ";
}
}
return 0;
}
int is_odd(vector<int> b, int N, int k) {
int sum = 0;
for (int j = 1;; j++) {
int index = k * j;
if (index > N)
break;
sum += b[index - 1];
}
return sum % 2;
}
int main(void) {
int N;
cin >> N;
vector<int> a(N);
vector<int> b(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
b[i] = 0;
}
if (N == 1) {
b[N - 1] = a[N - 1];
out_print(b, N, b[N - 1]);
return 0;
}
int num = 0;
for (int i = N - 1; i >= 0; i--) {
int sum = 0;
for (int j = 1;; j++) {
int index = (i + 1) * j;
if (index > N)
break;
sum += b[index - 1];
}
b[i] = (sum % 2) ^ a[i];
num += b[i];
}
out_print(b, N, num);
return 0;
} | replace | 47 | 49 | 47 | 57 | TLE | |
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
int m;
cin >> m;
vector<int> v(m + 1);
for (int i = 1; i <= m; i++)
cin >> v[i];
vector<int> b(m + 1, 0);
// for(int i=1;i<=m;i++) cout<<v[i]<<" ";
// cout<<endl;
int cnt = 0;
for (int i = m; i > 0; i--) {
// cout<<endl;
// cout<<i<<"start"<<endl;
int sum = 0;
for (int j = m; j >= i; j--) {
if (j % i == 0) {
// cout<<j<<"baisu"<<endl;
sum += b[j];
}
}
if (v[i] == 0) {
// cout<<"0"<<endl;
if (sum % 2 == 0)
b[i] = 0;
else {
b[i] = 1;
cnt++;
}
} else {
// cout<<"1"<<endl;
if (sum % 2 == 0) {
b[i] = 1;
cnt++;
} else
b[i] = 0;
}
// cout<<sum<<endl;
// cout<<"v["<<i<<"]"<<"="<<v[i]<<endl;
}
if (cnt == 0)
cout << 0 << endl;
else {
cout << cnt << endl;
for (int i = 1; i <= m; i++) {
if (b[i] == 1)
cout << i << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
int m;
cin >> m;
vector<int> v(m + 1);
for (int i = 1; i <= m; i++)
cin >> v[i];
vector<int> b(m + 1, 0);
// for(int i=1;i<=m;i++) cout<<v[i]<<" ";
// cout<<endl;
int cnt = 0;
for (int i = m; i > 0; i--) {
// cout<<endl;
// cout<<i<<"start"<<endl;
int sum = 0;
for (int j = 2 * i; j <= m; j += i) {
if (j > m)
break;
if (b[j] == 1)
sum += 1;
}
if (v[i] == 0) {
// cout<<"0"<<endl;
if (sum % 2 == 0)
b[i] = 0;
else {
b[i] = 1;
cnt++;
}
} else {
// cout<<"1"<<endl;
if (sum % 2 == 0) {
b[i] = 1;
cnt++;
} else
b[i] = 0;
}
// cout<<sum<<endl;
// cout<<"v["<<i<<"]"<<"="<<v[i]<<endl;
}
if (cnt == 0)
cout << 0 << endl;
else {
cout << cnt << endl;
for (int i = 1; i <= m; i++) {
if (b[i] == 1)
cout << i << endl;
}
}
return 0;
} | replace | 24 | 29 | 24 | 29 | TLE | |
p02972 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 100100100;
using namespace std;
int main() {
int N;
int a[100001];
int c[100001];
int res = 0;
cin >> N;
rep(i, N) cin >> a[i + 1];
rep(i, N + 1) c[i] = 0;
for (int i = N; i > 0; i--) {
int j = 2;
int sum = 0;
while (j * i <= N) {
sum += c[j * i];
j++;
}
if (sum % 2 == a[i])
c[i] = 0;
else
c[i] = 1;
}
for (int i = 1; i <= N; i++) {
res += c[i];
}
cout << res << endl;
for (int i = 1; i <= N; i++) {
if (c[i] > 0)
cout << i << " ";
}
cout << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 100100100;
using namespace std;
int main() {
int N;
int a[200001];
int c[200001];
int res = 0;
cin >> N;
rep(i, N) cin >> a[i + 1];
rep(i, N + 1) c[i] = 0;
for (int i = N; i > 0; i--) {
int j = 2;
int sum = 0;
while (j * i <= N) {
sum += c[j * i];
j++;
}
if (sum % 2 == a[i])
c[i] = 0;
else
c[i] = 1;
}
for (int i = 1; i <= N; i++) {
res += c[i];
}
cout << res << endl;
for (int i = 1; i <= N; i++) {
if (c[i] > 0)
cout << i << " ";
}
cout << endl;
}
| replace | 7 | 9 | 7 | 9 | 0 | |
p02972 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
int main() {
// read problem
long long int N, tmp, factor;
std::vector<long long int> a, count, box;
scanf("%lld", &N);
for (long long int i = 0; i < N; i++) {
scanf("%lld", &tmp);
a.push_back(tmp);
count.push_back(0);
}
// solve problem
for (int i = N; i >= 1; i--) {
// if add an ball to i-th box
// if((a[i-1]^count[i-1])&1 != 0){
if ((a[i - 1] + count[i - 1] + 2) % 2 != 0) {
// update box
box.push_back(i);
// update count
for (factor = 1; factor * factor < i; factor++) {
if (i % factor == 0) {
count[factor - 1]++;
count[(i % factor) - 1]++;
}
}
if (factor * factor == i) {
count[factor - 1]++;
}
}
}
std::cerr << "Answer:" << std::endl;
std::cout << box.size() << std::endl;
for (int i = 0; i < box.size(); i++) {
std::cout << box[i] << " ";
}
std::cerr << std::endl;
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
int main() {
// read problem
long long int N, tmp, factor;
std::vector<long long int> a, count, box;
scanf("%lld", &N);
for (long long int i = 0; i < N; i++) {
scanf("%lld", &tmp);
a.push_back(tmp);
count.push_back(0);
}
// solve problem
for (int i = N; i >= 1; i--) {
// if add an ball to i-th box
// if((a[i-1]^count[i-1])&1 != 0){
if ((a[i - 1] + count[i - 1] + 2) % 2 != 0) {
// update box
box.push_back(i);
// update count
for (factor = 1; factor * factor < i; factor++) {
if (i % factor == 0) {
count[factor - 1]++;
count[(i / factor) - 1]++;
}
}
if (factor * factor == i) {
count[factor - 1]++;
}
}
}
std::cerr << "Answer:" << std::endl;
std::cout << box.size() << std::endl;
for (int i = 0; i < box.size(); i++) {
std::cout << box[i] << " ";
}
std::cerr << std::endl;
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | Answer:
|
p02972 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using cint = cpp_int;
*/
// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
// const ll INF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
#define modulo(a) ((a % mod + mod) % mod)
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
// Debug
#define debug(...) \
{ \
cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \
for (auto &&X : {__VA_ARGS__}) \
cerr << "[" << X << "] "; \
cerr << endl; \
}
#define dump(a, h, w) \
{ \
cerr << __LINE__ << ": " << #a << " = [" << endl; \
rep(__i, h) { \
rep(__j, w) cerr << a[__i][__j] << space; \
cerr << endl; \
} \
cerr << "]" << endl; \
}
#define vdump(a, n) \
{ \
cerr << __LINE__ << ": " << #a << " = ["; \
rep(__i, n) if (__i) cerr << space << a[__i]; \
else cerr << a[__i]; \
cerr << "]" << endl; \
}
struct edge {
ll to, cost;
edge(ll a, ll b) : to(a), cost(b) {}
};
struct position {
ll x, y;
position() {}
position(ll a, ll b) : x(a), y(b) {}
position next(ll i) { return {x + dx[i], y + dy[i]}; }
ll mdist() { return abs(x) + abs(y); }
double dist() { return sqrt(x * x + y * y); }
double norm(ll d) {
if (d == inf)
return max(x, y);
if (d == 1)
return mdist();
if (d == 2)
return dist();
return 0;
}
ll num(ll width) { return abs(x) * width + abs(y); }
bool operator==(position a) { return x == a.x && y == a.y; }
bool operator!=(position a) { return x != a.x || y != a.y; }
bool operator<(position a) { return x < a.x && y < a.y; }
bool operator>(position a) { return x > a.x && y > a.y; }
bool operator<=(position a) { return x <= a.x && y <= a.y; }
bool operator>=(position a) { return x >= a.x && y >= a.y; }
position operator+(position a) { return position(x + a.x, y + a.y); }
position operator-(position a) { return position(x - a.x, y - a.y); }
position operator*(position a) { return position(x * a.x, y * a.y); }
position operator/(position a) { return position(x / a.x, y / a.y); }
position operator%(position a) { return position(x % a.x, y % a.y); }
position complex(position a) {
return position(x * a.x - y * a.y, x * a.y + y * a.x);
}
/*
// for sort:
bool operator<(position a) { return x ^ a.x ? x < a.x : y < a.y; }
bool operator>(position a) { return x ^ a.x ? x > a.x : y > a.y; }
bool operator<=(position a) { return x ^ a.x ? x < a.x : y <= a.y; }
bool operator>=(position a) { return x ^ a.x ? x > a.x : y >= a.y; }
*/
};
position Origin = position(0, 0);
using pos = position;
using vec = position;
struct Range {
ll left, right;
Range() {}
Range(ll l, ll r) : left(l), right(r) {}
ll length() { return right - left; }
bool operator==(Range A) { return left == A.left && right == A.right; }
bool operator!=(Range A) { return !(Range(left, right) == A); }
bool operator>(Range A) { return left < A.left && right > A.right; }
bool operator<(Range A) { return left > A.left && right < A.right; }
bool operator>=(Range A) { return left <= A.left && right >= A.right; }
bool operator<=(Range A) { return left >= A.left && right <= A.right; }
};
// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)
// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
// Speed
run(0) { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// Gen-Test
#define RAND(a) \
{ \
random_device rnd; \
mt19937_64 a(rnd()); \
}
#define warning(A) \
if (!(A)) \
return 1
#define sin(a, b) ifstream a(b);
#define sout(a, b) ofstream a(b);
// Math
// #define gcd __gcd
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }
template <class T> def in() {
T A;
cin >> A;
return A;
}
template <class T>
def out(vector<vector<T>> A, ll H, ll W, char divc = space, char endc = endl) {
rep(i, H) {
rep(j, W) {
if (j)
cout << divc << A[i][j];
else
cout << A[i][j];
}
cout << endc;
}
}
ll N, A[200000];
vector<ll> B(200000, -1);
ll num(ll n) {
if (B[n - 1] != -1)
return B[n - 1];
ll res = 0;
for (ll i = n * 2; i <= N; i += n) {
res ^= num(i);
}
return res ^ A[n - 1];
}
signed main() {
cin >> N;
vector<ll> P;
rep(i, N) cin >> A[i];
rep(i, N) if (num(i + 1)) P.pb(i + 1);
cout << P.size() << endl;
if (P.size()) {
rep(i, P.size()) {
if (i)
cout << space << P[i];
else
cout << P[i];
}
cout << endl;
}
}
// 今年残り 325AC
// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++20 | #include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using cint = cpp_int;
*/
// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
// const ll INF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
#define modulo(a) ((a % mod + mod) % mod)
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
// Debug
#define debug(...) \
{ \
cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \
for (auto &&X : {__VA_ARGS__}) \
cerr << "[" << X << "] "; \
cerr << endl; \
}
#define dump(a, h, w) \
{ \
cerr << __LINE__ << ": " << #a << " = [" << endl; \
rep(__i, h) { \
rep(__j, w) cerr << a[__i][__j] << space; \
cerr << endl; \
} \
cerr << "]" << endl; \
}
#define vdump(a, n) \
{ \
cerr << __LINE__ << ": " << #a << " = ["; \
rep(__i, n) if (__i) cerr << space << a[__i]; \
else cerr << a[__i]; \
cerr << "]" << endl; \
}
struct edge {
ll to, cost;
edge(ll a, ll b) : to(a), cost(b) {}
};
struct position {
ll x, y;
position() {}
position(ll a, ll b) : x(a), y(b) {}
position next(ll i) { return {x + dx[i], y + dy[i]}; }
ll mdist() { return abs(x) + abs(y); }
double dist() { return sqrt(x * x + y * y); }
double norm(ll d) {
if (d == inf)
return max(x, y);
if (d == 1)
return mdist();
if (d == 2)
return dist();
return 0;
}
ll num(ll width) { return abs(x) * width + abs(y); }
bool operator==(position a) { return x == a.x && y == a.y; }
bool operator!=(position a) { return x != a.x || y != a.y; }
bool operator<(position a) { return x < a.x && y < a.y; }
bool operator>(position a) { return x > a.x && y > a.y; }
bool operator<=(position a) { return x <= a.x && y <= a.y; }
bool operator>=(position a) { return x >= a.x && y >= a.y; }
position operator+(position a) { return position(x + a.x, y + a.y); }
position operator-(position a) { return position(x - a.x, y - a.y); }
position operator*(position a) { return position(x * a.x, y * a.y); }
position operator/(position a) { return position(x / a.x, y / a.y); }
position operator%(position a) { return position(x % a.x, y % a.y); }
position complex(position a) {
return position(x * a.x - y * a.y, x * a.y + y * a.x);
}
/*
// for sort:
bool operator<(position a) { return x ^ a.x ? x < a.x : y < a.y; }
bool operator>(position a) { return x ^ a.x ? x > a.x : y > a.y; }
bool operator<=(position a) { return x ^ a.x ? x < a.x : y <= a.y; }
bool operator>=(position a) { return x ^ a.x ? x > a.x : y >= a.y; }
*/
};
position Origin = position(0, 0);
using pos = position;
using vec = position;
struct Range {
ll left, right;
Range() {}
Range(ll l, ll r) : left(l), right(r) {}
ll length() { return right - left; }
bool operator==(Range A) { return left == A.left && right == A.right; }
bool operator!=(Range A) { return !(Range(left, right) == A); }
bool operator>(Range A) { return left < A.left && right > A.right; }
bool operator<(Range A) { return left > A.left && right < A.right; }
bool operator>=(Range A) { return left <= A.left && right >= A.right; }
bool operator<=(Range A) { return left >= A.left && right <= A.right; }
};
// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)
// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
// Speed
run(0) { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// Gen-Test
#define RAND(a) \
{ \
random_device rnd; \
mt19937_64 a(rnd()); \
}
#define warning(A) \
if (!(A)) \
return 1
#define sin(a, b) ifstream a(b);
#define sout(a, b) ofstream a(b);
// Math
// #define gcd __gcd
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }
template <class T> def in() {
T A;
cin >> A;
return A;
}
template <class T>
def out(vector<vector<T>> A, ll H, ll W, char divc = space, char endc = endl) {
rep(i, H) {
rep(j, W) {
if (j)
cout << divc << A[i][j];
else
cout << A[i][j];
}
cout << endc;
}
}
ll N, A[200000];
vector<ll> B(200000, -1);
ll num(ll n) {
if (B[n - 1] != -1)
return B[n - 1];
ll res = 0;
for (ll i = n * 2; i <= N; i += n) {
res ^= num(i);
}
return B[n - 1] = res ^ A[n - 1];
}
signed main() {
cin >> N;
vector<ll> P;
rep(i, N) cin >> A[i];
rep(i, N) if (num(i + 1)) P.pb(i + 1);
cout << P.size() << endl;
if (P.size()) {
rep(i, P.size()) {
if (i)
cout << space << P[i];
else
cout << P[i];
}
cout << endl;
}
}
// 今年残り 325AC
// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++20 | replace | 209 | 210 | 209 | 210 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.