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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template <class T> using VE = vector<T>;
template <class T> using P = pair<T, T>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define REP(i, k, n) for (int i = (k); i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define output(x, y) cout << fixed << setprecision(y) << x << endl;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
ll two[202020];
ll two2[202020];
ll two3[202020];
ll popcount(ll x) {
int res = 0;
for (; x > 0; x >>= 1)
res += (x & 1);
return res;
}
ll modpow(string s, int mod) {
ll res = 0;
ll now = 1;
rep(i, s.size()) {
if (s[i] == '1')
res = res + now % mod;
now = now * 2 % mod;
}
return res;
}
ll rem(ll x, int s) {
if (x == 0)
return s;
ll nxt = popcount(x);
if (nxt == 0)
return s;
return rem(x % nxt, s + 1);
}
int main() {
two[0] = 1;
two2[0] = 1;
two3[0] = 1;
int n;
string s;
cin >> n >> s;
reverse(all(s));
int ppcnt = 0;
rep(i, n) { ppcnt += s[i] - '0'; }
if (ppcnt == 0) {
rep(i, n) { cout << 1 << endl; }
return 0;
}
rep1(i, 200005) two[i] = (two[i - 1] * 2) % ppcnt;
rep1(i, 200005) two2[i] = (two2[i - 1] * 2) % (ppcnt + 1);
if (ppcnt != 1) {
rep1(i, 200005) two3[i] = (two3[i - 1] * 2) % (ppcnt - 1);
} else {
rep1(i, 200005) two3[i] = -1;
}
ll x = modpow(s, ppcnt);
ll x2 = modpow(s, ppcnt + 1);
ll x3 = (ppcnt != 0) ? modpow(s, ppcnt - 1) : -1;
// 割り算はlog回で収束しそう
V ans(n);
rep(i, n) {
int pc = ppcnt;
if (s[i] == '0') {
pc++;
if (pc == 1) {
ans[i] = 1;
continue;
}
ll tmp = (x2 + two2[i]) % pc;
if (tmp == 0)
ans[i] = 1;
else
ans[i] = rem(tmp, 1);
} else {
pc--;
if (pc == 1) {
ans[i] = 1;
continue;
} else if (pc == 0) {
ans[i] = 0;
continue;
}
ll tmp = (x3 - two3[i] + pc) % pc;
if (tmp == 0)
ans[i] = 1;
else
ans[i] = rem(tmp, 1);
}
}
reverse(all(ans));
rep(i, n) cout << ans[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template <class T> using VE = vector<T>;
template <class T> using P = pair<T, T>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define REP(i, k, n) for (int i = (k); i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define output(x, y) cout << fixed << setprecision(y) << x << endl;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
ll two[202020];
ll two2[202020];
ll two3[202020];
ll popcount(ll x) {
int res = 0;
for (; x > 0; x >>= 1)
res += (x & 1);
return res;
}
ll modpow(string s, int mod) {
ll res = 0;
ll now = 1;
rep(i, s.size()) {
if (s[i] == '1')
res = res + now % mod;
now = now * 2 % mod;
}
return res;
}
ll rem(ll x, int s) {
if (x == 0)
return s;
ll nxt = popcount(x);
if (nxt == 0)
return s;
return rem(x % nxt, s + 1);
}
int main() {
two[0] = 1;
two2[0] = 1;
two3[0] = 1;
int n;
string s;
cin >> n >> s;
reverse(all(s));
int ppcnt = 0;
rep(i, n) { ppcnt += s[i] - '0'; }
if (ppcnt == 0) {
rep(i, n) { cout << 1 << endl; }
return 0;
} else if (ppcnt == 1) {
V ans(n);
rep(i, n) {
if (s[i] == '1')
ans[i] = 0;
else {
if (s[0] == '1')
ans[i] = 2;
else {
if (i == 0)
ans[i] = 2;
else
ans[i] = 1;
}
}
}
reverse(all(ans));
rep(i, n) cout << ans[i] << endl;
return 0;
}
rep1(i, 200005) two[i] = (two[i - 1] * 2) % ppcnt;
rep1(i, 200005) two2[i] = (two2[i - 1] * 2) % (ppcnt + 1);
if (ppcnt != 1) {
rep1(i, 200005) two3[i] = (two3[i - 1] * 2) % (ppcnt - 1);
} else {
rep1(i, 200005) two3[i] = -1;
}
ll x = modpow(s, ppcnt);
ll x2 = modpow(s, ppcnt + 1);
ll x3 = (ppcnt != 0) ? modpow(s, ppcnt - 1) : -1;
// 割り算はlog回で収束しそう
V ans(n);
rep(i, n) {
int pc = ppcnt;
if (s[i] == '0') {
pc++;
if (pc == 1) {
ans[i] = 1;
continue;
}
ll tmp = (x2 + two2[i]) % pc;
if (tmp == 0)
ans[i] = 1;
else
ans[i] = rem(tmp, 1);
} else {
pc--;
if (pc == 1) {
ans[i] = 1;
continue;
} else if (pc == 0) {
ans[i] = 0;
continue;
}
ll tmp = (x3 - two3[i] + pc) % pc;
if (tmp == 0)
ans[i] = 1;
else
ans[i] = rem(tmp, 1);
}
}
reverse(all(ans));
rep(i, n) cout << ans[i] << endl;
return 0;
} | insert | 80 | 80 | 80 | 99 | 0 | |
p02609 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
int N;
cin >> N;
string X;
cin >> X;
vector<int> vu(N), vd(N), u(N), d(N);
int mod, modu, modd, uu, dd;
mod = bitset<200000>(X).count();
modu = mod + 1;
modd = mod - 1;
if (modd == 0) {
for (int i = 0; i < N - 1; i++) {
if (X[N - 1] == '1')
cout << 2 << endl;
else if (X[i] == '1')
cout << 0 << endl;
else
cout << 1 << endl;
}
if (X[N - 1] == '1')
cout << 0 << endl;
else
cout << 2 << endl;
} else {
int tmp, tmpu, tmpd;
tmpu = 1;
tmpd = 1;
u[N - 1] = 1;
d[N - 1] = 1;
if (X[N - 1] == '1') {
vu[0] = 1;
vd[0] = 1;
} else {
vu[0] = 0;
vd[0] = 0;
}
for (int i = N - 2; i >= 0; i--) {
tmpu = tmpu * 2 % modu;
tmpd = tmpd * 2 % modd;
if (X[i] == '1') {
vu[N - 1 - i] = (vu[N - 2 - i] + tmpu) % modu;
vd[N - 1 - i] = (vd[N - 2 - i] + tmpd) % modd;
} else {
vu[N - 1 - i] = vu[N - 2 - i];
vd[N - 1 - i] = vd[N - 2 - i];
}
u[i] = tmpu;
d[i] = tmpd;
}
uu = vu[N - 1];
dd = vd[N - 1];
int ans;
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
tmp = (dd + modd - d[i]) % modd;
} else {
tmp = (uu + u[i]) % modu;
}
ans = 1;
while (bitset<200000>(tmp).count() > 0) {
tmp = tmp % bitset<200000>(tmp).count();
ans++;
}
cout << ans << endl;
}
}
} | #include <algorithm>
#include <bitset>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
int N;
cin >> N;
string X;
cin >> X;
vector<int> vu(N), vd(N), u(N), d(N);
int mod, modu, modd, uu, dd;
mod = bitset<200000>(X).count();
modu = mod + 1;
modd = mod - 1;
if (modd == 0) {
for (int i = 0; i < N - 1; i++) {
if (X[N - 1] == '1')
cout << 2 << endl;
else if (X[i] == '1')
cout << 0 << endl;
else
cout << 1 << endl;
}
if (X[N - 1] == '1')
cout << 0 << endl;
else
cout << 2 << endl;
} else {
int tmp, tmpu, tmpd;
tmpu = 1;
tmpd = 1;
u[N - 1] = 1;
d[N - 1] = 1;
if (X[N - 1] == '1') {
vu[0] = 1;
vd[0] = 1;
} else {
vu[0] = 0;
vd[0] = 0;
}
for (int i = N - 2; i >= 0; i--) {
tmpu = tmpu * 2 % modu;
tmpd = tmpd * 2 % modd;
if (X[i] == '1') {
vu[N - 1 - i] = (vu[N - 2 - i] + tmpu) % modu;
vd[N - 1 - i] = (vd[N - 2 - i] + tmpd) % modd;
} else {
vu[N - 1 - i] = vu[N - 2 - i];
vd[N - 1 - i] = vd[N - 2 - i];
}
u[i] = tmpu;
d[i] = tmpd;
}
uu = vu[N - 1];
dd = vd[N - 1];
int ans;
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
tmp = (dd + modd - d[i]) % modd;
} else {
tmp = (uu + u[i]) % modu;
}
ans = 1;
while (__builtin_popcount(tmp) > 0) {
tmp = tmp % __builtin_popcount(tmp);
ans++;
}
cout << ans << endl;
}
}
} | replace | 73 | 75 | 73 | 75 | TLE | |
p02609 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
long long f(long long x) {
int cnt = 0;
for (int i = 0; i < 20; i++) {
cnt += (x >> i) & 1;
}
return x % cnt;
}
long long modpow(int p, long long m) {
long long ret = 1;
for (int i = 0; i < p; i++) {
ret = ret * 2 % m;
}
return ret;
}
int main() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
std::vector<long long> m(3), r(3);
for (int i = 0; i < n; i++)
m[1] += s[i] == '1';
m[0] = m[1] - 1;
m[2] = m[1] + 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (m[j] == 0)
continue;
r[j] = (r[j] * 2 + (s[i] == '1')) % m[j];
}
}
for (int i = 0; i < n; i++) {
int id = s[i] == '1' ? 0 : 2;
if (m[id] == 0) {
std::cout << 0 << std::endl;
continue;
}
int ans = 1;
long long q =
(r[id] + m[id] + (id - 1) * modpow(n - 1 - i, m[id]) % m[id]) % m[id];
while (q != 0) {
q = f(q);
ans++;
}
std::cout << ans << std::endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
long long f(long long x) {
int cnt = 0;
for (int i = 0; i < 20; i++) {
cnt += (x >> i) & 1;
}
return x % cnt;
}
long long modpow(int p, long long m) {
long long ret = 1;
long long b = 2;
for (int i = 0; i < 20; i++) {
if ((p >> i) & 1)
ret = ret * b % m;
b = b * b % m;
}
return ret;
}
int main() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
std::vector<long long> m(3), r(3);
for (int i = 0; i < n; i++)
m[1] += s[i] == '1';
m[0] = m[1] - 1;
m[2] = m[1] + 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (m[j] == 0)
continue;
r[j] = (r[j] * 2 + (s[i] == '1')) % m[j];
}
}
for (int i = 0; i < n; i++) {
int id = s[i] == '1' ? 0 : 2;
if (m[id] == 0) {
std::cout << 0 << std::endl;
continue;
}
int ans = 1;
long long q =
(r[id] + m[id] + (id - 1) * modpow(n - 1 - i, m[id]) % m[id]) % m[id];
while (q != 0) {
q = f(q);
ans++;
}
std::cout << ans << std::endl;
}
return 0;
}
| replace | 28 | 30 | 28 | 33 | TLE | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout << x
#define pb push_back
#include <string.h>
ll modex(ll a, ll b, ll mod) {
ll ans = 1;
while (b) {
if (b % 2)
ans = (ans * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return ans;
}
ll count(ll val) {
ll cnt = 0;
while (val) {
if (val % 2)
cnt++;
val /= 2;
}
return cnt;
}
ll fun(ll val) {
if (val == 0)
return 0;
return (1 + fun(val % count(val)));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T = 1;
// cin>>T;
while (T--) {
ll n;
cin >> n;
string str;
cin >> str;
ll val = 0, val1 = 0, val2 = 0, cnt = 0;
for (int i = 0; i < n; i++)
if (str[i] == '1')
cnt++;
for (int i = 0; i < n; i++) {
val = (val + (int)(str[i] - '0') * modex(2, n - 1 - i, cnt)) % cnt;
val1 = (val1 + (int)(str[i] - '0') * modex(2, n - 1 - i, cnt + 1)) %
(cnt + 1);
val2 = (val2 + (int)(str[i] - '0') * modex(2, n - 1 - i, cnt - 1)) %
(cnt - 1);
}
for (int i = 0; i < n; i++) {
if (str[i] == '1') {
if ((cnt - 1) == 0) {
cout << "0" << endl;
continue;
}
ll value =
((((val2 - modex(2, n - 1 - i, cnt - 1)) % (cnt - 1)) + (cnt - 1)) %
(cnt - 1));
cout << (1 + fun(value)) << endl;
} else {
ll value =
((val1 + modex(2, n - 1 - i, cnt + 1)) + cnt + 1) % (cnt + 1);
cout << (1 + fun(value)) << endl;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout << x
#define pb push_back
#include <string.h>
ll modex(ll a, ll b, ll mod) {
ll ans = 1;
while (b) {
if (b % 2)
ans = (ans * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return ans;
}
ll count(ll val) {
ll cnt = 0;
while (val) {
if (val % 2)
cnt++;
val /= 2;
}
return cnt;
}
ll fun(ll val) {
if (val == 0)
return 0;
return (1 + fun(val % count(val)));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T = 1;
// cin>>T;
while (T--) {
ll n;
cin >> n;
string str;
cin >> str;
ll val = 0, val1 = 0, val2 = 0, cnt = 0;
for (int i = 0; i < n; i++)
if (str[i] == '1')
cnt++;
for (int i = 0; i < n; i++) {
val = (val + (int)(str[i] - '0') * modex(2, n - 1 - i, cnt)) % cnt;
val1 = (val1 + (int)(str[i] - '0') * modex(2, n - 1 - i, cnt + 1)) %
(cnt + 1);
if (cnt > 1)
val2 = (val2 + (int)(str[i] - '0') * modex(2, n - 1 - i, cnt - 1)) %
(cnt - 1);
}
for (int i = 0; i < n; i++) {
if (str[i] == '1') {
if ((cnt - 1) == 0) {
cout << "0" << endl;
continue;
}
ll value =
((((val2 - modex(2, n - 1 - i, cnt - 1)) % (cnt - 1)) + (cnt - 1)) %
(cnt - 1));
cout << (1 + fun(value)) << endl;
} else {
ll value =
((val1 + modex(2, n - 1 - i, cnt + 1)) + cnt + 1) % (cnt + 1);
cout << (1 + fun(value)) << endl;
}
}
}
return 0;
} | replace | 49 | 51 | 49 | 52 | 0 | |
p02609 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
// constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll rui(ll a, ll b, ll MOD) {
ll ans = 1;
while (b > 0) {
if (b & 1)
ans = ans * a % MOD;
a = a * a % MOD;
b /= 2;
}
return ans;
}
int main() {
int n;
string x;
cin >> n >> x;
int popcount = count(all(x), '1');
int pp = popcount + 1, pm = popcount - 1;
int mod_plus = 0, mod_minus = 0;
rep(i, n) {
if (x[n - 1 - i] == '1') {
mod_plus = (mod_plus + rui(2, i, pp)) % pp;
mod_minus = (mod_minus + rui(2, i, pm)) % pm;
}
}
// cout << mod_plus << " " << mod_minus << ln;
vector<int> res;
rep(i, n) { // 前からi番目のビットを反転
int m;
if (x[n - 1 - i] == '1' && popcount == 1) {
res.push_back(0);
continue;
};
if (x[n - 1 - i] == '1')
m = (mod_minus + pm - rui(2, i, pm)) % pm;
else
m = (mod_plus + rui(2, i, pp)) % pp;
if (m == 0) {
res.push_back(1);
continue;
}
int cnt = 1;
// cout << "i:" << i << " m:" << m << ln;
while (m != 0) {
int tmp = m, pc = 0;
while (tmp > 0) {
if (tmp & 1)
pc++;
tmp /= 2;
}
if (pc == 0)
break;
m %= pc;
cnt++;
}
res.push_back(cnt);
}
reverse(all(res));
for (int a : res)
cout << a << ln;
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
// constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll rui(ll a, ll b, ll MOD) {
ll ans = 1;
while (b > 0) {
if (b & 1)
ans = ans * a % MOD;
a = a * a % MOD;
b /= 2;
}
return ans;
}
int main() {
int n;
string x;
cin >> n >> x;
int popcount = count(all(x), '1');
int pp = popcount + 1, pm = popcount - 1;
int mod_plus = 0, mod_minus = 0;
rep(i, n) {
if (x[n - 1 - i] == '1') {
mod_plus = (mod_plus + rui(2, i, pp)) % pp;
if (pm)
mod_minus = (mod_minus + rui(2, i, pm)) % pm;
else
mod_minus = 0;
}
}
// cout << mod_plus << " " << mod_minus << ln;
vector<int> res;
rep(i, n) { // 前からi番目のビットを反転
int m;
if (x[n - 1 - i] == '1' && popcount == 1) {
res.push_back(0);
continue;
};
if (x[n - 1 - i] == '1')
m = (mod_minus + pm - rui(2, i, pm)) % pm;
else
m = (mod_plus + rui(2, i, pp)) % pp;
if (m == 0) {
res.push_back(1);
continue;
}
int cnt = 1;
// cout << "i:" << i << " m:" << m << ln;
while (m != 0) {
int tmp = m, pc = 0;
while (tmp > 0) {
if (tmp & 1)
pc++;
tmp /= 2;
}
if (pc == 0)
break;
m %= pc;
cnt++;
}
res.push_back(cnt);
}
reverse(all(res));
for (int a : res)
cout << a << ln;
}
| replace | 50 | 51 | 50 | 54 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define input_from_file freopen("input.txt", "r", stdin);
using namespace std::chrono;
ll fun(ll a, ll b, ll m) {
ll ans = 1;
while (b >= 1) {
if (b & 1)
ans = (ans * a) % m;
a = (a * a) % m;
b = b / 2;
}
return ans % m;
}
int main() {
input_from_file fastIO ll n;
cin >> n;
string s;
cin >> s;
vector<ll> dp(2e5 + 5, 0);
for (int i = 1; i <= 2e5 + 4; i++) {
ll x = i, val = 0;
while (x != 0) {
if (x & 1)
val++;
x = x >> 1;
}
dp[i] = dp[i % val] + 1;
}
// for(int i=0;i<=n;i++) cout<<dp[i]<<" ";cout<<endl;
ll ctr = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
ctr++;
}
ll plus_one = 0, minus_one = 0;
ll val = 1;
for (int i = n - 1; i >= 0; i--) {
plus_one += (s[i] - '0') * val;
plus_one = plus_one % (ctr + 1);
val = val * 2;
val = val % (ctr + 1);
}
ll x;
if (ctr == 1) {
for (int i = 0; i < n; i++) {
if (s[i] == '1')
cout << 0 << endl;
else {
x = (plus_one + fun(2, n - 1 - i, ctr + 1)) % (ctr + 1);
cout << dp[x] + 1 << endl;
}
}
return 0;
}
val = 1;
for (int i = n - 1; i >= 0; i--) {
minus_one += (s[i] - '0') * val;
minus_one = minus_one % (ctr - 1);
val = val * 2;
val = val % (ctr - 1);
}
// cout<<"ctr="<<ctr<<" ,plus_one="<<plus_one<<"
// ,minus_one="<<minus_one<<endl; cout<<fun(2,21,ctr+1)<<endl<<endl;;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
x = (minus_one - fun(2, n - 1 - i, ctr - 1) + (ctr - 1)) % (ctr - 1);
else
x = (plus_one + fun(2, n - 1 - i, ctr + 1)) % (ctr + 1);
cout << dp[x] + 1 << endl;
}
// cout<<"aaaaaaaa";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define input_from_file freopen("input.txt", "r", stdin);
using namespace std::chrono;
ll fun(ll a, ll b, ll m) {
ll ans = 1;
while (b >= 1) {
if (b & 1)
ans = (ans * a) % m;
a = (a * a) % m;
b = b / 2;
}
return ans % m;
}
int main() {
// input_from_file
fastIO ll n;
cin >> n;
string s;
cin >> s;
vector<ll> dp(2e5 + 5, 0);
for (int i = 1; i <= 2e5 + 4; i++) {
ll x = i, val = 0;
while (x != 0) {
if (x & 1)
val++;
x = x >> 1;
}
dp[i] = dp[i % val] + 1;
}
// for(int i=0;i<=n;i++) cout<<dp[i]<<" ";cout<<endl;
ll ctr = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
ctr++;
}
ll plus_one = 0, minus_one = 0;
ll val = 1;
for (int i = n - 1; i >= 0; i--) {
plus_one += (s[i] - '0') * val;
plus_one = plus_one % (ctr + 1);
val = val * 2;
val = val % (ctr + 1);
}
ll x;
if (ctr == 1) {
for (int i = 0; i < n; i++) {
if (s[i] == '1')
cout << 0 << endl;
else {
x = (plus_one + fun(2, n - 1 - i, ctr + 1)) % (ctr + 1);
cout << dp[x] + 1 << endl;
}
}
return 0;
}
val = 1;
for (int i = n - 1; i >= 0; i--) {
minus_one += (s[i] - '0') * val;
minus_one = minus_one % (ctr - 1);
val = val * 2;
val = val % (ctr - 1);
}
// cout<<"ctr="<<ctr<<" ,plus_one="<<plus_one<<"
// ,minus_one="<<minus_one<<endl; cout<<fun(2,21,ctr+1)<<endl<<endl;;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
x = (minus_one - fun(2, n - 1 - i, ctr - 1) + (ctr - 1)) % (ctr - 1);
else
x = (plus_one + fun(2, n - 1 - i, ctr + 1)) % (ctr + 1);
cout << dp[x] + 1 << endl;
}
// cout<<"aaaaaaaa";
return 0;
}
| replace | 24 | 25 | 24 | 26 | -11 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
using namespace std;
const int N = 500077;
int n, m, d, t;
char a[N];
int s1 = 0, s2 = 0;
int binpow(int a, int n, int k) {
if (n == 0)
return 1 % k;
if (n % 2 == 1)
return binpow(a, n - 1, k) * a % k;
else {
int b = binpow(a, n / 2, k) % k;
return b * b % k;
}
}
int make(int x) {
int cnt = 0;
while (x > 0) {
if (x % 2 == 1) {
cnt++;
}
x /= 2;
}
return cnt;
}
void check(int x) {
int cnt = 1;
while (x > 0) {
cnt++;
x %= make(x);
}
cout << cnt << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
cin >> n;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == '1') {
cnt++;
}
}
if (cnt == 0) {
for (int i = 1; i <= n; i++) {
cout << 1 << endl;
}
return 0;
}
if (cnt == 1) {
for (int i = 1; i <= n; i++) {
if (a[i] == '1') {
s1 = binpow(2, n - i, 2);
}
}
for (int i = 1; i <= n; i++) {
if (a[i] == '1') {
cout << 0 << endl;
} else {
int s2 = binpow(2, n - i, 2) + s1;
s2 %= 2;
check(s2);
}
}
}
for (int i = 1; i <= n; i++) {
if (a[i] == '1') {
s1 += (binpow(2, n - i, cnt - 1) % (cnt - 1));
s2 += (binpow(2, n - i, cnt + 1) % (cnt + 1));
}
}
for (int i = 1; i <= n; i++) {
int sum = 0;
if (a[i] == '1') {
sum = s1;
sum -= binpow(2, n - i, cnt - 1);
sum %= (cnt - 1);
sum += (cnt - 1);
sum %= (cnt - 1);
check(sum);
} else {
sum = s2;
sum += binpow(2, n - i, cnt + 1) % (cnt + 1);
sum %= (cnt + 1);
sum += (cnt + 1);
sum %= (cnt + 1);
check(sum);
}
}
}
| #include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
using namespace std;
const int N = 500077;
int n, m, d, t;
char a[N];
int s1 = 0, s2 = 0;
int binpow(int a, int n, int k) {
if (n == 0)
return 1 % k;
if (n % 2 == 1)
return binpow(a, n - 1, k) * a % k;
else {
int b = binpow(a, n / 2, k) % k;
return b * b % k;
}
}
int make(int x) {
int cnt = 0;
while (x > 0) {
if (x % 2 == 1) {
cnt++;
}
x /= 2;
}
return cnt;
}
void check(int x) {
int cnt = 1;
while (x > 0) {
cnt++;
x %= make(x);
}
cout << cnt << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
cin >> n;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == '1') {
cnt++;
}
}
if (cnt == 0) {
for (int i = 1; i <= n; i++) {
cout << 1 << endl;
}
return 0;
}
if (cnt == 1) {
for (int i = 1; i <= n; i++) {
if (a[i] == '1') {
s1 = binpow(2, n - i, 2);
}
}
for (int i = 1; i <= n; i++) {
if (a[i] == '1') {
cout << 0 << endl;
} else {
int s2 = binpow(2, n - i, 2) + s1;
s2 %= 2;
check(s2);
}
}
return 0;
}
for (int i = 1; i <= n; i++) {
if (a[i] == '1') {
s1 += (binpow(2, n - i, cnt - 1) % (cnt - 1));
s2 += (binpow(2, n - i, cnt + 1) % (cnt + 1));
}
}
for (int i = 1; i <= n; i++) {
int sum = 0;
if (a[i] == '1') {
sum = s1;
sum -= binpow(2, n - i, cnt - 1);
sum %= (cnt - 1);
sum += (cnt - 1);
sum %= (cnt - 1);
check(sum);
} else {
sum = s2;
sum += binpow(2, n - i, cnt + 1) % (cnt + 1);
sum %= (cnt + 1);
sum += (cnt + 1);
sum %= (cnt + 1);
check(sum);
}
}
}
| insert | 77 | 77 | 77 | 78 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;
int f[200010];
int amari[200010][2];
int main() {
int n, popcount = 0;
string s;
cin >> n >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1')
popcount++;
}
for (int i = 1; i <= 200000; i++) {
int coun = 0;
for (int j = 0; j <= 18; j++) {
if (i & (1LL << j))
coun++;
}
f[i] = f[(i % coun)] + 1;
}
if (popcount != 1) {
amari[0][0] = 1 % (popcount - 1);
}
amari[0][1] = 1 % (popcount + 1);
for (int i = 1; i < n; i++) {
if (popcount != 1) {
amari[i][0] = (amari[i - 1][0] * 2) % (popcount - 1);
}
amari[i][1] = (amari[i - 1][1] * 2) % (popcount + 1);
}
int defamari0 = 0;
int defamari1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
defamari0 += amari[s.length() - 1 - i][0];
defamari1 += amari[s.length() - 1 - i][1];
defamari0 %= (popcount - 1);
defamari1 %= (popcount + 1);
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') {
int newamari = defamari1 + amari[s.length() - 1 - i][1];
newamari %= (popcount + 1);
cout << f[newamari] + 1 << endl;
} else if (s[i] == '1' && popcount != 1) {
int newamari = defamari0 - amari[s.length() - 1 - i][0];
newamari %= (popcount + 1);
if (newamari < 0)
newamari += (popcount - 1);
cout << f[newamari] + 1 << endl;
} else {
cout << 0 << endl;
}
}
return 0;
}
| #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;
int f[200010];
int amari[200010][2];
int main() {
int n, popcount = 0;
string s;
cin >> n >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1')
popcount++;
}
for (int i = 1; i <= 200000; i++) {
int coun = 0;
for (int j = 0; j <= 18; j++) {
if (i & (1LL << j))
coun++;
}
f[i] = f[(i % coun)] + 1;
}
if (popcount != 1) {
amari[0][0] = 1 % (popcount - 1);
}
amari[0][1] = 1 % (popcount + 1);
for (int i = 1; i < n; i++) {
if (popcount != 1) {
amari[i][0] = (amari[i - 1][0] * 2) % (popcount - 1);
}
amari[i][1] = (amari[i - 1][1] * 2) % (popcount + 1);
}
int defamari0 = 0;
int defamari1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
defamari0 += amari[s.length() - 1 - i][0];
defamari1 += amari[s.length() - 1 - i][1];
if (popcount != 1) {
defamari0 %= (popcount - 1);
}
defamari1 %= (popcount + 1);
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') {
int newamari = defamari1 + amari[s.length() - 1 - i][1];
newamari %= (popcount + 1);
cout << f[newamari] + 1 << endl;
} else if (s[i] == '1' && popcount != 1) {
int newamari = defamari0 - amari[s.length() - 1 - i][0];
newamari %= (popcount + 1);
if (newamari < 0)
newamari += (popcount - 1);
cout << f[newamari] + 1 << endl;
} else {
cout << 0 << endl;
}
}
return 0;
} | replace | 55 | 56 | 55 | 58 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i < b; i++)
#define int long long
#define mod 1000000009
#define garou \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
int pow(int p, int r, int m) {
int ans = 1;
while (r > 0) {
if (r & 1) {
ans = ((ans % m) * (p % m)) % m;
}
r = r >> 1;
p = ((p % m) * (p % m)) % m;
}
return ans;
}
int popcount(int n) {
int ans = 0;
REP(i, 0, 32) {
if ((n & (1 << i)))
ans++;
}
return ans;
}
int binary(string x, int m) {
int n = x.length();
int ans = 0, j = 0;
for (int i = n - 1; i >= 0; i--) {
if (x[i] != '0')
ans = (ans + pow(2, j, m)) % m;
j++;
}
return ans;
}
signed main() {
garou;
int n;
cin >> n;
string x;
cin >> x;
int one = 0;
int n1 = x.length();
REP(i, 0, n) {
if (x[i] == '1')
one++;
}
int a = binary(x, one + 1);
int b = binary(x, one - 1);
REP(i, 0, n1) {
if (x[i] == '1' && (one - 1) == 0) {
cout << 0 << endl;
continue;
}
int c = 0;
if (x[i] == '0')
c = (a + pow(2, n1 - i - 1, one + 1)) % (one + 1);
else
c = (b - pow(2, n1 - i - 1, one - 1) + one - 1) % (one - 1);
int re = 0;
while (c) {
c %= popcount(c);
re++;
}
cout << re + 1 << endl;
}
} | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i < b; i++)
#define int long long
#define mod 1000000009
#define garou \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
int pow(int p, int r, int m) {
int ans = 1;
while (r > 0) {
if (r & 1) {
ans = ((ans % m) * (p % m)) % m;
}
r = r >> 1;
p = ((p % m) * (p % m)) % m;
}
return ans;
}
int popcount(int n) {
int ans = 0;
REP(i, 0, 32) {
if ((n & (1 << i)))
ans++;
}
return ans;
}
int binary(string x, int m) {
int n = x.length();
int ans = 0, j = 0;
for (int i = n - 1; i >= 0; i--) {
if (x[i] != '0')
ans = (ans + pow(2, j, m)) % m;
j++;
}
return ans;
}
signed main() {
garou;
int n;
cin >> n;
string x;
cin >> x;
int one = 0;
int n1 = x.length();
REP(i, 0, n) {
if (x[i] == '1')
one++;
}
int a = binary(x, one + 1);
int b = 0;
if (one > 1)
b = binary(x, one - 1);
REP(i, 0, n1) {
if (x[i] == '1' && (one - 1) == 0) {
cout << 0 << endl;
continue;
}
int c = 0;
if (x[i] == '0')
c = (a + pow(2, n1 - i - 1, one + 1)) % (one + 1);
else
c = (b - pow(2, n1 - i - 1, one - 1) + one - 1) % (one - 1);
int re = 0;
while (c) {
c %= popcount(c);
re++;
}
cout << re + 1 << endl;
}
} | replace | 50 | 51 | 50 | 53 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int, int>
#define iii pair<ii, int>
#define ppb pop_back
#define st first
#define nd second
#define ll long long
#define N 500005
#define inf 2000000005
#define MOD 1000000007
#define LOG 14
#define EPS 0.000000001
using namespace std;
int n;
int mod[2];
int f[N];
int p[2][N], s[2];
string S;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 1; i < N; i++) {
int cnt = __builtin_popcount(i);
f[i] = f[i % cnt] + 1;
}
cin >> n;
cin >> S;
int cnt = 0;
for (int i = 0; i < n; i++)
cnt += (S[i] == '1');
mod[0] = cnt - 1;
mod[1] = cnt + 1;
for (int i = 0; i < 2; i++) {
p[i][0] = 1;
for (int j = 1; j <= n; j++) {
p[i][j] = (ll)p[i][j - 1] * 2 % mod[i];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
int bit = n - j - 1;
if (S[j] == '1')
s[i] = ((ll)s[i] + p[i][bit]) % mod[i];
}
}
for (int i = 0; i < n; i++) {
int bit = n - i - 1;
int sum;
if (S[i] == '1') {
sum = s[0];
sum = (((ll)sum - p[0][bit]) % mod[0] + mod[0]) % mod[0];
} else {
sum = s[1];
sum = (((ll)sum + p[1][bit]) % mod[1] + mod[1]) % mod[1];
}
cout << f[sum] + 1 << "\n";
}
} | #include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int, int>
#define iii pair<ii, int>
#define ppb pop_back
#define st first
#define nd second
#define ll long long
#define N 500005
#define inf 2000000005
#define MOD 1000000007
#define LOG 14
#define EPS 0.000000001
using namespace std;
int n;
int mod[2];
int f[N];
int p[2][N], s[2];
string S;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 1; i < N; i++) {
int cnt = __builtin_popcount(i);
f[i] = f[i % cnt] + 1;
}
cin >> n;
cin >> S;
int cnt = 0;
for (int i = 0; i < n; i++)
cnt += (S[i] == '1');
if (cnt == 1) {
for (int i = 0; i < n; i++) {
if (S[i] == '1')
cout << "0\n";
else {
if (i == n - 1 or S[n - 1] == '1') {
cout << "2\n";
} else {
cout << "1\n";
}
}
}
return 0;
}
mod[0] = cnt - 1;
mod[1] = cnt + 1;
for (int i = 0; i < 2; i++) {
p[i][0] = 1;
for (int j = 1; j <= n; j++) {
p[i][j] = (ll)p[i][j - 1] * 2 % mod[i];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
int bit = n - j - 1;
if (S[j] == '1')
s[i] = ((ll)s[i] + p[i][bit]) % mod[i];
}
}
for (int i = 0; i < n; i++) {
int bit = n - i - 1;
int sum;
if (S[i] == '1') {
sum = s[0];
sum = (((ll)sum - p[0][bit]) % mod[0] + mod[0]) % mod[0];
} else {
sum = s[1];
sum = (((ll)sum + p[1][bit]) % mod[1] + mod[1]) % mod[1];
}
cout << f[sum] + 1 << "\n";
}
} | insert | 37 | 37 | 37 | 51 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FIN \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
const int INF = 1000000000;
const int MOD = 1000000007;
ll powMod(ll n, ll p, ll m) {
if (p == 0)
return 1;
if (p == 1)
return n % m;
ll e = powMod(n, p / 2, m);
e = (e * e) % m;
if (p & 1)
e = (e * n) % m;
return e;
}
ll fn(ll i, vll &ns) {
if (ns[i] != -1)
return ns[i];
return 1 + fn(i % __builtin_popcount(i), ns);
}
int main() {
FIN
ll n,
m = 0, i, p, d;
string s;
cin >> n;
vll ns(n + 1, -1);
vvll md(n + 1, vll(2));
cin >> s;
for (i = 0; i < n; i++)
if (s[i] == '1')
m++;
ns[0] = 0;
for (i = 1; i <= n; i++) {
ns[i] = fn(i, ns);
}
if (m - 1 > 0) {
p = 1;
for (i = n - 1; i >= 0; i--) {
if (s[i] == '1')
md[i][0] = (md[i + 1][0] + p) % (m - 1);
else
md[i][0] = md[i + 1][0];
p = (2 * p) % (m - 1);
}
}
if (m + 1 <= n) {
p = 1;
for (i = n - 1; i >= 0; i--) {
if (s[i] == '1')
md[i][1] = (md[i + 1][1] + p) % (m + 1);
else
md[i][1] = md[i + 1][1];
p = (2 * p) % (m + 1);
}
}
for (i = 0; i < n; i++) {
if (s[i] == '1') {
d = 1 +
ns[((md[i + 1][0] + (((md[0][0] - md[i][0]) + (m - 1)) % (m - 1))) %
(m - 1))];
} else {
d = 1 +
ns[((((md[i + 1][1] + (((md[0][1] - md[i][1]) + (m + 1)) % (m + 1))) %
(m + 1)) +
powMod(2, n - i - 1, m + 1)) %
(m + 1))];
}
cout << d << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FIN \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
const int INF = 1000000000;
const int MOD = 1000000007;
ll powMod(ll n, ll p, ll m) {
if (p == 0)
return 1;
if (p == 1)
return n % m;
ll e = powMod(n, p / 2, m);
e = (e * e) % m;
if (p & 1)
e = (e * n) % m;
return e;
}
ll fn(ll i, vll &ns) {
if (ns[i] != -1)
return ns[i];
return 1 + fn(i % __builtin_popcount(i), ns);
}
int main() {
FIN
ll n,
m = 0, i, p, d;
string s;
cin >> n;
vll ns(n + 1, -1);
vvll md(n + 1, vll(2));
cin >> s;
for (i = 0; i < n; i++)
if (s[i] == '1')
m++;
ns[0] = 0;
for (i = 1; i <= n; i++) {
ns[i] = fn(i, ns);
}
if (m - 1 > 0) {
p = 1;
for (i = n - 1; i >= 0; i--) {
if (s[i] == '1')
md[i][0] = (md[i + 1][0] + p) % (m - 1);
else
md[i][0] = md[i + 1][0];
p = (2 * p) % (m - 1);
}
}
if (m + 1 <= n) {
p = 1;
for (i = n - 1; i >= 0; i--) {
if (s[i] == '1')
md[i][1] = (md[i + 1][1] + p) % (m + 1);
else
md[i][1] = md[i + 1][1];
p = (2 * p) % (m + 1);
}
}
for (i = 0; i < n; i++) {
if (s[i] == '1') {
d = m > 1 ? (1 + ns[((md[i + 1][0] +
(((md[0][0] - md[i][0]) + (m - 1)) % (m - 1))) %
(m - 1))])
: 0;
} else {
d = 1 +
ns[((((md[i + 1][1] + (((md[0][1] - md[i][1]) + (m + 1)) % (m + 1))) %
(m + 1)) +
powMod(2, n - i - 1, m + 1)) %
(m + 1))];
}
cout << d << "\n";
}
return 0;
}
| replace | 81 | 84 | 81 | 85 | 0 | |
p02609 | C++ | Runtime Error | #ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define sim template <class c
#define int long long
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18 + 10;
int popcount(int x) {
int cnt = 0;
for (int i = 0; i < 32; i++) {
if ((1LL << i) & x)
cnt++;
}
return cnt;
}
string toBin(int x) {
string ans = "";
for (int i = 0; i < 32; i++) {
if ((1LL << i) & x)
ans.push_back('1');
else
ans.push_back('0');
}
reverse(ans.begin(), ans.end());
return ans;
}
int fast(int a, int b, int mod) {
if (b == 0)
return 1;
if (b == 1)
return a;
int y = fast(a, b / 2, mod);
int ans = (y * y) % mod;
if (b & 1)
ans *= a;
return ans % mod;
}
signed main() {
fastio vector<int> v(2e5 + 5, 0);
for (int i = 1; i < 2e5 + 5; i++) {
int x = i;
int cnt = 0;
int y = popcount(x);
while (x != 0) {
int c = popcount(x);
x %= c;
cnt++;
}
v[i] = cnt;
// if ( cnt == 4 )
// debug() << imie(i) imie(y) imie(toBin(i)) imie(cnt) ;
}
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for (char &c : s) {
if (c == '1')
cnt++;
}
int high = 0, low = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
high += fast(2, n - i - 1, cnt + 1);
low += fast(2, n - i - 1, cnt - 1);
}
}
debug() << imie(high);
debug() << imie(low);
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
int x = high;
x += fast(2, n - i - 1, cnt + 1);
cout << 1 + v[x % (cnt + 1)] << endl;
debug() << imie(x);
} else {
int x = low;
x -= fast(2, n - i - 1, cnt - 1);
x = (x % (cnt - 1) + (cnt - 1)) % (cnt - 1);
cout << 1 + v[x % (cnt - 1)] << endl;
debug() << imie(x);
}
}
// return 0 ;
// int n ;
// cin >> n ;
// string s ;
// cin >> s;
// int cnt = 0 ;
// for(int i = 0; i < n; i++){
// if ( s[i] == '1' ) cnt++ ;
// }
// bool isOdd = s[n - 1] == '1' ? true : false ;
// for(int i = 0; i < n; i++){
// int newCnt = cnt ;
// if ( s[i] == '0' ) newCnt++ ;
// if ( newCnt == 1 ) {
// cout << 1 << endl;
// }
// else if ( isOdd ) {
// }
// else{
// }
// }
return 0;
} | #ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define sim template <class c
#define int long long
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18 + 10;
int popcount(int x) {
int cnt = 0;
for (int i = 0; i < 32; i++) {
if ((1LL << i) & x)
cnt++;
}
return cnt;
}
string toBin(int x) {
string ans = "";
for (int i = 0; i < 32; i++) {
if ((1LL << i) & x)
ans.push_back('1');
else
ans.push_back('0');
}
reverse(ans.begin(), ans.end());
return ans;
}
int fast(int a, int b, int mod) {
if (b == 0)
return 1;
if (b == 1)
return a;
int y = fast(a, b / 2, mod);
int ans = (y * y) % mod;
if (b & 1)
ans *= a;
return ans % mod;
}
signed main() {
fastio vector<int> v(2e5 + 5, 0);
for (int i = 1; i < 2e5 + 5; i++) {
int x = i;
int cnt = 0;
int y = popcount(x);
while (x != 0) {
int c = popcount(x);
x %= c;
cnt++;
}
v[i] = cnt;
// if ( cnt == 4 )
// debug() << imie(i) imie(y) imie(toBin(i)) imie(cnt) ;
}
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for (char &c : s) {
if (c == '1')
cnt++;
}
bool isOdd = s[n - 1] == '1' ? true : false;
if (cnt == 1) {
for (int i = 0; i < n; i++) {
if (i == n - 1 && !isOdd) {
cout << 2 << endl;
} else if (s[i] == '0') {
if (isOdd) {
cout << 2 << endl;
} else {
cout << 1 << endl;
}
} else {
cout << 0 << endl;
}
}
return 0;
}
int high = 0, low = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
high += fast(2, n - i - 1, cnt + 1);
low += fast(2, n - i - 1, cnt - 1);
}
}
debug() << imie(high);
debug() << imie(low);
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
int x = high;
x += fast(2, n - i - 1, cnt + 1);
cout << 1 + v[x % (cnt + 1)] << endl;
debug() << imie(x);
} else {
int x = low;
x -= fast(2, n - i - 1, cnt - 1);
x = (x % (cnt - 1) + (cnt - 1)) % (cnt - 1);
cout << 1 + v[x % (cnt - 1)] << endl;
debug() << imie(x);
}
}
// return 0 ;
// int n ;
// cin >> n ;
// string s ;
// cin >> s;
// int cnt = 0 ;
// for(int i = 0; i < n; i++){
// if ( s[i] == '1' ) cnt++ ;
// }
// bool isOdd = s[n - 1] == '1' ? true : false ;
// for(int i = 0; i < n; i++){
// int newCnt = cnt ;
// if ( s[i] == '0' ) newCnt++ ;
// if ( newCnt == 1 ) {
// cout << 1 << endl;
// }
// else if ( isOdd ) {
// }
// else{
// }
// }
return 0;
} | insert | 108 | 108 | 108 | 125 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;
ll ff(ll x, ll n, ll a) {
if (x == 0) {
return a;
}
x %= n;
ll nx = x;
ll nn = 0;
while (nx > 0) {
if (nx % 2 == 1) {
nn++;
}
nx /= 2;
}
return ff(x, nn, a + 1);
}
ll f(string x, ll n) {
ll x1 = 0, a = 1;
if (n == 0) {
return 0;
}
for (int i = x.size() - 1; i >= 0; i--) {
if (x[i] == '1') {
x1 += a;
}
a *= 2;
a %= n;
x1 %= n;
}
return x1;
}
int main() {
ll N;
string X;
cin >> N >> X;
ll num = 0;
ll a[N];
rep(i, N) {
if (X[i] == '1') {
num++;
}
}
ll n1 = f(X, num + 1);
// cout<<n1;
ll n2 = f(X, num - 1);
ll a1 = 1, a2 = 1;
for (int i = N - 1; i >= 0; i--) {
string x = X;
ll n = num;
if (X[i] == '0') {
x[i] = '1';
n++;
ll n11 = a1 + n1;
n11 %= num + 1;
ll nx = n11;
ll nn = 0;
while (nx > 0) {
if (nx % 2 == 1) {
nn++;
}
nx /= 2;
}
a[i] = ff(n11, nn, 1);
} else {
x[i] = '0';
n--;
ll n22 = n2 - a2;
if (n == 0) {
a[i] = 0;
continue;
}
n22 %= num - 1;
if (n22 < 0) {
n22 += num - 1;
}
ll nx = n22;
ll nn = 0;
while (nx > 0) {
if (nx % 2 == 1) {
nn++;
}
nx /= 2;
}
a[i] = ff(n22, nn, 1);
}
// cout<<ff(x,n,1)<<endl;
a1 *= 2;
a1 %= num + 1;
a2 *= 2;
if (n == 0) {
continue;
}
a2 %= num - 1;
}
for (int i = 0; i < N; i++) {
cout << a[i] << endl; // cout<<0%2;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;
ll ff(ll x, ll n, ll a) {
if (x == 0) {
return a;
}
x %= n;
ll nx = x;
ll nn = 0;
while (nx > 0) {
if (nx % 2 == 1) {
nn++;
}
nx /= 2;
}
return ff(x, nn, a + 1);
}
ll f(string x, ll n) {
ll x1 = 0, a = 1;
if (n == 0) {
return 0;
}
for (int i = x.size() - 1; i >= 0; i--) {
if (x[i] == '1') {
x1 += a;
}
a *= 2;
a %= n;
x1 %= n;
}
return x1;
}
int main() {
ll N;
string X;
cin >> N >> X;
ll num = 0;
ll a[N];
rep(i, N) {
if (X[i] == '1') {
num++;
}
}
ll n1 = f(X, num + 1);
// cout<<n1;
ll n2 = f(X, num - 1);
ll a1 = 1, a2 = 1;
for (int i = N - 1; i >= 0; i--) {
string x = X;
ll n = num;
if (X[i] == '0') {
x[i] = '1';
n++;
ll n11 = a1 + n1;
n11 %= num + 1;
ll nx = n11;
ll nn = 0;
while (nx > 0) {
if (nx % 2 == 1) {
nn++;
}
nx /= 2;
}
a[i] = ff(n11, nn, 1);
} else {
x[i] = '0';
n--;
ll n22 = n2 - a2;
if (n == 0) {
a[i] = 0;
continue;
}
n22 %= num - 1;
if (n22 < 0) {
n22 += num - 1;
}
ll nx = n22;
ll nn = 0;
while (nx > 0) {
if (nx % 2 == 1) {
nn++;
}
nx /= 2;
}
a[i] = ff(n22, nn, 1);
}
// cout<<ff(x,n,1)<<endl;
a1 *= 2;
a1 %= num + 1;
a2 *= 2;
if (num == 1) {
continue;
}
a2 %= num - 1;
}
for (int i = 0; i < N; i++) {
cout << a[i] << endl; // cout<<0%2;
}
}
| replace | 100 | 101 | 100 | 101 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
ll mod_pow(ll x, ll n, ll mod = MOD) {
if (n == 0)
return 1;
ll res = mod_pow(x * x % mod, n / 2, mod);
if (n & 1)
res = res * x % mod;
return res;
}
int main() {
int N;
cin >> N;
string X;
cin >> X;
reverse(ALL(X));
vector<int> dp(N + 100);
dp[0] = 0;
FOR(i, 1, N + 10) {
int p = 0;
REP(j, 30) if (i >> j & 1)++ p;
dp[i] = dp[i % p] + 1;
}
int bp = 0;
REP(i, N) if (X[i] == '1')++ bp;
int base[3]{}; // -1, 0, 1
REP(i, 3) {
int bias = i - 1;
// bias >= 0
if (bias == 0)
continue;
// bp + bias 個で割る
REP(j, N) if (X[j] == '1') {
base[i] += mod_pow(2, j, bp + bias);
base[i] %= bp + bias;
}
}
reverse(ALL(X));
REP(i, N) {
int bias = X[i] == '1' ? -1 : 1;
if (bp + bias == 0) {
puts("0");
continue;
}
int ch = mod_pow(2, N - 1 - i, bp + bias);
if (X[i] == '1')
ch = (-ch + bp + bias) % (bp + bias);
int nem = (ch + base[bias == -1 ? 0 : 2]) % (bp + bias);
printf("%d\n", dp[nem] + 1);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
ll mod_pow(ll x, ll n, ll mod = MOD) {
if (n == 0)
return 1;
ll res = mod_pow(x * x % mod, n / 2, mod);
if (n & 1)
res = res * x % mod;
return res;
}
int main() {
int N;
cin >> N;
string X;
cin >> X;
reverse(ALL(X));
vector<int> dp(N + 100);
dp[0] = 0;
FOR(i, 1, N + 10) {
int p = 0;
REP(j, 30) if (i >> j & 1)++ p;
dp[i] = dp[i % p] + 1;
}
int bp = 0;
REP(i, N) if (X[i] == '1')++ bp;
int base[3]{}; // -1, 0, 1
REP(i, 3) {
int bias = i - 1;
// bias >= 0
if (bp + bias == 0)
continue;
// bp + bias 個で割る
REP(j, N) if (X[j] == '1') {
base[i] += mod_pow(2, j, bp + bias);
base[i] %= bp + bias;
}
}
reverse(ALL(X));
REP(i, N) {
int bias = X[i] == '1' ? -1 : 1;
if (bp + bias == 0) {
puts("0");
continue;
}
int ch = mod_pow(2, N - 1 - i, bp + bias);
if (X[i] == '1')
ch = (-ch + bp + bias) % (bp + bias);
int nem = (ch + base[bias == -1 ? 0 : 2]) % (bp + bias);
printf("%d\n", dp[nem] + 1);
}
return 0;
}
| replace | 62 | 63 | 62 | 63 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define IFOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR((i), 0, (n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int calc(ll x) {
if (x == 0)
return 0;
int cnt = 0;
ll tmp = x;
while (tmp > 0) {
if (tmp & 1)
cnt++;
tmp >>= 1;
}
return calc(x % cnt) + 1;
}
int calc(string x, int cnt, int bit, vector<ll> &p2_plus, vector<ll> &p2_minus,
ll base_plus, ll base_minus) {
ll now;
if (x[bit] == '0') {
cnt++;
now = (base_plus + p2_plus[x.size() - 1 - bit]) % cnt;
} else {
cnt--;
if (cnt == 0)
return 0;
now = (base_minus + (cnt - p2_minus[x.size() - 1 - bit])) % cnt;
}
return calc(now) + 1;
}
int main() {
int n;
cin >> n;
string x;
cin >> x;
int popcount = count(x.begin(), x.end(), '1');
vector<ll> p2_minus(n + 1, 1);
vector<ll> p2_plus(n + 1, 1);
IFOR(i, 1, n) {
p2_plus[i] = (p2_plus[i - 1] * 2) % (popcount + 1);
if (popcount >= 2)
p2_minus[i] = (p2_minus[i - 1] * 2) % (popcount - 1);
}
ll base_plus = 0;
ll base_minus = 0;
REP(i, x.size()) {
base_plus *= 2;
base_minus *= 2;
int toadd = x[i] - '0';
base_plus = (base_plus + toadd) % (popcount + 1);
base_minus = (base_minus + toadd) % (popcount - 1);
}
REP(i, n) {
cout << calc(x, popcount, i, p2_plus, p2_minus, base_plus, base_minus)
<< endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define IFOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR((i), 0, (n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int calc(ll x) {
if (x == 0)
return 0;
int cnt = 0;
ll tmp = x;
while (tmp > 0) {
if (tmp & 1)
cnt++;
tmp >>= 1;
}
return calc(x % cnt) + 1;
}
int calc(string x, int cnt, int bit, vector<ll> &p2_plus, vector<ll> &p2_minus,
ll base_plus, ll base_minus) {
ll now;
if (x[bit] == '0') {
cnt++;
now = (base_plus + p2_plus[x.size() - 1 - bit]) % cnt;
} else {
cnt--;
if (cnt == 0)
return 0;
now = (base_minus + (cnt - p2_minus[x.size() - 1 - bit])) % cnt;
}
return calc(now) + 1;
}
int main() {
int n;
cin >> n;
string x;
cin >> x;
int popcount = count(x.begin(), x.end(), '1');
vector<ll> p2_minus(n + 1, 1);
vector<ll> p2_plus(n + 1, 1);
IFOR(i, 1, n) {
p2_plus[i] = (p2_plus[i - 1] * 2) % (popcount + 1);
if (popcount >= 2)
p2_minus[i] = (p2_minus[i - 1] * 2) % (popcount - 1);
}
ll base_plus = 0;
ll base_minus = 0;
REP(i, x.size()) {
base_plus *= 2;
base_minus *= 2;
int toadd = x[i] - '0';
base_plus = (base_plus + toadd) % (popcount + 1);
if (popcount >= 2)
base_minus = (base_minus + toadd) % (popcount - 1);
}
REP(i, n) {
cout << calc(x, popcount, i, p2_plus, p2_minus, base_plus, base_minus)
<< endl;
}
return 0;
} | replace | 87 | 88 | 87 | 89 | 0 | |
p02609 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <new>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define lrep(i, n, m) for (int i = n; i < m; i++)
using ll = long long;
using ld = long double;
using Vii = vector<vector<int>>;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll>>;
using Vldd = vector<vector<ld>>;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n;
cin >> n;
string x;
cin >> x;
int d = 0;
rep(i, n) if (x[i] == '1') d++;
if (d == 1) {
Vi p(n);
Vi ans(n, -1);
int z = (x[n - 1] - '0') % 2;
rep(i, n) {
if (x[i] == '1')
p[i] == 0;
else
p[i] = 2;
if (p[i] == 0)
ans[i] = 0;
else {
if (z) {
if (i == n - 1)
ans[i] = 1;
else
ans[i] = 2;
} else {
if (i == n - 1)
ans[i] = 2;
else
ans[i] = 1;
}
}
}
for (int u : ans)
cout << u << endl;
return 0;
}
reverse(x.begin(), x.end());
Vi popx(n, 0);
rep(i, n) {
if (x[i] == '1')
popx[i] = d - 1;
else
popx[i] = d + 1;
}
int A[3] = {0};
for (int i = 0; i < 3; i++) {
int t = 1;
ll u = 0;
for (int j = 0; j < n; j++) {
if (x[j] == '1') {
u = (u + t) % (d - 1 + i);
}
t = (t * 2) % (d - 1 + i);
}
u %= (d - 1 + i);
A[i] = u;
}
Vi mod2(n, 0);
int t1 = 1, t2 = 1, t3 = 1;
rep(i, n) {
int u = popx[i];
if (x[i] == '0') {
if (u == d - 1) {
mod2[i] = (A[0] + t1) % u;
} else if (u == d) {
mod2[i] = (A[1] + t2) % u;
} else {
mod2[i] = (A[2] + t3) % u;
}
} else {
if (u == d - 1) {
mod2[i] = (u + A[0] - t1) % u;
} else if (u == d) {
mod2[i] = (u + A[1] - t2) % u;
} else {
mod2[i] = (u + A[2] - t3) % u;
}
}
t1 = (t1 * 2) % (d - 1);
t2 = (t2 * 2) % d;
t3 = (t3 * 2) % (d + 1);
}
reverse(mod2.begin(), mod2.end());
Vi ans(n, -1);
rep(i, n) {
if (mod2[i] == 0 && ans[i] == -1) {
ans[i] = 1;
continue;
}
int tans = 1;
while (mod2[i] > 0) {
int u = mod2[i];
bitset<32> t = bitset<32>(u);
int c = t.count();
if (c == 0)
break;
mod2[i] %= c;
tans++;
}
ans[i] = tans;
}
for (int u : ans) {
cout << u << endl;
}
}
| #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <new>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define lrep(i, n, m) for (int i = n; i < m; i++)
using ll = long long;
using ld = long double;
using Vii = vector<vector<int>>;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll>>;
using Vldd = vector<vector<ld>>;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n;
cin >> n;
string x;
cin >> x;
int d = 0;
rep(i, n) if (x[i] == '1') d++;
if (d == 0) {
rep(i, n) cout << 1 << endl;
return 0;
}
if (d == 1) {
Vi p(n);
Vi ans(n, -1);
int z = (x[n - 1] - '0') % 2;
rep(i, n) {
if (x[i] == '1')
p[i] == 0;
else
p[i] = 2;
if (p[i] == 0)
ans[i] = 0;
else {
if (z) {
if (i == n - 1)
ans[i] = 1;
else
ans[i] = 2;
} else {
if (i == n - 1)
ans[i] = 2;
else
ans[i] = 1;
}
}
}
for (int u : ans)
cout << u << endl;
return 0;
}
reverse(x.begin(), x.end());
Vi popx(n, 0);
rep(i, n) {
if (x[i] == '1')
popx[i] = d - 1;
else
popx[i] = d + 1;
}
int A[3] = {0};
for (int i = 0; i < 3; i++) {
int t = 1;
ll u = 0;
for (int j = 0; j < n; j++) {
if (x[j] == '1') {
u = (u + t) % (d - 1 + i);
}
t = (t * 2) % (d - 1 + i);
}
u %= (d - 1 + i);
A[i] = u;
}
Vi mod2(n, 0);
int t1 = 1, t2 = 1, t3 = 1;
rep(i, n) {
int u = popx[i];
if (x[i] == '0') {
if (u == d - 1) {
mod2[i] = (A[0] + t1) % u;
} else if (u == d) {
mod2[i] = (A[1] + t2) % u;
} else {
mod2[i] = (A[2] + t3) % u;
}
} else {
if (u == d - 1) {
mod2[i] = (u + A[0] - t1) % u;
} else if (u == d) {
mod2[i] = (u + A[1] - t2) % u;
} else {
mod2[i] = (u + A[2] - t3) % u;
}
}
t1 = (t1 * 2) % (d - 1);
t2 = (t2 * 2) % d;
t3 = (t3 * 2) % (d + 1);
}
reverse(mod2.begin(), mod2.end());
Vi ans(n, -1);
rep(i, n) {
if (mod2[i] == 0 && ans[i] == -1) {
ans[i] = 1;
continue;
}
int tans = 1;
while (mod2[i] > 0) {
int u = mod2[i];
bitset<32> t = bitset<32>(u);
int c = t.count();
if (c == 0)
break;
mod2[i] %= c;
tans++;
}
ans[i] = tans;
}
for (int u : ans) {
cout << u << endl;
}
}
| insert | 73 | 73 | 73 | 78 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define setDP(arr) memset(arr, -1, sizeof arr)
#define Clear(arr) memset(arr, 0, sizeof arr)
#define oo 1000000000
#define inf 1000000000000000000
#define M 998244353
using namespace std;
typedef long long ll;
const int N = 1e6 + 300;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2 * PI;
int n;
int dp[N];
char s[N];
int fast(int x, int y, int mod) {
if (!y)
return 1;
int ret = fast(x, y >> 1, mod);
ret = (ret * 1ll * ret) % mod;
if (y & 1)
ret = ret * 1ll * x % mod;
return ret;
}
int popcount(int x) {
int ctr = 0;
while (x) {
ctr += x & 1;
x >>= 1;
}
return ctr;
}
inline void solve() {
cin >> n;
dp[1] = 1;
for (int i = 2; i < N; i++) {
dp[i] = dp[i % (popcount(i))] + 1;
}
int ones = 0;
scanf("%s", s);
for (int i = 0; i < n; i++) {
ones += s[i] == '1';
}
if (ones == 0) {
for (int i = 0; i < n; i++) {
puts("1");
}
return;
}
int val1, val2, val3;
val1 = val2 = val3 = 0;
for (int i = 0; i < n; i++) {
val1 *= 2;
val2 *= 2;
val3 *= 2;
val1 += s[i] - '0';
val2 += s[i] - '0';
val3 += s[i] - '0';
val1 %= ones - 1;
val2 %= ones;
val3 %= ones + 1;
}
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
printf("%d\n",
1 + dp[(val3 + fast(2, n - i - 1, ones + 1)) % (ones + 1)]);
} else {
if (ones > 1)
printf("%d\n", 1 + dp[(ones - 1 + val1 - fast(2, n - i - 1, ones - 1)) %
(ones - 1)]);
else {
cout << 0 << endl;
}
}
}
}
signed main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define setDP(arr) memset(arr, -1, sizeof arr)
#define Clear(arr) memset(arr, 0, sizeof arr)
#define oo 1000000000
#define inf 1000000000000000000
#define M 998244353
using namespace std;
typedef long long ll;
const int N = 1e6 + 300;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2 * PI;
int n;
int dp[N];
char s[N];
int fast(int x, int y, int mod) {
if (!y)
return 1;
int ret = fast(x, y >> 1, mod);
ret = (ret * 1ll * ret) % mod;
if (y & 1)
ret = ret * 1ll * x % mod;
return ret;
}
int popcount(int x) {
int ctr = 0;
while (x) {
ctr += x & 1;
x >>= 1;
}
return ctr;
}
inline void solve() {
cin >> n;
dp[1] = 1;
for (int i = 2; i < N; i++) {
dp[i] = dp[i % (popcount(i))] + 1;
}
int ones = 0;
scanf("%s", s);
for (int i = 0; i < n; i++) {
ones += s[i] == '1';
}
if (ones == 0) {
for (int i = 0; i < n; i++) {
puts("1");
}
return;
}
int val1, val2, val3;
val1 = val2 = val3 = 0;
for (int i = 0; i < n; i++) {
val1 *= 2;
val2 *= 2;
val3 *= 2;
val1 += s[i] - '0';
val2 += s[i] - '0';
val3 += s[i] - '0';
if (ones - 1)
val1 %= ones - 1;
val2 %= ones;
val3 %= ones + 1;
}
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
printf("%d\n",
1 + dp[(val3 + fast(2, n - i - 1, ones + 1)) % (ones + 1)]);
} else {
if (ones > 1)
printf("%d\n", 1 + dp[(ones - 1 + val1 - fast(2, n - i - 1, ones - 1)) %
(ones - 1)]);
else {
cout << 0 << endl;
}
}
}
}
signed main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
| replace | 75 | 76 | 75 | 77 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
ll N, ans = 0, tmp = 0, tmpp = 0, tmpn = 0;
vector<ll> A;
string S;
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
signed main() {
cin >> N >> S;
for (int i = 0; i < N; i++) {
ll num = S[i] - '0';
if (num == 1)
tmp++;
A.push_back(num);
}
for (int i = 0; i < N; i++) {
if (A[N - 1 - i] == 1) {
tmpp += modpow(2, i, tmp + 1);
tmpp %= (tmp + 1);
if (tmpp < 0)
tmpp += tmp + 1;
tmpn += modpow(2, i, tmp - 1);
tmpn %= (tmp - 1);
if (tmpn < 0)
tmpn += tmp - 1;
}
}
for (int i = 0; i < N; i++) {
// cout << "OK" << endl;
ans = 1;
if (A[i] == 0) {
ll tmp2 = tmpp;
ll tmp3 = tmp + 1;
tmp2 += modpow(2, N - 1 - i, tmp3);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
while (tmp2 != 0) {
// cout << i << " " << tmp2 << endl;
tmp3 = __builtin_popcount(tmp2);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
ans++;
}
} else {
ll tmp2 = tmpn;
ll tmp3 = tmp - 1;
tmp2 -= modpow(2, N - 1 - i, tmp3);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
while (tmp2 != 0) {
// cout << i << " " << tmp2 << endl;
tmp3 = __builtin_popcount(tmp2);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
ans++;
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
ll N, ans = 0, tmp = 0, tmpp = 0, tmpn = 0;
vector<ll> A;
string S;
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
signed main() {
cin >> N >> S;
for (int i = 0; i < N; i++) {
ll num = S[i] - '0';
if (num == 1)
tmp++;
A.push_back(num);
}
if (tmp == 0) {
for (int i = 0; i < N; i++) {
cout << 1 << endl;
}
return 0;
}
if (tmp == 1) {
for (int i = 0; i < N; i++) {
if (A[N - 1 - i] == 1) {
tmpp += modpow(2, i, 2);
tmpp %= 2;
if (tmpp < 0)
tmpp += 2;
}
}
for (int i = 0; i < N; i++) {
if (A[i] == 1) {
cout << 0 << endl;
continue;
}
ll id = tmpp;
id += modpow(2, N - 1 - i, 2);
id %= 2;
if (id < 0)
id += 2;
if (id == 0)
cout << 1 << endl;
else
cout << 2 << endl;
}
return 0;
}
for (int i = 0; i < N; i++) {
if (A[N - 1 - i] == 1) {
tmpp += modpow(2, i, tmp + 1);
tmpp %= (tmp + 1);
if (tmpp < 0)
tmpp += tmp + 1;
tmpn += modpow(2, i, tmp - 1);
tmpn %= (tmp - 1);
if (tmpn < 0)
tmpn += tmp - 1;
}
}
for (int i = 0; i < N; i++) {
// cout << "OK" << endl;
ans = 1;
if (A[i] == 0) {
ll tmp2 = tmpp;
ll tmp3 = tmp + 1;
tmp2 += modpow(2, N - 1 - i, tmp3);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
while (tmp2 != 0) {
// cout << i << " " << tmp2 << endl;
tmp3 = __builtin_popcount(tmp2);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
ans++;
}
} else {
ll tmp2 = tmpn;
ll tmp3 = tmp - 1;
tmp2 -= modpow(2, N - 1 - i, tmp3);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
while (tmp2 != 0) {
// cout << i << " " << tmp2 << endl;
tmp3 = __builtin_popcount(tmp2);
tmp2 %= tmp3;
if (tmp2 < 0)
tmp2 += tmp3;
ans++;
}
}
cout << ans << endl;
}
return 0;
} | insert | 32 | 32 | 32 | 65 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
long long N, num = 0, xx, uu, dd;
char str[400000];
inline long long calc(long long x) {
long long b = x, rr = 0;
while (b > 0) {
if (b & 1)
++rr;
b >>= 1;
}
return x % rr;
}
inline void init() {
long long base1 = 1, base2 = 1, now1 = 0, now2 = 0;
for (int i = N; i >= 1; --i, base1 = base1 * 2ll, base2 = base2 * 2ll) {
if (str[i] == '0')
continue;
if (num - 1 != 0) {
now1 += base1 % (num - 1);
now1 %= (num - 1);
}
now2 += base2 % (num + 1);
now2 %= (num + 1);
base1 = base1 % (num - 1);
base2 = base2 % (num + 1);
}
uu = now2;
dd = now1;
}
inline long long fastpow(long long bass, long long b, long long mod) {
long long ret = 1, base = bass;
while (b > 0) {
if (b & 1)
ret = ret * base % mod;
base = base * base % mod;
b >>= 1;
}
return ret % mod;
}
int main() {
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
scanf("%lld", &N);
scanf("%s", str + 1);
for (int i = 1; i <= N; ++i)
if (str[i] == '1')
++num;
xx = num;
init();
for (int i = 1; i <= N; ++i) {
long long now = 0, ans = 0;
if (str[i] == '0') {
now = uu;
now = (now + fastpow(2, N - i, num + 1)) % (num + 1);
++ans;
while (now) {
++ans;
now = calc(now);
}
printf("%lld\n", ans);
} else {
if (num == 1)
printf("0\n");
else {
now = dd;
now = (now - fastpow(2, N - i, num - 1) + num - 1) % (num - 1);
++ans;
while (now) {
++ans;
now = calc(now);
}
printf("%lld\n", ans);
}
}
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
long long N, num = 0, xx, uu, dd;
char str[400000];
inline long long calc(long long x) {
long long b = x, rr = 0;
while (b > 0) {
if (b & 1)
++rr;
b >>= 1;
}
return x % rr;
}
inline void init() {
long long base1 = 1, base2 = 1, now1 = 0, now2 = 0;
for (int i = N; i >= 1; --i, base1 = base1 * 2ll, base2 = base2 * 2ll) {
if (str[i] == '0')
continue;
if (num - 1 != 0) {
now1 += base1 % (num - 1);
now1 %= (num - 1);
}
now2 += base2 % (num + 1);
now2 %= (num + 1);
if (num - 1 != 0)
base1 = base1 % (num - 1);
base2 = base2 % (num + 1);
}
uu = now2;
dd = now1;
}
inline long long fastpow(long long bass, long long b, long long mod) {
long long ret = 1, base = bass;
while (b > 0) {
if (b & 1)
ret = ret * base % mod;
base = base * base % mod;
b >>= 1;
}
return ret % mod;
}
int main() {
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
scanf("%lld", &N);
scanf("%s", str + 1);
for (int i = 1; i <= N; ++i)
if (str[i] == '1')
++num;
xx = num;
init();
for (int i = 1; i <= N; ++i) {
long long now = 0, ans = 0;
if (str[i] == '0') {
now = uu;
now = (now + fastpow(2, N - i, num + 1)) % (num + 1);
++ans;
while (now) {
++ans;
now = calc(now);
}
printf("%lld\n", ans);
} else {
if (num == 1)
printf("0\n");
else {
now = dd;
now = (now - fastpow(2, N - i, num - 1) + num - 1) % (num - 1);
++ans;
while (now) {
++ans;
now = calc(now);
}
printf("%lld\n", ans);
}
}
}
return 0;
} | replace | 39 | 40 | 39 | 41 | 0 | |
p02609 | C++ | Runtime Error | // #pragma warning(disable:4996)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <bitset>
#include <complex>
#include <cstdio>
#include <list>
// #include <stdio.h>
//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
// typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
int popcount(int N) {
int ans = 0;
int n = 0;
while ((N >> n) > 0) {
ans += (N >> n) & 1;
n++;
}
return ans;
}
int calc(int N) {
int ans = 0;
while (N > 0) {
int p = popcount(N);
N %= p;
ans++;
}
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
string S;
VI X(N);
char chr;
cin.get(chr);
for (int n = 0; n < N; n++) {
cin.get(chr);
// int c = (S[n] == '0' ? 0 : 1);
X[N - 1 - n] = chr - 48;
}
int N0 = 0;
for (int n = 0; n < N; n++)
N0 += X[n];
VI bnp(N, 0);
bnp[0] = 1 % (N0 + 1);
for (int n = 1; n < N; n++) {
bnp[n] = (bnp[n - 1] * 2) % (N0 + 1);
}
VI bnm(N, 0);
if (N0 - 1 != 0) {
bnm[0] = 1 % (N0 - 1);
for (int n = 1; n < N; n++) {
bnm[n] = (bnm[n - 1] * 2) % (N0 - 1);
}
}
int xnp = 0;
for (int n = 0; n < N; n++) {
if (X[n] == 1) {
xnp += bnp[n];
xnp %= (N0 + 1);
}
}
int xnm = 0;
if (N0 > 1) {
for (int n = 0; n < N; n++) {
if (X[n] == 1) {
xnm += bnm[n];
xnm %= (N0 - 1);
}
}
}
for (int n = N - 1; n >= 0; n--) {
if (X[n] == 0) {
int XX = (xnp + bnp[n]) % (N0 + 1);
cout << calc(XX) + 1 << "\n";
} else {
int XX = (xnm - bnm[n]) % (N0 - 1);
XX = (XX + N0 - 1) % (N0 - 1);
cout << calc(XX) + 1 << "\n";
}
}
return 0;
} | // #pragma warning(disable:4996)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <bitset>
#include <complex>
#include <cstdio>
#include <list>
// #include <stdio.h>
//< in.txt > out.txt
using namespace std;
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
// typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
int popcount(int N) {
int ans = 0;
int n = 0;
while ((N >> n) > 0) {
ans += (N >> n) & 1;
n++;
}
return ans;
}
int calc(int N) {
int ans = 0;
while (N > 0) {
int p = popcount(N);
N %= p;
ans++;
}
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
string S;
VI X(N);
char chr;
cin.get(chr);
for (int n = 0; n < N; n++) {
cin.get(chr);
// int c = (S[n] == '0' ? 0 : 1);
X[N - 1 - n] = chr - 48;
}
int N0 = 0;
for (int n = 0; n < N; n++)
N0 += X[n];
VI bnp(N, 0);
bnp[0] = 1 % (N0 + 1);
for (int n = 1; n < N; n++) {
bnp[n] = (bnp[n - 1] * 2) % (N0 + 1);
}
VI bnm(N, 0);
if (N0 - 1 != 0) {
bnm[0] = 1 % (N0 - 1);
for (int n = 1; n < N; n++) {
bnm[n] = (bnm[n - 1] * 2) % (N0 - 1);
}
}
int xnp = 0;
for (int n = 0; n < N; n++) {
if (X[n] == 1) {
xnp += bnp[n];
xnp %= (N0 + 1);
}
}
int xnm = 0;
if (N0 > 1) {
for (int n = 0; n < N; n++) {
if (X[n] == 1) {
xnm += bnm[n];
xnm %= (N0 - 1);
}
}
}
for (int n = N - 1; n >= 0; n--) {
if (X[n] == 0) {
int XX = (xnp + bnp[n]) % (N0 + 1);
cout << calc(XX) + 1 << "\n";
} else {
if (N0 == 1) {
cout << 0 << "\n";
continue;
}
int XX = (xnm - bnm[n]) % (N0 - 1);
XX = (XX + N0 - 1) % (N0 - 1);
cout << calc(XX) + 1 << "\n";
}
}
return 0;
}
| insert | 112 | 112 | 112 | 116 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int pcnt(int x) { return __builtin_popcount(x); }
int f(int x) {
if (x == 0)
return 0;
return f(x % pcnt(x)) + 1;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> x(n);
for (int i = 0; i < n; ++i)
x[i] = s[i] - '0';
int pc = 0;
for (int i = 0; i < n; ++i)
pc += x[i];
vector<int> ans(n);
for (int b = 0; b < 2; ++b) {
int npc = pc;
if (b == 0)
npc++;
else
npc--;
int r0 = 0;
for (int i = 0; i < n; ++i) {
r0 = (r0 * 2) % npc;
r0 += x[i];
}
int k = 1;
for (int i = n - 1; i >= 0; --i) {
if (x[i] == b) {
int r = r0;
if (b == 0)
r = (r + k) % npc;
else
r = (r - k + npc) % npc;
ans[i] = f(r) + 1;
}
k = (k * 2) % npc;
}
}
for (int i = 0; i < n; ++i) {
cout << ans[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int pcnt(int x) { return __builtin_popcount(x); }
int f(int x) {
if (x == 0)
return 0;
return f(x % pcnt(x)) + 1;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> x(n);
for (int i = 0; i < n; ++i)
x[i] = s[i] - '0';
int pc = 0;
for (int i = 0; i < n; ++i)
pc += x[i];
vector<int> ans(n);
for (int b = 0; b < 2; ++b) {
int npc = pc;
if (b == 0)
npc++;
else
npc--;
if (npc <= 0)
continue;
int r0 = 0;
for (int i = 0; i < n; ++i) {
r0 = (r0 * 2) % npc;
r0 += x[i];
}
int k = 1;
for (int i = n - 1; i >= 0; --i) {
if (x[i] == b) {
int r = r0;
if (b == 0)
r = (r + k) % npc;
else
r = (r - k + npc) % npc;
ans[i] = f(r) + 1;
}
k = (k * 2) % npc;
}
}
for (int i = 0; i < n; ++i) {
cout << ans[i] << endl;
}
return 0;
}
| insert | 30 | 30 | 30 | 33 | 0 | |
p02609 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
#define itrep1(ITR, CONT) \
for (auto ITR = next(begin(CONT)); ITR != end(CONT); ITR++)
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void prec(const int &DIG) {
cerr << fixed << setprecision(DIG);
cout << fixed << setprecision(DIG);
}
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
template <typename T1, typename T2> void CERR(const pair<T1, T2> &PAIR) {
cerr << "(";
CERR(PAIR.first);
cerr << ", ";
CERR(PAIR.second);
cerr << ")";
}
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR1(const vector<T> &VEC) {
cerr << "{ ";
itrep1(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const set<T> &SET) {
cerr << "{ ";
itrep(ITR, SET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const multiset<T> &MULTISET) {
cerr << "{ ";
itrep(ITR, MULTISET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T1, typename T2> void CERR(const map<T1, T2> &MAP) {
cerr << "{ ";
itrep(ITR, MAP) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define db(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << ", "
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
#define db1(OBJ) \
cerr << #OBJ << ": "; \
CERR1(OBJ); \
cerr << "\n"
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define dbvv(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db01(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db10(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db11(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = 1'000'000'000'000'000'007;
const int INF = 1'000'000'007; // Bについて,傾きが20億になることがある(?)
const ll MOD = 1'000'000'007; // 998'244'353;
int N;
string X;
vi fx;
int f(int n) {
int res = 0;
while (n > 0) {
n = n % __builtin_popcount(n);
res++;
}
return res;
}
int solve(int x) {
int res = 1;
rep(i, N) {
x = f(x);
res++;
}
return res;
}
int main() {
cin >> N;
cin >> X;
reverse(all(X));
int p = 0;
rep(i, N) if (X[i] == '1') p++;
// dbl(X); dbl(p);
// Nをp+1,p-1で割った余り
int r1 = 0, r2 = 0, R1 = 1, R2 = 1;
rep(i, N) {
if (X[i] == '1') {
r1 = (r1 + R1) % (p + 1);
r2 = (r2 + R2) % (p - 1);
}
R1 = (R1 * 2) % (p + 1);
R2 = (R2 * 2) % (p - 1);
}
// dbs(r1, r2);
fx = vi(N);
int s1 = 1, s2 = 1; // 2^i%(p+1),2^i%(p-1)
rep(i, N) {
if (X[i] == '1') {
fx[i] = ((r2 - s2) + (p - 1)) % (p - 1);
} else if (X[i] == '0') {
fx[i] = (r1 + s1) % (p + 1);
}
s1 = (s1 * 2) % (p + 1);
s2 = (s2 * 2) % (p - 1);
}
// dbvv(fx);
rep3(i, N - 1, -1) cout << f(fx[i]) + 1 << endl;
} | #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
#define itrep1(ITR, CONT) \
for (auto ITR = next(begin(CONT)); ITR != end(CONT); ITR++)
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void prec(const int &DIG) {
cerr << fixed << setprecision(DIG);
cout << fixed << setprecision(DIG);
}
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
template <typename T1, typename T2> void CERR(const pair<T1, T2> &PAIR) {
cerr << "(";
CERR(PAIR.first);
cerr << ", ";
CERR(PAIR.second);
cerr << ")";
}
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR1(const vector<T> &VEC) {
cerr << "{ ";
itrep1(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const set<T> &SET) {
cerr << "{ ";
itrep(ITR, SET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const multiset<T> &MULTISET) {
cerr << "{ ";
itrep(ITR, MULTISET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T1, typename T2> void CERR(const map<T1, T2> &MAP) {
cerr << "{ ";
itrep(ITR, MAP) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define db(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << ", "
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
#define db1(OBJ) \
cerr << #OBJ << ": "; \
CERR1(OBJ); \
cerr << "\n"
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define dbvv(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db01(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db10(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db11(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = 1'000'000'000'000'000'007;
const int INF = 1'000'000'007; // Bについて,傾きが20億になることがある(?)
const ll MOD = 1'000'000'007; // 998'244'353;
int N;
string X;
vi fx;
int f(int n) {
int res = 0;
while (n > 0) {
n = n % __builtin_popcount(n);
res++;
}
return res;
}
int solve(int x) {
int res = 1;
rep(i, N) {
x = f(x);
res++;
}
return res;
}
int main() {
cin >> N;
cin >> X;
reverse(all(X));
int p = 0;
rep(i, N) if (X[i] == '1') p++;
if (p == 0) {
rep(i, N) cout << 1 << endl;
return 0;
} else if (p == 1) {
int k;
rep(i, N) if (X[i] == '1') k = i;
rep3(i, N - 1, -1) {
if (i == k)
cout << 0 << endl;
else if (k == 0)
cout << 2 << endl;
else if (i == 0)
cout << 2 << endl;
else
cout << 1 << endl;
}
return 0;
}
// dbl(X); dbl(p);
// Nをp+1,p-1で割った余り
int r1 = 0, r2 = 0, R1 = 1, R2 = 1;
rep(i, N) {
if (X[i] == '1') {
r1 = (r1 + R1) % (p + 1);
r2 = (r2 + R2) % (p - 1);
}
R1 = (R1 * 2) % (p + 1);
R2 = (R2 * 2) % (p - 1);
}
// dbs(r1, r2);
fx = vi(N);
int s1 = 1, s2 = 1; // 2^i%(p+1),2^i%(p-1)
rep(i, N) {
if (X[i] == '1') {
fx[i] = ((r2 - s2) + (p - 1)) % (p - 1);
} else if (X[i] == '0') {
fx[i] = (r1 + s1) % (p + 1);
}
s1 = (s1 * 2) % (p + 1);
s2 = (s2 * 2) % (p - 1);
}
// dbvv(fx);
rep3(i, N - 1, -1) cout << f(fx[i]) + 1 << endl;
} | insert | 174 | 174 | 174 | 193 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
int cnt = 0;
for (auto c : s) {
cnt += (c == '1');
}
auto poly = [&](int mod) {
vector<int> r(n);
r[0] = 1;
for (int i = 1; i < n; i++) {
r[i] = r[i - 1] * 2 % mod;
}
return r;
};
auto f = [&](vector<int> &a, int mod) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum = (sum + (s[i] - '0') * a[n - 1 - i]) % mod;
}
return sum;
};
// one 1 to 0
auto a0 = poly(cnt - 1);
int r0 = f(a0, cnt - 1);
auto a1 = poly(cnt + 1);
int r1 = f(a1, cnt + 1);
auto solve = [](int x) {
int res = 0;
while (x) {
int cnt = __builtin_popcount(x);
x = x % cnt;
res++;
}
return res;
};
for (int i = 0; i < n; i++) {
int sum;
if (s[i] == '1') {
sum = (r0 - a0[n - 1 - i]) % (cnt - 1);
if (sum < 0)
sum += (cnt - 1);
} else {
sum = (r1 + a1[n - 1 - i]) % (cnt + 1);
if (sum < 0)
sum += (cnt + 1);
}
cout << solve(sum) + 1 << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
int cnt = 0;
for (auto c : s) {
cnt += (c == '1');
}
// special
if (cnt == 0) {
for (int i = 0; i < n; i++) {
cout << 1 << '\n';
}
return 0;
}
if (cnt == 1) {
for (int i = 0; i < n; i++) {
if (s[i] == '1')
cout << 0 << '\n';
else {
if (s[n - 1] == '1' || i == n - 1)
cout << 2 << '\n';
else
cout << 1 << '\n';
}
}
return 0;
}
auto poly = [&](int mod) {
vector<int> r(n);
r[0] = 1;
for (int i = 1; i < n; i++) {
r[i] = r[i - 1] * 2 % mod;
}
return r;
};
auto f = [&](vector<int> &a, int mod) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum = (sum + (s[i] - '0') * a[n - 1 - i]) % mod;
}
return sum;
};
// one 1 to 0
auto a0 = poly(cnt - 1);
int r0 = f(a0, cnt - 1);
auto a1 = poly(cnt + 1);
int r1 = f(a1, cnt + 1);
auto solve = [](int x) {
int res = 0;
while (x) {
int cnt = __builtin_popcount(x);
x = x % cnt;
res++;
}
return res;
};
for (int i = 0; i < n; i++) {
int sum;
if (s[i] == '1') {
sum = (r0 - a0[n - 1 - i]) % (cnt - 1);
if (sum < 0)
sum += (cnt - 1);
} else {
sum = (r1 + a1[n - 1 - i]) % (cnt + 1);
if (sum < 0)
sum += (cnt + 1);
}
cout << solve(sum) + 1 << '\n';
}
return 0;
}
| insert | 14 | 14 | 14 | 35 | 0 | |
p02609 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define p_ary(ary, a, b) \
do { \
cout << "["; \
for (int count = (a); count < (b); ++count) \
cout << ary[count] << ((b)-1 == count ? "" : ", "); \
cout << "]\n"; \
} while (0)
#define p_map(map, it) \
do { \
cout << "{"; \
for (auto(it) = map.begin();; ++(it)) { \
if ((it) == map.end()) { \
cout << "}\n"; \
break; \
} else \
cout << "" << (it)->first << "=>" << (it)->second << ", "; \
} \
} while (0)
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
os << "(" << a.first << ", " << a.second << ")";
return os;
}
const char newl = '\n';
int main() {
int n;
string x;
cin >> n >> x;
int cnt = 0;
for (int i = 0; i < n; ++i)
cnt += (x[i] == '1');
reverse(x.begin(), x.end());
vector<int> m1(n, 0), m2(n, 0);
int sum1 = 0, sum2 = 0;
m1[0] = m2[0] = 1;
if (cnt - 1)
for (int i = 1; i < n; ++i)
m1[i] = m1[i - 1] * 2 % (cnt - 1);
for (int i = 1; i < n; ++i)
m2[i] = m2[i - 1] * 2 % (cnt + 1);
if (cnt - 1)
for (int i = 0; i < n; ++i)
if (x[i] == '1')
(sum1 += m1[i]) %= cnt - 1;
for (int i = 0; i < n; ++i)
if (x[i] == '1')
(sum2 += m2[i]) %= cnt + 1;
for (int j = 0; j < n; ++j) {
int i = n - 1 - j;
int ans = 0, mod, sum;
if (x[i] == '0') {
mod = cnt + 1;
sum = sum2 + m2[i];
ans++;
} else {
mod = cnt - 1;
sum = sum1 - m1[i] + mod;
if (mod)
ans++;
}
if (mod)
sum %= mod;
while (sum) {
int d = 0;
for (int j = 0; j < 20; ++j)
if ((sum >> j) & 1)
d++;
sum %= d;
ans++;
}
cout << ans << newl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define p_ary(ary, a, b) \
do { \
cout << "["; \
for (int count = (a); count < (b); ++count) \
cout << ary[count] << ((b)-1 == count ? "" : ", "); \
cout << "]\n"; \
} while (0)
#define p_map(map, it) \
do { \
cout << "{"; \
for (auto(it) = map.begin();; ++(it)) { \
if ((it) == map.end()) { \
cout << "}\n"; \
break; \
} else \
cout << "" << (it)->first << "=>" << (it)->second << ", "; \
} \
} while (0)
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
os << "(" << a.first << ", " << a.second << ")";
return os;
}
const char newl = '\n';
int main() {
int n;
string x;
cin >> n >> x;
int cnt = 0;
for (int i = 0; i < n; ++i)
cnt += (x[i] == '1');
reverse(x.begin(), x.end());
vector<int> m1(n, 0), m2(n, 0);
int sum1 = 0, sum2 = 0;
m1[0] = m2[0] = 1;
if (cnt - 1)
for (int i = 1; i < n; ++i)
m1[i] = m1[i - 1] * 2 % (cnt - 1);
for (int i = 1; i < n; ++i)
m2[i] = m2[i - 1] * 2 % (cnt + 1);
if (cnt - 1)
for (int i = 0; i < n; ++i)
if (x[i] == '1')
(sum1 += m1[i]) %= cnt - 1;
for (int i = 0; i < n; ++i)
if (x[i] == '1')
(sum2 += m2[i]) %= cnt + 1;
for (int j = 0; j < n; ++j) {
int i = n - 1 - j;
int ans = 0, mod, sum;
if (x[i] == '0') {
mod = cnt + 1;
sum = sum2 + m2[i];
ans++;
} else {
mod = cnt - 1;
sum = sum1 - m1[i] + mod;
if (mod)
ans++;
}
if (mod)
sum %= mod;
while (sum && mod) {
int d = 0;
for (int j = 0; j < 20; ++j)
if ((sum >> j) & 1)
d++;
sum %= d;
ans++;
}
cout << ans << newl;
}
} | replace | 71 | 72 | 71 | 72 | TLE | |
p02609 | C++ | Runtime Error | #pragma GCC optimize("O3") // コンパイラ最適化用
#define _GLIBCXX_DEBUG // 配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) // ループ変数は1ずつデクリ
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--) // ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
ll pcnt(ll x) { return __builtin_popcountll(x); }
ll f(ll x) {
if (x == 0) {
return 0;
}
return f(x % pcnt(x)) + 1;
}
int main() {
ll n;
cin >> n;
string s;
cin >> s;
vector<ll> x(n);
REP(i, n) { x[i] = s[i] - '0'; }
ll pc = 0;
vector<ll> ans(n);
REP(i, n) { pc += x[i]; }
REP(b, 2) {
ll npc = pc;
if (b == 0) {
npc++;
} else {
npc--;
}
ll r0 = 0;
REP(i, n) {
r0 = (r0 * 2) % npc;
r0 += x[i];
}
ll k = 1;
REPD(i, n) {
if (x[i] == b) {
ll r = r0;
if (b == 0) {
r = (r + k) % npc;
} else {
r = (r - k + npc) % npc;
}
ans[i] = f(r) + 1;
}
k = (k * 2) % npc;
}
}
REP(i, n) { cout << ans[i] << endl; }
}
| #pragma GCC optimize("O3") // コンパイラ最適化用
#define _GLIBCXX_DEBUG // 配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) // ループ変数は1ずつデクリ
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--) // ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
ll pcnt(ll x) { return __builtin_popcountll(x); }
ll f(ll x) {
if (x == 0) {
return 0;
}
return f(x % pcnt(x)) + 1;
}
int main() {
ll n;
cin >> n;
string s;
cin >> s;
vector<ll> x(n);
REP(i, n) { x[i] = s[i] - '0'; }
ll pc = 0;
vector<ll> ans(n);
REP(i, n) { pc += x[i]; }
REP(b, 2) {
ll npc = pc;
if (b == 0) {
npc++;
} else {
npc--;
}
if (npc == 0)
continue;
ll r0 = 0;
REP(i, n) {
r0 = (r0 * 2) % npc;
r0 += x[i];
}
ll k = 1;
REPD(i, n) {
if (x[i] == b) {
ll r = r0;
if (b == 0) {
r = (r + k) % npc;
} else {
r = (r - k + npc) % npc;
}
ans[i] = f(r) + 1;
}
k = (k * 2) % npc;
}
}
REP(i, n) { cout << ans[i] << endl; }
}
| insert | 62 | 62 | 62 | 64 | 0 | |
p02609 | C++ | Runtime Error | #ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FAST ;
#else
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9 + 7;
signed main() {
FAST;
int n;
string x;
cin >> n >> x;
reverse(All(x));
vector<int> ans(n);
int c = 0;
Fr(j, 0, n) c += x[j] == '1';
auto f = [&](char t, int z) {
const int mod = c + z;
int k = 0, r = 1;
Fr(i, 0, n) {
k = (k + r * (x[i] == '1')) % mod;
r = r * 2 % mod;
}
r = (z + mod) % mod;
Fr(i, 0, n) {
if (x[i] == t) {
ans[i] = 1;
int y = (k + r) % mod;
while (y) {
ans[i]++;
y = y % __builtin_popcount(y);
}
}
r = r * 2 % mod;
}
};
f('1', -1);
f('0', +1);
reverse(All(ans));
Fr(i, 0, n) cout << ans[i] << endl;
}
| #ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FAST ;
#else
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9 + 7;
signed main() {
FAST;
int n;
string x;
cin >> n >> x;
reverse(All(x));
vector<int> ans(n);
int c = 0;
Fr(j, 0, n) c += x[j] == '1';
auto f = [&](char t, int z) {
const int mod = c + z;
if (!mod)
return;
int k = 0, r = 1;
Fr(i, 0, n) {
k = (k + r * (x[i] == '1')) % mod;
r = r * 2 % mod;
}
r = (z + mod) % mod;
Fr(i, 0, n) {
if (x[i] == t) {
ans[i] = 1;
int y = (k + r) % mod;
while (y) {
ans[i]++;
y = y % __builtin_popcount(y);
}
}
r = r * 2 % mod;
}
};
f('1', -1);
f('0', +1);
reverse(All(ans));
Fr(i, 0, n) cout << ans[i] << endl;
}
| insert | 37 | 37 | 37 | 39 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pll = pair<ll, ll>;
#define all(v) v.begin(), v.end()
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double pie = acos(-1);
vll dx4 = {-1, 0, 1, 0};
vll dy4 = {0, -1, 0, 1};
vll dx8 = {-1, 0, 1, 1, 1, 0, -1, -1};
vll dy8 = {-1, -1, -1, 0, 1, 1, 1, 0};
void fix_cout() { cout << fixed << setprecision(20); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void chmax(ll &a, ll b) {
if (a < b)
a = b;
}
void chmin(ll &a, ll b) {
if (a > b)
a = b;
}
ll modpow(ll a, ll b, ll m) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
b >>= 1;
a = a * a % m;
}
return res;
}
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll a = 0, b = 0;
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (s.at(i) == '1');
for (int i = 0; i < n; i++) {
if (s.at(i) == '1') {
a += modpow(2, n - i - 1, cnt + 1);
b += modpow(2, n - i - 1, cnt - 1);
}
}
for (int i = 0; i < n; i++) {
ll tmp, ans = 1, sub = 0;
if (s.at(i) == '1') {
tmp = (b - modpow(2, n - i - 1, cnt - 1) + cnt - 1) % (cnt - 1);
while (tmp) {
ans++;
sub = 0;
for (int j = 0; j < 64; j++)
sub += (tmp >> j & 1);
tmp = tmp % sub;
}
} else {
tmp = (a + modpow(2, n - i - 1, cnt + 1)) % (cnt + 1);
while (tmp) {
ans++;
sub = 0;
for (int j = 0; j < 64; j++)
sub += (tmp >> j & 1);
tmp = tmp % sub;
}
}
cout << ans << endl;
}
} | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pll = pair<ll, ll>;
#define all(v) v.begin(), v.end()
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double pie = acos(-1);
vll dx4 = {-1, 0, 1, 0};
vll dy4 = {0, -1, 0, 1};
vll dx8 = {-1, 0, 1, 1, 1, 0, -1, -1};
vll dy8 = {-1, -1, -1, 0, 1, 1, 1, 0};
void fix_cout() { cout << fixed << setprecision(20); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void chmax(ll &a, ll b) {
if (a < b)
a = b;
}
void chmin(ll &a, ll b) {
if (a > b)
a = b;
}
ll modpow(ll a, ll b, ll m) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
b >>= 1;
a = a * a % m;
}
return res;
}
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll a = 0, b = 0;
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (s.at(i) == '1');
if (cnt == 0) {
for (int i = 0; i < n; i++)
cout << 1 << endl;
return 0;
}
if (cnt == 1) {
for (int i = 0; i < n; i++) {
if (s.at(i) == '1')
cout << 0 << endl;
else if (i == n - 1)
cout << 2 << endl;
else
cout << 1 << endl;
}
return 0;
}
for (int i = 0; i < n; i++) {
if (s.at(i) == '1') {
a += modpow(2, n - i - 1, cnt + 1);
b += modpow(2, n - i - 1, cnt - 1);
}
}
for (int i = 0; i < n; i++) {
ll tmp, ans = 1, sub = 0;
if (s.at(i) == '1') {
tmp = (b - modpow(2, n - i - 1, cnt - 1) + cnt - 1) % (cnt - 1);
while (tmp) {
ans++;
sub = 0;
for (int j = 0; j < 64; j++)
sub += (tmp >> j & 1);
tmp = tmp % sub;
}
} else {
tmp = (a + modpow(2, n - i - 1, cnt + 1)) % (cnt + 1);
while (tmp) {
ans++;
sub = 0;
for (int j = 0; j < 64; j++)
sub += (tmp >> j & 1);
tmp = tmp % sub;
}
}
cout << ans << endl;
}
} | insert | 69 | 69 | 69 | 85 | 0 | |
p02609 | C++ | Runtime Error | #pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
if (!(s)) \
cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
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 << ' ';
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i];
if (i != len - 1)
s << '\n';
}
return s;
}
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;
}
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
#pragma endregion
int ff(int n) {
int res = 0;
while (n != 0) {
res++;
n %= __builtin_popcount(n);
}
return res;
}
signed main() {
int N;
cin >> N;
string X;
cin >> X;
int B = 0;
for (char c : X) {
B += c == '1';
}
int Bp = B + 1, Bm = B - 1;
int Sp = 0, Sm = 0;
for (char c : X) {
Sp = Sp * 2 + c - '0';
Sp %= Bp;
Sm = Sm * 2 + c - '0';
Sm %= Bm;
}
vector<int> Rp(N), Rm(N);
int tp = 1, tm = 1;
rep(i, N) {
tp %= Bp;
Rp[i] = tp;
tp *= 2;
tm %= Bm;
Rm[i] = tm;
tm *= 2;
}
reverse(all(Rp));
reverse(all(Rm));
rep(i, N) {
int n;
if (X[i] == '1') { // m
n = Sm - Rm[i];
n = (n + Bm) % Bm;
} else {
n = Sp + Rp[i];
n %= Bp;
}
int ans = ff(n) + 1;
cout << ans << endl;
}
} | #pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
if (!(s)) \
cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
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 << ' ';
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i];
if (i != len - 1)
s << '\n';
}
return s;
}
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;
}
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
#pragma endregion
int ff(int n) {
int res = 0;
while (n != 0) {
res++;
n %= __builtin_popcount(n);
}
return res;
}
signed main() {
int N;
cin >> N;
string X;
cin >> X;
int B = 0;
for (char c : X) {
B += c == '1';
}
int Bp = B + 1, Bm = B - 1;
if (Bm == 0) {
vector<int> R(N);
int t = 1;
rep(i, N) {
t %= 2;
R[i] = t;
t *= 2;
}
reverse(all(R));
int ind = -1;
rep(i, N) {
if (X[i] == '1') {
ind = i;
break;
}
}
rep(i, N) {
if (X[i] == '1')
cout << 0 << endl;
else {
int temp = R[ind] + R[i];
temp %= 2;
int ans = ff(temp) + 1;
cout << ans << endl;
}
}
return 0;
}
int Sp = 0, Sm = 0;
for (char c : X) {
Sp = Sp * 2 + c - '0';
Sp %= Bp;
Sm = Sm * 2 + c - '0';
Sm %= Bm;
}
vector<int> Rp(N), Rm(N);
int tp = 1, tm = 1;
rep(i, N) {
tp %= Bp;
Rp[i] = tp;
tp *= 2;
tm %= Bm;
Rm[i] = tm;
tm *= 2;
}
reverse(all(Rp));
reverse(all(Rm));
rep(i, N) {
int n;
if (X[i] == '1') { // m
n = Sm - Rm[i];
n = (n + Bm) % Bm;
} else {
n = Sp + Rp[i];
n %= Bp;
}
int ans = ff(n) + 1;
cout << ans << endl;
}
} | insert | 93 | 93 | 93 | 125 | 0 | |
p02609 | Python | Runtime Error | import math
def f(n):
pop = 0
ntemp = n
for i in range(int(math.log2(n)) + 1):
pop += ntemp % 2
ntemp //= 2
return n % pop
n = int(input())
S = input()
popcount = 0
for i in range(n):
popcount += int(S[i])
Sint = int(S, 2)
remminus = Sint % (popcount - 1)
remplus = Sint % (popcount + 1)
# 1,2,4,...の余りのリストを準備
remlistminus = []
remlistplus = []
temp = 1
for i in range(n):
remlistminus.append(temp)
temp = (temp * 2) % (popcount - 1)
temp = 1
for i in range(n):
remlistplus.append(temp)
temp = (temp * 2) % (popcount + 1)
remlistminus.reverse()
remlistplus.reverse()
ans = []
for i in range(n):
count = 1
if S[i] == "0":
rem = (remplus + remlistplus[i]) % (popcount + 1)
while rem > 0:
rem = f(rem)
count += 1
else:
rem = (remminus - remlistminus[i]) % (popcount - 1)
while rem > 0:
rem = f(rem)
count += 1
ans.append(count)
for i in range(n):
print(ans[i])
| import math
def f(n):
pop = 0
ntemp = n
for i in range(int(math.log2(n)) + 1):
pop += ntemp % 2
ntemp //= 2
return n % pop
n = int(input())
S = input()
popcount = 0
for i in range(n):
popcount += int(S[i])
# 1が1個しかない場合の例外処理
if popcount == 1:
if S[-1] == 1:
ans = [2] * n
ans[-1] = 0
else:
ans = [1] * n
ans[-1] = 2
for i in range(n):
if S[i] == "1":
ans[i] = 0
for i in range(n):
print(ans[i])
exit()
Sint = int(S, 2)
remminus = Sint % (popcount - 1)
remplus = Sint % (popcount + 1)
# 1,2,4,...の余りのリストを準備
remlistminus = []
remlistplus = []
temp = 1
for i in range(n):
remlistminus.append(temp)
temp = (temp * 2) % (popcount - 1)
temp = 1
for i in range(n):
remlistplus.append(temp)
temp = (temp * 2) % (popcount + 1)
remlistminus.reverse()
remlistplus.reverse()
ans = []
for i in range(n):
count = 1
if S[i] == "0":
rem = (remplus + remlistplus[i]) % (popcount + 1)
while rem > 0:
rem = f(rem)
count += 1
else:
rem = (remminus - remlistminus[i]) % (popcount - 1)
while rem > 0:
rem = f(rem)
count += 1
ans.append(count)
for i in range(n):
print(ans[i])
| insert | 17 | 17 | 17 | 34 | 0 | |
p02609 | C++ | Runtime Error | // #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template <typename T = ll> using v = vector<T>;
template <typename T = ll> using vv = v<v<T>>;
template <typename T = ll, typename U = ll> using p = pair<T, U>;
template <typename T> T chmin(T &a, T b) { return a = min(a, b); }
template <typename T> T chmax(T &a, T b) { return a = max(a, b); }
const ll INF = (ll)1e9;
template <int MOD> struct ModInt {
using lint = long long;
int val;
// constructor
ModInt(lint v = 0) : val(v % MOD) {
if (val < 0)
val += MOD;
};
// unary operator
ModInt operator+() const { return ModInt(val); }
ModInt operator-() const { return ModInt(MOD - val); }
ModInt inv() const { return this->pow(MOD - 2); }
// arithmetic
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
ModInt pow(lint n) const {
auto x = ModInt(1);
auto b = *this;
while (n > 0) {
if (n & 1)
x *= b;
n >>= 1;
b *= b;
}
return x;
}
// compound assignment
ModInt &operator+=(const ModInt &x) {
if ((val += x.val) >= MOD)
val -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &x) {
if ((val -= x.val) < 0)
val += MOD;
return *this;
}
ModInt &operator*=(const ModInt &x) {
val = lint(val) * x.val % MOD;
return *this;
}
ModInt &operator/=(const ModInt &x) { return *this *= x.inv(); }
//
ModInt operator++(int) {
auto t = *this;
*this += 1;
return t;
}
ModInt operator--(int) {
auto t = *this;
*this -= 1;
return t;
}
ModInt operator<<(const int n) { return ModInt(*this) * ModInt(2).pow(n); }
// compare
bool operator==(const ModInt &b) const { return val == b.val; }
bool operator!=(const ModInt &b) const { return val != b.val; }
// I/O
friend std::istream &operator>>(std::istream &is, ModInt &x) noexcept {
return is >> x.val;
}
friend std::ostream &operator<<(std::ostream &os, const ModInt &x) noexcept {
return os << x.val;
}
};
constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
void a() {
ll L, R, d;
cin >> L >> R >> d;
ll cnt = d;
ll ans = 0;
if (R < d) {
cout << 0 << endl;
return;
}
while (cnt <= R) {
if (L <= cnt)
ans++;
cnt += d;
}
cout << ans << endl;
}
void b() {
ll N;
cin >> N;
auto A = v<>(N, 0);
rep(i, N) cin >> A[i];
ll ans = 0;
for (ll i = 0; i < N; i += 2) {
if (A[i] % 2)
ans++;
}
cout << ans;
}
void c() {
ll N;
cin >> N;
for (ll n = 1; n <= N; n++) {
ll cnt = 0;
for (ll x = 1; x * x < n; x++)
for (ll y = 1; x * x + y * y + y * x < n; y++)
for (ll z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= n;
z++) {
if (x * x + y * y + z * z + x * y + y * z + z * x == n) {
cnt++;
break;
}
}
cout << cnt << endl;
}
}
ll popcount(ll x) { return __builtin_popcount(x); }
ll f(ll x) {
if (x == 0)
return 0;
return f(x % popcount(x)) + 1;
}
void d() {
ll N;
cin >> N;
string s;
cin >> s;
v<> x(N, 0);
rep(i, N) { x[i] = s[i] - '0'; }
ll pct = accumulate(all(x), 0);
v<> ans(N + 1, 0);
rep(b, 2) {
ll npct = (b == 0) ? pct + 1 : pct - 1;
ll n = 0;
for (ll i = 0; i < N; i++) {
n = (n * 2) % npct;
n += x[i];
}
ll k = 1;
for (ll i = N - 1; i >= 0; i--) {
if (x[i] == b) {
ll nn = 0;
if (b == 0)
nn = (n + k) % npct;
else
nn = (n - k + npct) % npct;
ans[i] = f(nn) + 1;
}
k = (k * 2) % npct;
}
}
rep(i, N) { cout << ans[i] << endl; }
}
int main() { d(); } | // #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template <typename T = ll> using v = vector<T>;
template <typename T = ll> using vv = v<v<T>>;
template <typename T = ll, typename U = ll> using p = pair<T, U>;
template <typename T> T chmin(T &a, T b) { return a = min(a, b); }
template <typename T> T chmax(T &a, T b) { return a = max(a, b); }
const ll INF = (ll)1e9;
template <int MOD> struct ModInt {
using lint = long long;
int val;
// constructor
ModInt(lint v = 0) : val(v % MOD) {
if (val < 0)
val += MOD;
};
// unary operator
ModInt operator+() const { return ModInt(val); }
ModInt operator-() const { return ModInt(MOD - val); }
ModInt inv() const { return this->pow(MOD - 2); }
// arithmetic
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
ModInt pow(lint n) const {
auto x = ModInt(1);
auto b = *this;
while (n > 0) {
if (n & 1)
x *= b;
n >>= 1;
b *= b;
}
return x;
}
// compound assignment
ModInt &operator+=(const ModInt &x) {
if ((val += x.val) >= MOD)
val -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &x) {
if ((val -= x.val) < 0)
val += MOD;
return *this;
}
ModInt &operator*=(const ModInt &x) {
val = lint(val) * x.val % MOD;
return *this;
}
ModInt &operator/=(const ModInt &x) { return *this *= x.inv(); }
//
ModInt operator++(int) {
auto t = *this;
*this += 1;
return t;
}
ModInt operator--(int) {
auto t = *this;
*this -= 1;
return t;
}
ModInt operator<<(const int n) { return ModInt(*this) * ModInt(2).pow(n); }
// compare
bool operator==(const ModInt &b) const { return val == b.val; }
bool operator!=(const ModInt &b) const { return val != b.val; }
// I/O
friend std::istream &operator>>(std::istream &is, ModInt &x) noexcept {
return is >> x.val;
}
friend std::ostream &operator<<(std::ostream &os, const ModInt &x) noexcept {
return os << x.val;
}
};
constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
void a() {
ll L, R, d;
cin >> L >> R >> d;
ll cnt = d;
ll ans = 0;
if (R < d) {
cout << 0 << endl;
return;
}
while (cnt <= R) {
if (L <= cnt)
ans++;
cnt += d;
}
cout << ans << endl;
}
void b() {
ll N;
cin >> N;
auto A = v<>(N, 0);
rep(i, N) cin >> A[i];
ll ans = 0;
for (ll i = 0; i < N; i += 2) {
if (A[i] % 2)
ans++;
}
cout << ans;
}
void c() {
ll N;
cin >> N;
for (ll n = 1; n <= N; n++) {
ll cnt = 0;
for (ll x = 1; x * x < n; x++)
for (ll y = 1; x * x + y * y + y * x < n; y++)
for (ll z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= n;
z++) {
if (x * x + y * y + z * z + x * y + y * z + z * x == n) {
cnt++;
break;
}
}
cout << cnt << endl;
}
}
ll popcount(ll x) { return __builtin_popcount(x); }
ll f(ll x) {
if (x == 0)
return 0;
return f(x % popcount(x)) + 1;
}
void d() {
ll N;
cin >> N;
string s;
cin >> s;
v<> x(N, 0);
rep(i, N) { x[i] = s[i] - '0'; }
ll pct = accumulate(all(x), 0);
v<> ans(N + 1, 0);
rep(b, 2) {
ll npct = (b == 0) ? pct + 1 : pct - 1;
ll n = 0;
if (npct == 0)
continue;
for (ll i = 0; i < N; i++) {
n = (n * 2) % npct;
n += x[i];
}
ll k = 1;
for (ll i = N - 1; i >= 0; i--) {
if (x[i] == b) {
ll nn = 0;
if (b == 0)
nn = (n + k) % npct;
else
nn = (n - k + npct) % npct;
ans[i] = f(nn) + 1;
}
k = (k * 2) % npct;
}
}
rep(i, N) { cout << ans[i] << endl; }
}
int main() { d(); } | insert | 175 | 175 | 175 | 177 | 0 | |
p02609 | Python | Runtime Error | N = int(input())
X = input()
Xi = int(X, 2)
c0 = X.count("1")
Xp = Xi % (c0 + 1)
Xm = Xi % (c0 - 1)
for i, x in enumerate(X):
if x == "1":
if c0 == 1:
print(0)
continue
y = (Xm - pow(2, N - 1 - i, c0 - 1)) % (c0 - 1)
else:
y = (Xp + pow(2, N - 1 - i, c0 + 1)) % (c0 + 1)
ans = 1
while y:
y %= bin(y).count("1")
ans += 1
print(ans)
| N = int(input())
X = input()
Xi = int(X, 2)
c0 = X.count("1")
Xp = Xi % (c0 + 1)
if c0 != 1:
Xm = Xi % (c0 - 1)
for i, x in enumerate(X):
if x == "1":
if c0 == 1:
print(0)
continue
y = (Xm - pow(2, N - 1 - i, c0 - 1)) % (c0 - 1)
else:
y = (Xp + pow(2, N - 1 - i, c0 + 1)) % (c0 + 1)
ans = 1
while y:
y %= bin(y).count("1")
ans += 1
print(ans)
| replace | 6 | 7 | 6 | 9 | 0 | |
p02609 | Python | Runtime Error | def main():
N = int(input())
(*X,) = map(int, input())
memo = [-1] * 21
def f(x):
ret = 0
while x > 0:
x = x % bin(x)[2:].count("1")
ret += 1
return ret
for x in range(21):
memo[x] = f(x)
cnt = X.count(1)
pow2_0_1 = [1]
pow2_1_0 = [1]
t_0_1 = 1
t_1_0 = 1
for i in range(N):
t_0_1 = t_0_1 * 2 % (cnt + 1)
pow2_0_1.append(t_0_1)
t_1_0 = t_1_0 * 2 % (cnt - 1)
pow2_1_0.append(t_1_0)
chg_0_1 = 0
chg_1_0 = 0
i = 0
for d in reversed(X):
if d:
chg_0_1 = (chg_0_1 + pow2_0_1[i]) % (cnt + 1)
chg_1_0 = (chg_1_0 + pow2_1_0[i]) % (cnt - 1)
i += 1
ans = []
i = 0
for d in reversed(X):
if d:
t = (chg_1_0 - pow2_1_0[i]) % (cnt - 1)
else:
t = (chg_0_1 + pow2_0_1[i]) % (cnt + 1)
i += 1
add_v = 1
while t > 20 or memo[t] == -1:
t = t % bin(t)[2:].count("1")
add_v += 1
ans.append(memo[t] + add_v)
ans.reverse()
print(*ans, sep="\n")
if __name__ == "__main__":
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| def main():
N = int(input())
(*X,) = map(int, input())
memo = [-1] * 21
def f(x):
ret = 0
while x > 0:
x = x % bin(x)[2:].count("1")
ret += 1
return ret
for x in range(21):
memo[x] = f(x)
cnt = X.count(1)
if cnt == 1:
ans = []
i = 0
for d in reversed(X):
if d:
ans.append(0)
continue
if i == 0 or X[-1]:
ans.append(2)
else:
ans.append(1)
i += 1
ans.reverse()
print(*ans, sep="\n")
return
pow2_0_1 = [1]
pow2_1_0 = [1]
t_0_1 = 1
t_1_0 = 1
for i in range(N):
t_0_1 = t_0_1 * 2 % (cnt + 1)
pow2_0_1.append(t_0_1)
t_1_0 = t_1_0 * 2 % (cnt - 1)
pow2_1_0.append(t_1_0)
chg_0_1 = 0
chg_1_0 = 0
i = 0
for d in reversed(X):
if d:
chg_0_1 = (chg_0_1 + pow2_0_1[i]) % (cnt + 1)
chg_1_0 = (chg_1_0 + pow2_1_0[i]) % (cnt - 1)
i += 1
ans = []
i = 0
for d in reversed(X):
if d:
t = (chg_1_0 - pow2_1_0[i]) % (cnt - 1)
else:
t = (chg_0_1 + pow2_0_1[i]) % (cnt + 1)
i += 1
add_v = 1
while t > 20 or memo[t] == -1:
t = t % bin(t)[2:].count("1")
add_v += 1
ans.append(memo[t] + add_v)
ans.reverse()
print(*ans, sep="\n")
if __name__ == "__main__":
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| insert | 17 | 17 | 17 | 35 | 0 | |
p02609 | Python | Runtime Error | from functools import lru_cache
N = int(input())
X = input()
@lru_cache(maxsize=None)
def popcount(x):
return x % bin(x).count("1")
def f(x):
cnt = 1
while x > 0:
x = popcount(x)
cnt += 1
return cnt
count = X.count("1")
mod_one = count - 1
mod_zero = count + 1
ones = [1 % mod_one]
zeros = [1 % mod_zero]
x_mod_one = 0 if X[-1] == "0" else 1 % mod_one
x_mod_zero = 0 if X[-1] == "0" else 1 % mod_zero
for xi in reversed(X[:-1]):
ones.append(ones[-1] * 2 % mod_one)
zeros.append(zeros[-1] * 2 % mod_zero)
if xi == "1":
x_mod_one += ones[-1]
x_mod_one %= mod_one
x_mod_zero += zeros[-1]
x_mod_zero %= mod_zero
ones = list(reversed(ones))
zeros = list(reversed(zeros))
for i in range(N):
if count == 1 and X[i] == "1":
print(0)
elif X[i] == "1":
x = (x_mod_one - ones[i]) % mod_one
print(f(x))
else:
x = (x_mod_zero + zeros[i]) % mod_zero
print(f(x))
| from functools import lru_cache
N = int(input())
X = input()
@lru_cache(maxsize=None)
def popcount(x):
return x % bin(x).count("1")
def f(x):
cnt = 1
while x > 0:
x = popcount(x)
cnt += 1
return cnt
count = X.count("1")
mod_one = count - 1
if mod_one == 0:
mod_one = 1
mod_zero = count + 1
ones = [1 % mod_one]
zeros = [1 % mod_zero]
x_mod_one = 0 if X[-1] == "0" else 1 % mod_one
x_mod_zero = 0 if X[-1] == "0" else 1 % mod_zero
for xi in reversed(X[:-1]):
ones.append(ones[-1] * 2 % mod_one)
zeros.append(zeros[-1] * 2 % mod_zero)
if xi == "1":
x_mod_one += ones[-1]
x_mod_one %= mod_one
x_mod_zero += zeros[-1]
x_mod_zero %= mod_zero
ones = list(reversed(ones))
zeros = list(reversed(zeros))
for i in range(N):
if count == 1 and X[i] == "1":
print(0)
elif X[i] == "1":
x = (x_mod_one - ones[i]) % mod_one
print(f(x))
else:
x = (x_mod_zero + zeros[i]) % mod_zero
print(f(x))
| insert | 22 | 22 | 22 | 24 | 0 | |
p02609 | 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 all(x) x.begin(), x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ std::cout << PREFIX << #x << " = " << x << std::endl; }
std::ostream &output_indent(std::ostream &os, int ind) {
for (int i = 0; i < ind; i++)
os << " ";
return os;
}
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p);
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v);
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
return (os << "(" << p.first << ", " << p.second << ")");
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
os << "[";
for (int i = 0; i < v.size(); i++)
os << v[i] << ", ";
return (os << "]");
}
template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) {
return std::vector<T>(n, std::forward<T>(val));
}
template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(
n, ndvec(std::forward<Tail>(tail)...));
}
template <class Cond> struct chain {
Cond cond;
chain(Cond cond) : cond(cond) {}
template <class T> bool operator()(T &a, const T &b) const {
if (cond(a, b)) {
a = b;
return true;
}
return false;
}
};
template <class Cond> chain<Cond> make_chain(Cond cond) {
return chain<Cond>(cond);
}
i64 solve(i64 X) {
i64 ans = 0;
while (X > 0) {
X %= __builtin_popcountll(X);
ans++;
}
return ans;
}
int main() {
i64 N;
cin >> N;
string X;
cin >> X;
reverse(all(X));
i64 pc = 0;
for (auto x : X) {
if (x == '1')
pc++;
}
vector<i64> up;
i64 up_value = 0;
{
i64 now = 1;
rep(i, 0, N) {
up.push_back(now % (pc + 1));
if (X[i] == '1') {
up_value += now;
up_value %= (pc + 1);
}
now *= 2;
now %= (pc + 1);
}
}
vector<i64> down;
i64 down_value = 0;
if (pc <= 1) {
down.assign(N, -1);
i64 down_value = -1;
} else {
i64 now = 1;
rep(i, 0, N) {
down.push_back(now % (pc - 1));
if (X[i] == '1') {
down_value += now;
down_value %= (pc - 1);
}
now *= 2;
now %= (pc - 1);
}
}
vector<i64> vec(N);
vector<i64> ans(N, -1);
rep(i, 0, N) {
if (X[i] == '0') {
// up
vec[i] = (up_value + up[i]) % (pc + 1);
ans[i] = solve(vec[i]) + 1;
} else if (X[i] == '1') {
if (down_value == -1) {
ans[i] = 0;
} else {
vec[i] = (down_value - down[i] + (pc - 1)) % (pc - 1);
ans[i] = solve(vec[i]) + 1;
}
}
}
reverse(all(ans));
rep(i, 0, N) { cout << ans[i] << "\n"; }
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ std::cout << PREFIX << #x << " = " << x << std::endl; }
std::ostream &output_indent(std::ostream &os, int ind) {
for (int i = 0; i < ind; i++)
os << " ";
return os;
}
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p);
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v);
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
return (os << "(" << p.first << ", " << p.second << ")");
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
os << "[";
for (int i = 0; i < v.size(); i++)
os << v[i] << ", ";
return (os << "]");
}
template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) {
return std::vector<T>(n, std::forward<T>(val));
}
template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(
n, ndvec(std::forward<Tail>(tail)...));
}
template <class Cond> struct chain {
Cond cond;
chain(Cond cond) : cond(cond) {}
template <class T> bool operator()(T &a, const T &b) const {
if (cond(a, b)) {
a = b;
return true;
}
return false;
}
};
template <class Cond> chain<Cond> make_chain(Cond cond) {
return chain<Cond>(cond);
}
i64 solve(i64 X) {
i64 ans = 0;
while (X > 0) {
X %= __builtin_popcountll(X);
ans++;
}
return ans;
}
int main() {
i64 N;
cin >> N;
string X;
cin >> X;
reverse(all(X));
i64 pc = 0;
for (auto x : X) {
if (x == '1')
pc++;
}
vector<i64> up;
i64 up_value = 0;
{
i64 now = 1;
rep(i, 0, N) {
up.push_back(now % (pc + 1));
if (X[i] == '1') {
up_value += now;
up_value %= (pc + 1);
}
now *= 2;
now %= (pc + 1);
}
}
vector<i64> down;
i64 down_value = 0;
if (pc <= 1) {
down.assign(N, -1);
down_value = -1;
} else {
i64 now = 1;
rep(i, 0, N) {
down.push_back(now % (pc - 1));
if (X[i] == '1') {
down_value += now;
down_value %= (pc - 1);
}
now *= 2;
now %= (pc - 1);
}
}
vector<i64> vec(N);
vector<i64> ans(N, -1);
rep(i, 0, N) {
if (X[i] == '0') {
// up
vec[i] = (up_value + up[i]) % (pc + 1);
ans[i] = solve(vec[i]) + 1;
} else if (X[i] == '1') {
if (down_value == -1) {
ans[i] = 0;
} else {
vec[i] = (down_value - down[i] + (pc - 1)) % (pc - 1);
ans[i] = solve(vec[i]) + 1;
}
}
}
reverse(all(ans));
rep(i, 0, N) { cout << ans[i] << "\n"; }
}
| replace | 96 | 97 | 96 | 97 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long modpow(long a, long b, long mod) {
long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b /= 2;
}
return res;
}
int main() {
int n;
string s;
cin >> n >> s;
int one = 0;
for (int i = 0; i < n; i++)
if (s[i] == '1')
one++;
long plus[n + 1];
long minus[n + 1];
long sum_plus = 0;
long sum_minus = 0;
for (long i = 0; i < n; i++) {
if (one != n) {
plus[i] = modpow(2L, i, (long)(one + 1));
if (s[n - 1 - i] == '1')
sum_plus = (sum_plus + plus[i]) % ((long)(one + 1));
}
if (one != 0) {
minus[i] = modpow(2L, i, (long)(one - 1));
if (s[n - 1 - i] == '1')
sum_minus = (sum_minus + minus[i]) % ((long)(one - 1));
}
}
for (int i = 0; i < n; i++) {
long tmp;
int ans = 0;
if (s[i] == '0') {
tmp = (sum_plus + plus[n - 1 - i]) % ((long)(one + 1));
ans++;
while (tmp > 0) {
tmp = tmp % __builtin_popcount((int)tmp);
ans++;
}
cout << ans << endl;
} else {
if (one == 1)
cout << 0 << endl;
else {
tmp = (sum_minus + one - 1 - minus[n - 1 - i]) % ((long)(one - 1));
ans++;
while (tmp > 0) {
tmp = tmp % __builtin_popcount((int)tmp);
ans++;
}
cout << ans << endl;
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
long modpow(long a, long b, long mod) {
long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b /= 2;
}
return res;
}
int main() {
int n;
string s;
cin >> n >> s;
int one = 0;
for (int i = 0; i < n; i++)
if (s[i] == '1')
one++;
long plus[n + 1];
long minus[n + 1];
long sum_plus = 0;
long sum_minus = 0;
for (long i = 0; i < n; i++) {
if (one != n) {
plus[i] = modpow(2L, i, (long)(one + 1));
if (s[n - 1 - i] == '1')
sum_plus = (sum_plus + plus[i]) % ((long)(one + 1));
}
if (one > 1) {
minus[i] = modpow(2L, i, (long)(one - 1));
if (s[n - 1 - i] == '1')
sum_minus = (sum_minus + minus[i]) % ((long)(one - 1));
}
}
for (int i = 0; i < n; i++) {
long tmp;
int ans = 0;
if (s[i] == '0') {
tmp = (sum_plus + plus[n - 1 - i]) % ((long)(one + 1));
ans++;
while (tmp > 0) {
tmp = tmp % __builtin_popcount((int)tmp);
ans++;
}
cout << ans << endl;
} else {
if (one == 1)
cout << 0 << endl;
else {
tmp = (sum_minus + one - 1 - minus[n - 1 - i]) % ((long)(one - 1));
ans++;
while (tmp > 0) {
tmp = tmp % __builtin_popcount((int)tmp);
ans++;
}
cout << ans << endl;
}
}
}
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define endl '\n'
template <typename T> inline bool chmin(T &x, T a) {
if (x >= a) {
x = a;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &x, T a) {
if (x <= a) {
x = a;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
vector<bool> v(N, false);
int n = 0;
for (int i = 0; i < N; i++) {
char c;
cin >> c;
v[i] = (c == '1');
if (v[i]) {
n++;
}
}
int x0 = n + 1;
int x1 = n - 1;
int res0 = 0, res1 = 0;
vector<int> pow0(N, 0), pow1(N, 0);
if (x0 >= 1) {
res0 = 0;
for (int i = 0; i < N; i++) {
res0 *= 2;
if (v[i])
res0++;
res0 %= x0;
}
pow0[N - 1] = 1 % x0;
for (int i = N - 2; i >= 0; i--) {
pow0[i] = pow0[i + 1] * 2;
pow0[i] %= x0;
}
}
if (x1 >= 1) {
res1 = 0;
for (int i = 0; i < N; i++) {
res1 *= 2;
if (v[i])
res1++;
res1 %= x1;
}
pow1[N - 1] = 1 % x1;
for (int i = N - 2; i >= 0; i--) {
pow1[i] = pow1[i + 1] * 2;
pow1[i] %= x1;
}
}
for (int i = 0; i < N; i++) {
if (v[i] == false) { // x0
int temp = (res0 + pow0[i]) % x0;
int ans = 1;
int a = temp;
while (a > 0) {
int n = a;
int b = 0;
while (n > 0) {
if (n % 2 == 1) {
b++;
}
n /= 2;
}
ans++;
a %= b;
}
cout << ans << endl;
} else { // x1
int temp = (res1 - pow1[i] + x1) % x1;
int ans = 1;
int a = temp;
while (a > 0) {
int n = a;
int b = 0;
while (n > 0) {
if (n % 2 == 1) {
b++;
}
n /= 2;
}
ans++;
a %= b;
}
cout << ans << endl;
}
}
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define endl '\n'
template <typename T> inline bool chmin(T &x, T a) {
if (x >= a) {
x = a;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &x, T a) {
if (x <= a) {
x = a;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
vector<bool> v(N, false);
int n = 0;
for (int i = 0; i < N; i++) {
char c;
cin >> c;
v[i] = (c == '1');
if (v[i]) {
n++;
}
}
int x0 = n + 1;
int x1 = n - 1;
int res0 = 0, res1 = 0;
vector<int> pow0(N, 0), pow1(N, 0);
if (x0 >= 1) {
res0 = 0;
for (int i = 0; i < N; i++) {
res0 *= 2;
if (v[i])
res0++;
res0 %= x0;
}
pow0[N - 1] = 1 % x0;
for (int i = N - 2; i >= 0; i--) {
pow0[i] = pow0[i + 1] * 2;
pow0[i] %= x0;
}
}
if (x1 >= 1) {
res1 = 0;
for (int i = 0; i < N; i++) {
res1 *= 2;
if (v[i])
res1++;
res1 %= x1;
}
pow1[N - 1] = 1 % x1;
for (int i = N - 2; i >= 0; i--) {
pow1[i] = pow1[i + 1] * 2;
pow1[i] %= x1;
}
}
for (int i = 0; i < N; i++) {
if (v[i] == false) { // x0
int temp = (res0 + pow0[i]) % x0;
int ans = 1;
int a = temp;
while (a > 0) {
int n = a;
int b = 0;
while (n > 0) {
if (n % 2 == 1) {
b++;
}
n /= 2;
}
ans++;
a %= b;
}
cout << ans << endl;
} else { // x1
if (x1 == 0) {
cout << 0 << endl;
continue;
}
int temp = (res1 - pow1[i] + x1) % x1;
int ans = 1;
int a = temp;
while (a > 0) {
int n = a;
int b = 0;
while (n > 0) {
if (n % 2 == 1) {
b++;
}
n /= 2;
}
ans++;
a %= b;
}
cout << ans << endl;
}
}
return 0;
} | insert | 112 | 112 | 112 | 116 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 5;
ll mod_pow(ll k, ll p) {
if (k == 0) {
return 1 % p;
}
if (k == 1) {
return 2 % p;
}
if (k % 2 == 0) {
ll tmp = mod_pow(k / 2, p);
return tmp * tmp % p;
} else {
ll tmp = mod_pow((k - 1) / 2, p);
tmp *= tmp;
tmp %= p;
tmp *= 2;
tmp %= p;
return tmp;
}
}
ll pow_fast(ll n, ll k) {
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
if (k % 2 == 0) {
ll tmp = pow_fast(n, k / 2) % MOD;
return tmp * tmp % MOD;
} else {
ll tmp = pow_fast(n, (k - 1) / 2);
return tmp * tmp * 2;
}
}
int main() {
vector<ll> memo(1e5 + 1, 0);
for (ll i = 1; i <= 1e6; i++) {
bitset<64> bits(i);
memo[i] += memo[i % bits.count()] + 1;
}
ll N;
cin >> N;
string S;
cin >> S;
vector<ll> X(N);
ll popcount = 0;
for (size_t i = 0; i < N; i++) {
X[i] = S[i] - '0';
if (X[i] == 1) {
popcount += 1;
}
}
vector<ll> UP(N, 0);
vector<ll> DOWN(N, 0);
for (ll i = 0; i < N; i++) {
if (i == 0) {
UP[i] = 1 % (popcount + 1);
continue;
}
UP[i] = UP[i - 1] * 2 % (popcount + 1);
}
for (ll i = 0; i < N; i++) {
if (popcount - 1 == 0) {
break;
}
if (i == 0) {
DOWN[i] = 1 % (popcount - 1);
continue;
}
DOWN[i] = DOWN[i - 1] * 2 % (popcount - 1);
}
ll up = 0;
ll down = 0;
for (ll i = 0; i < N; i++) {
if (X[i] == 0) {
continue;
}
up += UP[N - 1 - i];
up %= (popcount + 1);
}
for (ll i = 0; i < N; i++) {
if (popcount - 1 == 0) {
break;
}
if (X[i] == 0) {
continue;
}
down += DOWN[N - 1 - i];
down %= (popcount - 1);
}
ll cnt = 0;
for (ll i = 0; i < N; i++) {
if (X[i] == 1) {
ll f = popcount - 1;
if (f == 0) {
cout << 0 << endl;
continue;
}
ll n = (down - DOWN[N - 1 - i] + f) % f;
cout << (memo[n] + 1) << endl;
} else {
ll f = popcount + 1;
ll n = (up + UP[N - 1 - i] + f) % f;
cout << (memo[n] + 1) << endl;
}
}
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 5;
ll mod_pow(ll k, ll p) {
if (k == 0) {
return 1 % p;
}
if (k == 1) {
return 2 % p;
}
if (k % 2 == 0) {
ll tmp = mod_pow(k / 2, p);
return tmp * tmp % p;
} else {
ll tmp = mod_pow((k - 1) / 2, p);
tmp *= tmp;
tmp %= p;
tmp *= 2;
tmp %= p;
return tmp;
}
}
ll pow_fast(ll n, ll k) {
if (k == 0) {
return 1;
}
if (k == 1) {
return n;
}
if (k % 2 == 0) {
ll tmp = pow_fast(n, k / 2) % MOD;
return tmp * tmp % MOD;
} else {
ll tmp = pow_fast(n, (k - 1) / 2);
return tmp * tmp * 2;
}
}
int main() {
vector<ll> memo(1e6 + 1, 0);
for (ll i = 1; i <= 1e6; i++) {
bitset<64> bits(i);
memo[i] += memo[i % bits.count()] + 1;
}
ll N;
cin >> N;
string S;
cin >> S;
vector<ll> X(N);
ll popcount = 0;
for (size_t i = 0; i < N; i++) {
X[i] = S[i] - '0';
if (X[i] == 1) {
popcount += 1;
}
}
vector<ll> UP(N, 0);
vector<ll> DOWN(N, 0);
for (ll i = 0; i < N; i++) {
if (i == 0) {
UP[i] = 1 % (popcount + 1);
continue;
}
UP[i] = UP[i - 1] * 2 % (popcount + 1);
}
for (ll i = 0; i < N; i++) {
if (popcount - 1 == 0) {
break;
}
if (i == 0) {
DOWN[i] = 1 % (popcount - 1);
continue;
}
DOWN[i] = DOWN[i - 1] * 2 % (popcount - 1);
}
ll up = 0;
ll down = 0;
for (ll i = 0; i < N; i++) {
if (X[i] == 0) {
continue;
}
up += UP[N - 1 - i];
up %= (popcount + 1);
}
for (ll i = 0; i < N; i++) {
if (popcount - 1 == 0) {
break;
}
if (X[i] == 0) {
continue;
}
down += DOWN[N - 1 - i];
down %= (popcount - 1);
}
ll cnt = 0;
for (ll i = 0; i < N; i++) {
if (X[i] == 1) {
ll f = popcount - 1;
if (f == 0) {
cout << 0 << endl;
continue;
}
ll n = (down - DOWN[N - 1 - i] + f) % f;
cout << (memo[n] + 1) << endl;
} else {
ll f = popcount + 1;
ll n = (up + UP[N - 1 - i] + f) % f;
cout << (memo[n] + 1) << endl;
}
}
} | replace | 51 | 52 | 51 | 52 | -11 | |
p02609 | C++ | Runtime Error | /*
this->author = Fuad Ashraful Mehmet, CSE-UAP
ToDo--
uva 1223
*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define all(o) (o).begin(), (o).end()
#define dbg(o) cerr << "at " << __LINE__ << " response = " << o << endl;
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update> #define ordered_multiset
tree<pair<int, int>, null_type,less<pair<int, int> >,
rb_tree_tag,tree_order_statistics_node_update>
*/
const int N = 2e5 + 5;
typedef long long ll;
int n, m;
string s;
ll a[2][N]; // idx 0 for up and 1 for down
ll tree[2][N * 4];
int res[N];
ll bigMod(ll b, ll p, ll mod) {
if (p == 0)
return 1LL;
if (p & 1)
return (b * bigMod(b, p - 1, mod) % mod);
ll r = bigMod(b, p >> 1, mod) % mod;
return (r * r) % mod;
}
void calMod(int idx, int mod) {
for (int i = 0; i < n; ++i) {
if (s[i] == '0')
continue;
a[idx][i + 1] = bigMod(2, i, mod);
}
} // end func
void buildTree(int idx, int l, int r, ll mod, int nd = 1) {
if (l == r) {
tree[idx][nd] = a[idx][l];
return;
}
int mid = (l + r) >> 1;
buildTree(idx, l, mid, mod, nd << 1);
buildTree(idx, mid + 1, r, mod, nd << 1 | 1);
tree[idx][nd] = (tree[idx][nd << 1] + tree[idx][nd << 1 | 1]) % mod;
return;
}
ll query(int idx, int l, int r, int x, int y, ll mod, int nd = 1) {
if (x > y)
return 0LL;
if (l > y or r < x)
return 0LL;
if (l >= x and r <= y) {
return tree[idx][nd];
}
int mid = (l + r) >> 1;
ll r1 = query(idx, l, mid, x, y, mod, nd << 1) % mod;
ll r2 = query(idx, mid + 1, r, x, y, mod, nd << 1 | 1) % mod;
return (r1 + r2) % mod;
}
int find_ans(int num) {
int cnt = 0;
while (num > 0) {
cnt++;
int bit = __builtin_popcount(num);
num = num % bit;
}
return cnt;
}
void HalfDead() {
cin >> n;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; ++i) {
cnt += (s[i] == '1');
}
int up = cnt + 1;
int down = cnt - 1;
reverse(all(s));
calMod(0, up);
buildTree(0, 1, n, up);
if (down >= 0) {
calMod(1, down);
buildTree(1, 1, n, down);
}
for (int i = 0; i < n; ++i) {
if (s[i] == '1') // one means take down answer
{
if (down == 0) {
res[i + 1] = -1;
continue;
}
ll ret =
(query(1, 1, n, 1, i, down) + query(1, 1, n, i + 2, n, down)) % down;
res[i + 1] = find_ans(ret);
} else {
ll ret = (query(0, 1, n, 1, i, up) + query(0, 1, n, i + 2, n, up) +
bigMod(2, i, up)) %
up;
res[i + 1] = find_ans(ret);
}
}
for (int i = n; i >= 1; --i) {
cout << res[i] + 1 << endl;
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int tc = 1;
// cin>>tc;
while (tc--)
HalfDead();
return 0;
} | /*
this->author = Fuad Ashraful Mehmet, CSE-UAP
ToDo--
uva 1223
*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define all(o) (o).begin(), (o).end()
#define dbg(o) cerr << "at " << __LINE__ << " response = " << o << endl;
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update> #define ordered_multiset
tree<pair<int, int>, null_type,less<pair<int, int> >,
rb_tree_tag,tree_order_statistics_node_update>
*/
const int N = 2e5 + 5;
typedef long long ll;
int n, m;
string s;
ll a[2][N]; // idx 0 for up and 1 for down
ll tree[2][N * 4];
int res[N];
ll bigMod(ll b, ll p, ll mod) {
if (p == 0)
return 1LL;
if (p & 1)
return (b * bigMod(b, p - 1, mod) % mod);
ll r = bigMod(b, p >> 1, mod) % mod;
return (r * r) % mod;
}
void calMod(int idx, int mod) {
for (int i = 0; i < n; ++i) {
if (s[i] == '0')
continue;
a[idx][i + 1] = bigMod(2, i, mod);
}
} // end func
void buildTree(int idx, int l, int r, ll mod, int nd = 1) {
if (l == r) {
tree[idx][nd] = a[idx][l];
return;
}
int mid = (l + r) >> 1;
buildTree(idx, l, mid, mod, nd << 1);
buildTree(idx, mid + 1, r, mod, nd << 1 | 1);
tree[idx][nd] = (tree[idx][nd << 1] + tree[idx][nd << 1 | 1]) % mod;
return;
}
ll query(int idx, int l, int r, int x, int y, ll mod, int nd = 1) {
if (x > y)
return 0LL;
if (l > y or r < x)
return 0LL;
if (l >= x and r <= y) {
return tree[idx][nd];
}
int mid = (l + r) >> 1;
ll r1 = query(idx, l, mid, x, y, mod, nd << 1) % mod;
ll r2 = query(idx, mid + 1, r, x, y, mod, nd << 1 | 1) % mod;
return (r1 + r2) % mod;
}
int find_ans(int num) {
int cnt = 0;
while (num > 0) {
cnt++;
int bit = __builtin_popcount(num);
num = num % bit;
}
return cnt;
}
void HalfDead() {
cin >> n;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; ++i) {
cnt += (s[i] == '1');
}
int up = cnt + 1;
int down = cnt - 1;
reverse(all(s));
calMod(0, up);
buildTree(0, 1, n, up);
if (down > 0) {
calMod(1, down);
buildTree(1, 1, n, down);
}
for (int i = 0; i < n; ++i) {
if (s[i] == '1') // one means take down answer
{
if (down == 0) {
res[i + 1] = -1;
continue;
}
ll ret =
(query(1, 1, n, 1, i, down) + query(1, 1, n, i + 2, n, down)) % down;
res[i + 1] = find_ans(ret);
} else {
ll ret = (query(0, 1, n, 1, i, up) + query(0, 1, n, i + 2, n, up) +
bigMod(2, i, up)) %
up;
res[i + 1] = find_ans(ret);
}
}
for (int i = n; i >= 1; --i) {
cout << res[i] + 1 << endl;
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int tc = 1;
// cin>>tc;
while (tc--)
HalfDead();
return 0;
} | replace | 95 | 96 | 95 | 96 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int popcount(int n) {
int ans = 0;
while (n != 0) {
ans += n % 2;
n = n / 2;
}
return ans;
}
int times(int n) {
int ans = 0;
while (n != 0) {
n = n % popcount(n);
ans++;
}
return ans;
}
int calc(int n, string s) {
int up = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == '1')
up++;
}
if (up == 0)
return 0;
int keta = 1;
int m = 0;
for (int i = 0; i < n; i++) {
m = (m + keta * (s.at(n - 1 - i) - '0')) % up;
keta = (keta * 2) % up;
}
return times(m % up) + 1;
}
int main() {
int n;
string s;
cin >> n;
cin >> s;
int up = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == '1')
up++;
}
vector<int> keta_mod_up(n, 1);
vector<int> keta_mod_down(n, 1);
int keta = 1;
for (int i = 0; i < n - 1; i++) {
keta_mod_up.at(i + 1) = (keta * 2) % (up + 1);
keta = (keta * 2) % (up + 1);
}
keta = 1;
for (int i = 0; i < n - 1; i++) {
keta_mod_down.at(i + 1) = (keta * 2) % (up - 1);
keta = (keta * 2) % (up - 1);
}
int stay_up = 0;
int stay_down = 0;
for (int i = 0; i < n; i++) {
stay_up =
(stay_up + keta_mod_up.at(i) * (s.at(n - 1 - i) - '0')) % (up + 1);
}
for (int i = 0; i < n; i++) {
stay_down =
(stay_down + keta_mod_down.at(i) * (s.at(n - 1 - i) - '0')) % (up - 1);
}
for (int i = 0; i < n; i++) {
bool z_to_o;
if (s.at(i) == '0') {
z_to_o = true;
} else {
z_to_o = false;
}
if (z_to_o) {
int k;
k = (stay_up + keta_mod_up.at(n - 1 - i)) % (up + 1);
if (k % (up + 1) == 0)
cout << 1 << endl;
else {
cout << times(k) + 1 << endl;
}
} else {
int k;
k = (stay_down - keta_mod_down.at(n - 1 - i)) % (up - 1);
while (k < 0) {
k += (up - 1);
}
if (k % (up - 1) == 0)
cout << 1 << endl;
else {
cout << times(k) + 1 << endl;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int popcount(int n) {
int ans = 0;
while (n != 0) {
ans += n % 2;
n = n / 2;
}
return ans;
}
int times(int n) {
int ans = 0;
while (n != 0) {
n = n % popcount(n);
ans++;
}
return ans;
}
int calc(int n, string s) {
int up = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == '1')
up++;
}
if (up == 0)
return 0;
int keta = 1;
int m = 0;
for (int i = 0; i < n; i++) {
m = (m + keta * (s.at(n - 1 - i) - '0')) % up;
keta = (keta * 2) % up;
}
return times(m % up) + 1;
}
int main() {
int n;
string s;
cin >> n;
cin >> s;
int up = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == '1')
up++;
}
if (up == 1) {
if (s.at(n - 1) == '0') {
for (int i = 0; i < n - 1; i++) {
if (s.at(i) == '0') {
cout << 1 << endl;
} else
cout << 0 << endl;
}
cout << 2 << endl;
return 0;
} else {
for (int i = 0; i < n - 1; i++) {
cout << 2 << endl;
}
cout << 0 << endl;
return 0;
}
}
vector<int> keta_mod_up(n, 1);
vector<int> keta_mod_down(n, 1);
int keta = 1;
for (int i = 0; i < n - 1; i++) {
keta_mod_up.at(i + 1) = (keta * 2) % (up + 1);
keta = (keta * 2) % (up + 1);
}
keta = 1;
for (int i = 0; i < n - 1; i++) {
keta_mod_down.at(i + 1) = (keta * 2) % (up - 1);
keta = (keta * 2) % (up - 1);
}
int stay_up = 0;
int stay_down = 0;
for (int i = 0; i < n; i++) {
stay_up =
(stay_up + keta_mod_up.at(i) * (s.at(n - 1 - i) - '0')) % (up + 1);
}
for (int i = 0; i < n; i++) {
stay_down =
(stay_down + keta_mod_down.at(i) * (s.at(n - 1 - i) - '0')) % (up - 1);
}
for (int i = 0; i < n; i++) {
bool z_to_o;
if (s.at(i) == '0') {
z_to_o = true;
} else {
z_to_o = false;
}
if (z_to_o) {
int k;
k = (stay_up + keta_mod_up.at(n - 1 - i)) % (up + 1);
if (k % (up + 1) == 0)
cout << 1 << endl;
else {
cout << times(k) + 1 << endl;
}
} else {
int k;
k = (stay_down - keta_mod_down.at(n - 1 - i)) % (up - 1);
while (k < 0) {
k += (up - 1);
}
if (k % (up - 1) == 0)
cout << 1 << endl;
else {
cout << times(k) + 1 << endl;
}
}
}
}
| insert | 48 | 48 | 48 | 66 | 0 | |
p02609 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int N;
int pcnt(int x) { return __builtin_popcount(x); }
int f(int a) {
if (a == 0)
return 0;
return f(a % pcnt(a)) + 1;
}
int main() {
cin >> N;
string s;
cin >> s;
vector<int> X(N);
rep(i, N) X[i] = s[i] - '0';
int opc = 0;
rep(i, N) opc += X[i];
vector<int> ans(N);
// b=0は0→1の反転をする場合
rep(b, 2) {
int pc = opc;
if (b == 0)
pc++;
else
pc--;
// x(mod pc)を求める
int y = 0;
for (int i = 0; i < N; i++) {
y = (2 * y) % pc;
y += X[i];
}
// ビット反転させていく
int bit = 1;
for (int i = N - 1; i >= 0; i--) {
if (b == X[i]) {
int z = y;
if (b == 0) {
z = (z + bit) % pc;
} else {
z = (z - bit + pc) % pc;
}
ans[i] = f(z) + 1;
}
bit *= 2;
bit %= pc;
}
}
rep(i, N) cout << ans[i] << endl;
} | #include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int N;
int pcnt(int x) { return __builtin_popcount(x); }
int f(int a) {
if (a == 0)
return 0;
return f(a % pcnt(a)) + 1;
}
int main() {
cin >> N;
string s;
cin >> s;
vector<int> X(N);
rep(i, N) X[i] = s[i] - '0';
int opc = 0;
rep(i, N) opc += X[i];
vector<int> ans(N);
// b=0は0→1の反転をする場合
rep(b, 2) {
int pc = opc;
if (b == 0)
pc++;
else
pc--;
if (pc <= 0)
continue;
// x(mod pc)を求める
int y = 0;
for (int i = 0; i < N; i++) {
y = (2 * y) % pc;
y += X[i];
}
// ビット反転させていく
int bit = 1;
for (int i = N - 1; i >= 0; i--) {
if (b == X[i]) {
int z = y;
if (b == 0) {
z = (z + bit) % pc;
} else {
z = (z - bit + pc) % pc;
}
ans[i] = f(z) + 1;
}
bit *= 2;
bit %= pc;
}
}
rep(i, N) cout << ans[i] << endl;
} | insert | 33 | 33 | 33 | 35 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX 100007
using namespace std;
int pw[MAX][3];
int sum[3];
int n;
string x;
void calc(int cnt, int idx) {
if (cnt <= 0)
return;
pw[0][idx] = 1;
for (int i = 1; i < MAX; i++) {
pw[i][idx] = 2 * pw[i - 1][idx];
pw[i][idx] %= cnt;
}
for (int i = 0; i < x.length(); i++) {
if (x[i] == '1') {
sum[idx] += pw[n - i - 1][idx];
sum[idx] %= cnt;
}
}
}
int f(int num) {
// std::popc
if (num == 0)
return 0;
int p = __builtin_popcount(num);
return 1 + f(num % p);
}
int main() {
int cnt = 0;
cin >> n >> x;
for (int i = 0; i < n; i++) {
if (x[i] == '1')
cnt++;
}
calc(cnt - 1, 0);
calc(cnt, 1);
calc(cnt + 1, 2);
for (int i = 0; i < n; i++) {
if (x[i] == '0') {
int rem = sum[2];
rem += pw[(n - i - 1)][2];
rem %= (cnt + 1);
// cout << rem << endl;
cout << (1 + f(rem)) << endl;
} else {
if (cnt == 1)
cout << 0 << endl;
else {
int rem = sum[0];
rem -= pw[(n - i - 1)][0];
rem %= (cnt - 1);
if (rem < 0)
rem += (cnt - 1);
cout << (1 + f(rem)) << endl;
}
}
}
return 0;
} | #include <bits/stdc++.h>
#define MAX 200007
using namespace std;
int pw[MAX][3];
int sum[3];
int n;
string x;
void calc(int cnt, int idx) {
if (cnt <= 0)
return;
pw[0][idx] = 1;
for (int i = 1; i < MAX; i++) {
pw[i][idx] = 2 * pw[i - 1][idx];
pw[i][idx] %= cnt;
}
for (int i = 0; i < x.length(); i++) {
if (x[i] == '1') {
sum[idx] += pw[n - i - 1][idx];
sum[idx] %= cnt;
}
}
}
int f(int num) {
// std::popc
if (num == 0)
return 0;
int p = __builtin_popcount(num);
return 1 + f(num % p);
}
int main() {
int cnt = 0;
cin >> n >> x;
for (int i = 0; i < n; i++) {
if (x[i] == '1')
cnt++;
}
calc(cnt - 1, 0);
calc(cnt, 1);
calc(cnt + 1, 2);
for (int i = 0; i < n; i++) {
if (x[i] == '0') {
int rem = sum[2];
rem += pw[(n - i - 1)][2];
rem %= (cnt + 1);
// cout << rem << endl;
cout << (1 + f(rem)) << endl;
} else {
if (cnt == 1)
cout << 0 << endl;
else {
int rem = sum[0];
rem -= pw[(n - i - 1)][0];
rem %= (cnt - 1);
if (rem < 0)
rem += (cnt - 1);
cout << (1 + f(rem)) << endl;
}
}
}
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\n'
// #define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000
using namespace std;
ll p(ll n, ll k, ll M) {
if (k == 0)
return 1;
ll x = p(n, k / 2, M) % M;
if (k % 2 == 0)
return ((x % M) * (x % M)) % M;
else
return ((((x % M) * (x % M)) % M) * n) % M;
}
void solve() {
ll n;
cin >> n;
string s;
cin >> s;
ll ones = 0;
ll pre[n + 1];
for (int i = 0; i <= n; ++i) {
if (i == 0)
pre[i] = 0;
else
pre[i] = pre[i % (__builtin_popcount(i))] + 1LL;
}
for (int i = 0; i < n; ++i) {
ones += (s[i] - '0');
}
ll m1 = ones + 1;
ll m2 = ones - 1;
ll v1 = 0, v2 = 0;
for (int i = 0; i < n; ++i) {
if (s[n - i - 1] == '1') {
v1 += p(2, i, m1);
v2 += p(2, i, m2);
}
v1 %= m1, v2 %= m2;
}
// deb(v1)deb(v2)deb(ones)
for (int i = 0; i < n; ++i) {
ll temp = ones;
if (s[i] == '1') {
temp--;
if (temp == 0) {
cout << 0 << endl;
continue;
}
ll val = (v2 - p(2, n - i - 1, m2) + m2) % m2;
cout << pre[val] + 1 << endl;
} else {
temp++;
ll val = (v1 + p(2, n - i - 1, m1) + m1) % m1;
cout << pre[val] + 1 << endl;
}
}
}
int32_t main() {
IOS ll T = 1;
// cin>>T;
for (ll i = 1; i <= T; ++i) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\n'
// #define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000
using namespace std;
ll p(ll n, ll k, ll M) {
if (k == 0)
return 1;
ll x = p(n, k / 2, M) % M;
if (k % 2 == 0)
return ((x % M) * (x % M)) % M;
else
return ((((x % M) * (x % M)) % M) * n) % M;
}
void solve() {
ll n;
cin >> n;
string s;
cin >> s;
ll ones = 0;
ll pre[n + 1];
for (int i = 0; i <= n; ++i) {
if (i == 0)
pre[i] = 0;
else
pre[i] = pre[i % (__builtin_popcount(i))] + 1LL;
}
for (int i = 0; i < n; ++i) {
ones += (s[i] - '0');
}
ll m1 = ones + 1;
ll m2 = ones - 1;
if (m2 <= 0)
m2 = 1;
ll v1 = 0, v2 = 0;
for (int i = 0; i < n; ++i) {
if (s[n - i - 1] == '1') {
v1 += p(2, i, m1);
v2 += p(2, i, m2);
}
v1 %= m1, v2 %= m2;
}
// deb(v1)deb(v2)deb(ones)
for (int i = 0; i < n; ++i) {
ll temp = ones;
if (s[i] == '1') {
temp--;
if (temp == 0) {
cout << 0 << endl;
continue;
}
ll val = (v2 - p(2, n - i - 1, m2) + m2) % m2;
cout << pre[val] + 1 << endl;
} else {
temp++;
ll val = (v1 + p(2, n - i - 1, m1) + m1) % m1;
cout << pre[val] + 1 << endl;
}
}
}
int32_t main() {
IOS ll T = 1;
// cin>>T;
for (ll i = 1; i <= T; ++i) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | insert | 44 | 44 | 44 | 46 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll calc(ll x, ll n) {
if (x == 0)
return n;
ll c = x;
ll ones = 0;
rep(i, 0, 20) {
if (((c >> i) % 2) == 1) {
ones++;
}
}
return calc(x % ones, n + 1);
}
int main() {
ll N;
cin >> N;
string X;
cin >> X;
reverse(all(X));
ll ones = 0;
rep(i, 0, N) {
if (X[i] == '1')
ones++;
}
ll sum_a = 0, sum_b = 0;
ll a, b;
if (ones == N) {
a = -1;
b = N - 1;
} else if (ones == 1) {
a = 2;
b = INF;
} else {
a = ones + 1;
b = ones - 1;
}
ll now_a = 1, now_b = 1;
rep(i, 0, N) {
if (X[i] == '1') {
sum_a += now_a;
sum_a %= a;
sum_b += now_b;
sum_b %= b;
}
now_a *= 2;
now_a %= a;
now_b *= 2;
now_b %= b;
}
now_a = 1, now_b = 1;
v ans;
rep(i, 0, N) {
if (X[i] == '1') {
if (b == INF)
ans.push_back(0);
else
ans.push_back(calc((sum_b - now_b + b) % b, 1));
} else {
ans.push_back(calc((sum_a + now_a + a) % a, 1));
}
now_a *= 2;
now_a %= a;
now_b *= 2;
now_b %= b;
}
rep(i, 0, N) cout << ans[N - 1 - i] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll calc(ll x, ll n) {
if (x == 0)
return n;
ll c = x;
ll ones = 0;
rep(i, 0, 20) {
if (((c >> i) % 2) == 1) {
ones++;
}
}
return calc(x % ones, n + 1);
}
int main() {
ll N;
cin >> N;
string X;
cin >> X;
reverse(all(X));
ll ones = 0;
rep(i, 0, N) {
if (X[i] == '1')
ones++;
}
ll sum_a = 0, sum_b = 0;
ll a, b;
if (ones == 1) {
a = 2;
b = INF;
} else {
a = ones + 1;
b = ones - 1;
}
ll now_a = 1, now_b = 1;
rep(i, 0, N) {
if (X[i] == '1') {
sum_a += now_a;
sum_a %= a;
sum_b += now_b;
sum_b %= b;
}
now_a *= 2;
now_a %= a;
now_b *= 2;
now_b %= b;
}
now_a = 1, now_b = 1;
v ans;
rep(i, 0, N) {
if (X[i] == '1') {
if (b == INF)
ans.push_back(0);
else
ans.push_back(calc((sum_b - now_b + b) % b, 1));
} else {
ans.push_back(calc((sum_a + now_a + a) % a, 1));
}
now_a *= 2;
now_a %= a;
now_b *= 2;
now_b %= b;
}
rep(i, 0, N) cout << ans[N - 1 - i] << endl;
return 0;
} | replace | 59 | 63 | 59 | 61 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << "\n"
ll power(ll a, ll b, ll MOD) { // a^b
ll res = 1;
a = a % MOD;
while (b > 0) {
if (b & 1) {
res = (res * a) % MOD;
b--;
}
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
int ans(int x) {
int c = 0;
while (x > 0) {
x = x % __builtin_popcount(x);
c++;
}
return c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
string s;
cin >> s;
int x = 0;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1')
x++;
}
int r1, r2, r3;
r1 = r2 = r3 = 0;
int y = max(x - 1, 1);
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
r1 = (2 * r1) % x;
r2 = (2 * r2) % (x + 1);
r3 = (2 * r3) % y;
} else {
r1 = (2 * r1 + 1) % x;
r2 = (2 * r2 + 1) % (x + 1);
r3 = (2 * r3 + 1) % y;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
cout << ans((r2 + (power(2, n - i - 1, x + 1))) % (x + 1)) + 1 << "\n";
} else {
cout << ans((r3 - (power(2, n - i - 1, x - 1)) + (x - 1)) % (x - 1)) + 1
<< "\n";
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << "\n"
ll power(ll a, ll b, ll MOD) { // a^b
ll res = 1;
a = a % MOD;
while (b > 0) {
if (b & 1) {
res = (res * a) % MOD;
b--;
}
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
int ans(int x) {
int c = 0;
while (x > 0) {
x = x % __builtin_popcount(x);
c++;
}
return c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
string s;
cin >> s;
int x = 0;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1')
x++;
}
int r1, r2, r3;
r1 = r2 = r3 = 0;
int y = max(x - 1, 1);
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
r1 = (2 * r1) % x;
r2 = (2 * r2) % (x + 1);
r3 = (2 * r3) % y;
} else {
r1 = (2 * r1 + 1) % x;
r2 = (2 * r2 + 1) % (x + 1);
r3 = (2 * r3 + 1) % y;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
cout << ans((r2 + (power(2, n - i - 1, x + 1))) % (x + 1)) + 1 << "\n";
} else {
if (x == 1)
cout << 0 << "\n";
else
cout << ans((r3 - (power(2, n - i - 1, x - 1)) + (x - 1)) % (x - 1)) + 1
<< "\n";
}
}
}
| replace | 71 | 73 | 71 | 76 | -8 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i <= n; i++)
#define rep3(i, x, n) for (int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
const ld EPS = 1e-10;
template <typename T> bool chmax(T &x, const T &y) {
return (x < y) ? (x = y, true) : false;
};
template <typename T> bool chmin(T &x, const T &y) {
return (x > y) ? (x = y, true) : false;
};
int main() {
int N;
string S;
cin >> N >> S;
int cnt = 0;
rep(i, N) cnt += S[i] - '0';
int a[2];
a[0] = cnt - 1, a[1] = cnt + 1;
int x[N][2], sum[2];
rep(i, 2) {
if (a[i] <= 0)
continue;
x[N - 1][i] = 1 % a[i], sum[i] = 0;
if (S[N - 1] == '1')
sum[i] = 1;
rep3(j, N - 2, 0) {
x[j][i] = (x[j + 1][i] * 2) % a[i];
if (S[j] == '1')
sum[i] += x[j][i], sum[i] %= a[i];
}
}
rep(i, N) {
int j = S[i] == '0';
int now = sum[j], ans = 1;
if (!j)
now += (a[j] - x[i][j]);
else
now += x[i][j];
now %= a[j];
while (now) {
now %= (__builtin_popcount(now));
ans++;
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i <= n; i++)
#define rep3(i, x, n) for (int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
const ld EPS = 1e-10;
template <typename T> bool chmax(T &x, const T &y) {
return (x < y) ? (x = y, true) : false;
};
template <typename T> bool chmin(T &x, const T &y) {
return (x > y) ? (x = y, true) : false;
};
int main() {
int N;
string S;
cin >> N >> S;
int cnt = 0;
rep(i, N) cnt += S[i] - '0';
int a[2];
a[0] = cnt - 1, a[1] = cnt + 1;
int x[N][2], sum[2];
rep(i, 2) {
if (a[i] <= 0)
continue;
x[N - 1][i] = 1 % a[i], sum[i] = 0;
if (S[N - 1] == '1')
sum[i] = 1;
rep3(j, N - 2, 0) {
x[j][i] = (x[j + 1][i] * 2) % a[i];
if (S[j] == '1')
sum[i] += x[j][i], sum[i] %= a[i];
}
}
rep(i, N) {
int j = S[i] == '0';
if (a[j] == 0) {
cout << 0 << endl;
continue;
}
int now = sum[j], ans = 1;
if (!j)
now += (a[j] - x[i][j]);
else
now += x[i][j];
now %= a[j];
while (now) {
now %= (__builtin_popcount(now));
ans++;
}
cout << ans << endl;
}
} | insert | 52 | 52 | 52 | 56 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> dp(n + 1);
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = 0; j < 20; j++)
if (i & (1 << j))
cnt++;
dp[i] = dp[i % cnt] + 1;
}
int modulo = 0;
vector<int> x(n);
for (int i = 0; i < n; i++) {
char c;
cin >> c;
x[i] = c - '0';
if (x[i])
modulo++;
}
reverse(x.begin(), x.end());
int modulo1 = modulo - 1;
int modulo2 = modulo + 1;
if (modulo1 < 0)
modulo1 = 1;
vector<int> p1(n);
vector<int> p2(n);
p1[0] = 1 % modulo1;
p2[0] = 1 % modulo2;
for (int i = 1; i < n; i++) {
p1[i] = p1[i - 1] * 2 % modulo1;
p2[i] = p2[i - 1] * 2 % modulo2;
}
int sum1 = 0;
int sum2 = 0;
for (int i = 0; i < n; i++) {
sum1 = (sum1 + p1[i] * x[i]) % modulo1;
sum2 = (sum2 + p2[i] * x[i]) % modulo2;
}
vector<int> ans(n);
for (int i = 0; i < n; i++) {
if (x[i] == 0) {
int tmp = sum2;
tmp = (tmp + p2[i]) % modulo2;
ans[i] = 1 + dp[tmp];
continue;
}
if (modulo == 1) {
ans[i] = 0;
continue;
}
int tmp = sum1;
tmp = (tmp - p1[i] + modulo1) % modulo1;
ans[i] = 1 + dp[tmp];
}
reverse(ans.begin(), ans.end());
for (auto &now : ans)
cout << now << '\n';
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> dp(n + 1);
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = 0; j < 20; j++)
if (i & (1 << j))
cnt++;
dp[i] = dp[i % cnt] + 1;
}
int modulo = 0;
vector<int> x(n);
for (int i = 0; i < n; i++) {
char c;
cin >> c;
x[i] = c - '0';
if (x[i])
modulo++;
}
reverse(x.begin(), x.end());
int modulo1 = modulo - 1;
int modulo2 = modulo + 1;
if (modulo1 <= 0)
modulo1 = 1;
vector<int> p1(n);
vector<int> p2(n);
p1[0] = 1 % modulo1;
p2[0] = 1 % modulo2;
for (int i = 1; i < n; i++) {
p1[i] = p1[i - 1] * 2 % modulo1;
p2[i] = p2[i - 1] * 2 % modulo2;
}
int sum1 = 0;
int sum2 = 0;
for (int i = 0; i < n; i++) {
sum1 = (sum1 + p1[i] * x[i]) % modulo1;
sum2 = (sum2 + p2[i] * x[i]) % modulo2;
}
vector<int> ans(n);
for (int i = 0; i < n; i++) {
if (x[i] == 0) {
int tmp = sum2;
tmp = (tmp + p2[i]) % modulo2;
ans[i] = 1 + dp[tmp];
continue;
}
if (modulo == 1) {
ans[i] = 0;
continue;
}
int tmp = sum1;
tmp = (tmp - p1[i] + modulo1) % modulo1;
ans[i] = 1 + dp[tmp];
}
reverse(ans.begin(), ans.end());
for (auto &now : ans)
cout << now << '\n';
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p02609 | C++ | Runtime Error |
// D - Anything Goes to Zero
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;
ll rem[2][200000];
ll rem_sum[2];
// aのn乗をmodで割った余りを計算
ll mod_pow(ll a, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1)
result = result * a % mod;
a = a * a % mod;
n >>= 1;
}
return result;
}
int popcount(int n) {
int result = 0;
while (n) {
if (n % 2 == 1)
result++;
n /= 2;
}
return result;
}
ll f(int n, int k) {
if (n == 0)
return k;
return f(n % popcount(n), k + 1);
}
int main() {
int N;
string X;
cin >> N >> X;
int pop_cnt = 0;
for (int i = 0; i < N; i++) {
if (X[i] == '1')
pop_cnt++;
}
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
rem_sum[0] += mod_pow(2, N - i - 1, pop_cnt + 1);
rem_sum[1] += mod_pow(2, N - i - 1, pop_cnt - 1);
}
}
vector<ll> ans_list;
ans_list.reserve(N);
for (int i = 0; i < N; i++) {
ll r;
if (X[i] == '0') {
r = (rem_sum[0] + mod_pow(2, N - i - 1, pop_cnt + 1)) % (pop_cnt + 1);
} else {
if (pop_cnt == 1) {
ans_list.push_back(0);
continue;
}
r = (rem_sum[1] - mod_pow(2, N - i - 1, pop_cnt - 1)) % (pop_cnt - 1);
}
ans_list.push_back(f(r, 1));
}
for (ll ans : ans_list) {
cout << ans << endl;
}
return 0;
} |
// D - Anything Goes to Zero
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;
ll rem[2][200000];
ll rem_sum[2];
// aのn乗をmodで割った余りを計算
ll mod_pow(ll a, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1)
result = result * a % mod;
a = a * a % mod;
n >>= 1;
}
return result;
}
int popcount(int n) {
int result = 0;
while (n) {
if (n % 2 == 1)
result++;
n /= 2;
}
return result;
}
ll f(int n, int k) {
if (n == 0)
return k;
return f(n % popcount(n), k + 1);
}
int main() {
int N;
string X;
cin >> N >> X;
int pop_cnt = 0;
for (int i = 0; i < N; i++) {
if (X[i] == '1')
pop_cnt++;
}
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
rem_sum[0] += mod_pow(2, N - i - 1, pop_cnt + 1);
if (pop_cnt != 1)
rem_sum[1] += mod_pow(2, N - i - 1, pop_cnt - 1);
}
}
vector<ll> ans_list;
ans_list.reserve(N);
for (int i = 0; i < N; i++) {
ll r;
if (X[i] == '0') {
r = (rem_sum[0] + mod_pow(2, N - i - 1, pop_cnt + 1)) % (pop_cnt + 1);
} else {
if (pop_cnt == 1) {
ans_list.push_back(0);
continue;
}
r = (rem_sum[1] - mod_pow(2, N - i - 1, pop_cnt - 1)) % (pop_cnt - 1);
}
ans_list.push_back(f(r, 1));
}
for (ll ans : ans_list) {
cout << ans << endl;
}
return 0;
} | replace | 56 | 57 | 56 | 58 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = pow(10, 9) + 7;
ll pw(ll n, ll mod) {
ll ans = 1;
ll x = 2, y = n;
while (y != 0) {
if (y % 2)
ans = ((ans % mod) * (x % mod)) % mod;
x = ((x % mod) * (x % mod)) % mod;
y /= 2;
}
return ans;
}
ll cunt(ll n) {
ll cnt = 0;
while (n != 0) {
if (n % 2)
cnt++;
n /= 2;
}
return cnt;
}
void func(ll n) {
ll cnt = 1;
while (n != 0) {
ll temp = cunt(n);
cnt++;
n = n % temp;
}
cout << cnt << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
string s;
cin >> s;
ll mn = 0, mx = 0;
for (ll i = 0; i < n; i++) {
if (s[i] == '1')
mn++;
}
if (mn < n) {
mx = mn + 1;
mn--;
} else {
mn--;
mx = mn;
}
ll chota = 0, bada = 0;
reverse(s.begin(), s.end());
ll temp1 = 1, temp2 = 1;
for (ll i = 0; i < n; i++) {
if (s[i] == '1') {
chota = ((chota % mn) + (temp1 % mn)) % mn;
bada = ((bada % mx) + (temp2 % mx)) % mx;
}
temp1 = ((temp1 % mn) * 2) % mn;
temp2 = ((temp2 % mx) * 2) % mx;
}
vector<ll> ans;
for (ll i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
ll temp = chota - pw(i, mn);
temp += mn;
temp = temp % mn;
func(temp);
} else {
ll temp = bada + pw(i, mx);
temp = temp % mx;
func(temp);
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = pow(10, 9) + 7;
ll pw(ll n, ll mod) {
ll ans = 1;
ll x = 2, y = n;
while (y != 0) {
if (y % 2)
ans = ((ans % mod) * (x % mod)) % mod;
x = ((x % mod) * (x % mod)) % mod;
y /= 2;
}
return ans;
}
ll cunt(ll n) {
ll cnt = 0;
while (n != 0) {
if (n % 2)
cnt++;
n /= 2;
}
return cnt;
}
void func(ll n) {
ll cnt = 1;
while (n != 0) {
ll temp = cunt(n);
cnt++;
n = n % temp;
}
cout << cnt << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
string s;
cin >> s;
ll mn = 0, mx = 0;
for (ll i = 0; i < n; i++) {
if (s[i] == '1')
mn++;
}
if (mn < n) {
mx = mn + 1;
mn--;
} else {
mn--;
mx = mn;
}
if (mn == 0 || mx == 0) {
for (ll i = 0; i < n; i++) {
if (s[i] == '1')
cout << 0 << endl;
else {
if (i == n - 1)
cout << 2 << endl;
else
cout << 1 << endl;
}
}
return 0;
}
ll chota = 0, bada = 0;
reverse(s.begin(), s.end());
ll temp1 = 1, temp2 = 1;
for (ll i = 0; i < n; i++) {
if (s[i] == '1') {
chota = ((chota % mn) + (temp1 % mn)) % mn;
bada = ((bada % mx) + (temp2 % mx)) % mx;
}
temp1 = ((temp1 % mn) * 2) % mn;
temp2 = ((temp2 % mx) * 2) % mx;
}
vector<ll> ans;
for (ll i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
ll temp = chota - pw(i, mn);
temp += mn;
temp = temp % mn;
func(temp);
} else {
ll temp = bada + pw(i, mx);
temp = temp % mx;
func(temp);
}
}
}
| insert | 60 | 60 | 60 | 74 | 0 | |
p02609 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using llong = long long;
#define inv(X) ((X) == '1' ? '0' : '1')
llong n;
string x;
llong bitcnt(llong a) {
llong ret = 0;
while (a > 0) {
if (a & 1)
ret++;
a >>= 1;
}
return ret;
}
llong f(llong x) {
llong cnt = 0;
while (bitcnt(x) > 0) {
x %= bitcnt(x);
cnt++;
}
return cnt;
}
llong to_int(string &s, llong mod) {
llong ret = 0;
for (auto ch : s) {
ret *= 2;
if (ch == '1')
ret |= 1;
ret %= mod;
}
return ret;
}
llong pow_mod(llong n, llong m, llong mod) {
llong ret = 1;
while (m > 0) {
if (m & 1) {
ret *= n;
ret %= mod;
}
n *= n;
n %= mod;
m >>= 1;
}
return ret;
}
int main() {
cin >> n >> x;
llong cnt = count(x.begin(), x.end(), '1');
llong x1 = to_int(x, cnt + 1);
llong x2 = to_int(x, cnt - 1);
for (int i = 0; i < n; i++) {
if (x[i] == '0') {
llong s = x1 + pow_mod(2, n - i - 1, cnt + 1);
s %= cnt + 1;
cout << f(s) + 1 << '\n';
} else {
if (cnt - 1 == 0) {
cout << 0 << '\n';
continue;
}
llong s = x2 - pow_mod(2, n - i - 1, cnt - 1);
s %= cnt - 1;
s += cnt - 1;
s %= cnt - 1;
cout << f(s) + 1 << '\n';
}
}
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using llong = long long;
#define inv(X) ((X) == '1' ? '0' : '1')
llong n;
string x;
llong bitcnt(llong a) {
llong ret = 0;
while (a > 0) {
if (a & 1)
ret++;
a >>= 1;
}
return ret;
}
llong f(llong x) {
llong cnt = 0;
while (bitcnt(x) > 0) {
x %= bitcnt(x);
cnt++;
}
return cnt;
}
llong to_int(string &s, llong mod) {
llong ret = 0;
for (auto ch : s) {
ret *= 2;
if (ch == '1')
ret |= 1;
ret %= mod;
}
return ret;
}
llong pow_mod(llong n, llong m, llong mod) {
llong ret = 1;
while (m > 0) {
if (m & 1) {
ret *= n;
ret %= mod;
}
n *= n;
n %= mod;
m >>= 1;
}
return ret;
}
int main() {
cin >> n >> x;
llong cnt = count(x.begin(), x.end(), '1');
llong x1 = to_int(x, cnt + 1);
llong x2;
if (cnt > 1)
x2 = to_int(x, cnt - 1);
for (int i = 0; i < n; i++) {
if (x[i] == '0') {
llong s = x1 + pow_mod(2, n - i - 1, cnt + 1);
s %= cnt + 1;
cout << f(s) + 1 << '\n';
} else {
if (cnt - 1 == 0) {
cout << 0 << '\n';
continue;
}
llong s = x2 - pow_mod(2, n - i - 1, cnt - 1);
s %= cnt - 1;
s += cnt - 1;
s %= cnt - 1;
cout << f(s) + 1 << '\n';
}
}
} | replace | 59 | 60 | 59 | 62 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)
typedef long long ll;
const int N = 2e5 + 5;
template <typename T> void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = (x << 1) + (x << 3) + c - '0';
x *= f;
}
int n;
int a[N], cnt;
int sum0, sum1;
int Qpow(int base, int ind, int p) {
int res = 1;
while (ind) {
if (ind & 1)
res = 1ll * res * base % p;
base = 1ll * base * base % p;
ind >>= 1;
}
return res;
}
int solve(int x) {
if (!x)
return 1;
int t = x, count = 0;
while (t) {
if (t & 1)
count++;
t /= 2;
}
return solve(x % count) + 1;
}
int main() {
read(n);
Rep(i, 1, n) scanf("%1d", &a[i]), cnt += a[i];
Rep(i, 1, n) {
sum0 += a[i] * Qpow(2, n - i, cnt + 1), sum0 %= (cnt + 1);
sum1 += a[i] * Qpow(2, n - i, cnt - 1), sum1 %= (cnt - 1);
}
Rep(i, 1, n) if (a[i]) printf(
"%d\n", solve((sum1 - Qpow(2, n - i, cnt - 1) + (cnt - 1)) % (cnt - 1)));
else printf("%d\n",
solve((sum0 + Qpow(2, n - i, cnt + 1) + cnt + 1) % (cnt + 1)));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)
typedef long long ll;
const int N = 2e5 + 5;
template <typename T> void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = (x << 1) + (x << 3) + c - '0';
x *= f;
}
int n;
int a[N], cnt;
int sum0, sum1;
int Qpow(int base, int ind, int p) {
int res = 1;
while (ind) {
if (ind & 1)
res = 1ll * res * base % p;
base = 1ll * base * base % p;
ind >>= 1;
}
return res;
}
int solve(int x) {
if (!x)
return 1;
int t = x, count = 0;
while (t) {
if (t & 1)
count++;
t /= 2;
}
return solve(x % count) + 1;
}
int main() {
read(n);
Rep(i, 1, n) scanf("%1d", &a[i]), cnt += a[i];
if (cnt == 1) {
Rep(i, 1, n) sum0 += a[i] * Qpow(2, n - i, cnt + 1), sum0 %= (cnt + 1);
Rep(i, 1, n) if (!a[i]) printf(
"%d\n", solve((sum0 + Qpow(2, n - i, cnt + 1) + cnt + 1) % (cnt + 1)));
else puts("0");
return 0;
}
Rep(i, 1, n) {
sum0 += a[i] * Qpow(2, n - i, cnt + 1), sum0 %= (cnt + 1);
sum1 += a[i] * Qpow(2, n - i, cnt - 1), sum1 %= (cnt - 1);
}
Rep(i, 1, n) if (a[i]) printf(
"%d\n", solve((sum1 - Qpow(2, n - i, cnt - 1) + (cnt - 1)) % (cnt - 1)));
else printf("%d\n",
solve((sum0 + Qpow(2, n - i, cnt + 1) + cnt + 1) % (cnt + 1)));
return 0;
} | insert | 53 | 53 | 53 | 60 | 0 | |
p02609 | 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;
// べき乗高速化
ll mpow(ll x, ll n, ll M) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
int main() {
ll n;
cin >> n;
string x;
cin >> x;
reverse(x.begin(), x.end());
ll popcountx = 0;
rep(i, n) {
if (x[i] == '1')
popcountx++;
}
ll X = 0; // mod(popcountx + 1)
ll Y = 0; // mod(popcountx - 1)
rep(i, n) {
if (x[i] == '1') {
X += mpow(2, i, popcountx + 1);
X %= popcountx + 1;
if (popcountx > 0) {
Y += mpow(2, i, popcountx - 1);
Y %= popcountx - 1;
}
}
}
vector<ll> ans;
rep(i, n) {
if (x[i] == '0') {
ll temp = X;
temp += mpow(2, i, popcountx + 1);
temp %= popcountx + 1;
ll count = 1;
while (temp > 0) {
temp = temp % __builtin_popcount(temp);
count++;
}
ans.push_back(count);
} else {
ll temp = Y;
if (popcountx == 1) {
ans.push_back(0);
continue;
}
temp -= mpow(2, i, popcountx - 1);
ll count = 1;
temp %= popcountx - 1;
if (temp < 0) {
temp += popcountx - 1;
}
while (temp > 0) {
temp = temp % __builtin_popcount(temp);
count++;
}
ans.push_back(count);
}
}
reverse(ans.begin(), ans.end());
for (auto v : ans) {
cout << v << 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;
// べき乗高速化
ll mpow(ll x, ll n, ll M) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
int main() {
ll n;
cin >> n;
string x;
cin >> x;
reverse(x.begin(), x.end());
ll popcountx = 0;
rep(i, n) {
if (x[i] == '1')
popcountx++;
}
ll X = 0; // mod(popcountx + 1)
ll Y = 0; // mod(popcountx - 1)
rep(i, n) {
if (x[i] == '1') {
X += mpow(2, i, popcountx + 1);
X %= popcountx + 1;
if (popcountx > 1) {
Y += mpow(2, i, popcountx - 1);
Y %= popcountx - 1;
}
}
}
vector<ll> ans;
rep(i, n) {
if (x[i] == '0') {
ll temp = X;
temp += mpow(2, i, popcountx + 1);
temp %= popcountx + 1;
ll count = 1;
while (temp > 0) {
temp = temp % __builtin_popcount(temp);
count++;
}
ans.push_back(count);
} else {
ll temp = Y;
if (popcountx == 1) {
ans.push_back(0);
continue;
}
temp -= mpow(2, i, popcountx - 1);
ll count = 1;
temp %= popcountx - 1;
if (temp < 0) {
temp += popcountx - 1;
}
while (temp > 0) {
temp = temp % __builtin_popcount(temp);
count++;
}
ans.push_back(count);
}
}
reverse(ans.begin(), ans.end());
for (auto v : ans) {
cout << v << endl;
}
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F(i, a, b) for (int i = a; i <= b; ++i)
const int maxn = 2e5 + 5;
int n, a[maxn], pw1[maxn], pw2[maxn], f[maxn], sum1 = 0, sum2 = 0, tot = 0;
char s[maxn];
int pct(int x) { return x == 0 ? x : pct(x >> 1) + (x & 1); }
void run(int p) {
a[p] ^= 1;
int x = 0, pc = 0;
if (a[p])
pc = tot + 1;
else
pc = tot - 1;
if (!pc) {
a[p] ^= 1;
f[p] = 0;
return;
}
if (pc == tot - 1)
x = (sum1 + tot - 1 - pw1[p]) % (tot - 1);
else
x = (sum2 + pw2[p]) % (tot + 1);
++f[p];
while (x) {
pc = pct(x);
x %= pc;
++f[p];
}
a[p] ^= 1;
}
int main() {
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
scanf("%d", &n);
scanf("%s", s + 1);
F(i, 1, n)
if (s[i] == '1')
a[i] = 1, ++tot;
LL all = 0;
for (int i = n; i; --i)
all += a[i] * (1LL << (n - i));
int tmp = 1;
if (tot) {
F(i, 1, n) sum1 = (2 * sum1 + a[i]) % (tot - 1);
for (int i = n; i; --i)
pw1[i] = tmp, tmp = tmp * 2 % (tot - 1);
}
if (tot < n) {
tmp = 1;
F(i, 1, n)
sum2 = (2 * sum2 + a[i]) % (tot + 1);
for (int i = n; i; --i)
pw2[i] = tmp, tmp = tmp * 2 % (tot + 1);
}
F(i, 1, n) run(i);
F(i, 1, n) printf("%d\n", f[i]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F(i, a, b) for (int i = a; i <= b; ++i)
const int maxn = 2e5 + 5;
int n, a[maxn], pw1[maxn], pw2[maxn], f[maxn], sum1 = 0, sum2 = 0, tot = 0;
char s[maxn];
int pct(int x) { return x == 0 ? x : pct(x >> 1) + (x & 1); }
void run(int p) {
a[p] ^= 1;
int x = 0, pc = 0;
if (a[p])
pc = tot + 1;
else
pc = tot - 1;
if (!pc) {
a[p] ^= 1;
f[p] = 0;
return;
}
if (pc == tot - 1)
x = (sum1 + tot - 1 - pw1[p]) % (tot - 1);
else
x = (sum2 + pw2[p]) % (tot + 1);
++f[p];
while (x) {
pc = pct(x);
x %= pc;
++f[p];
}
a[p] ^= 1;
}
int main() {
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
scanf("%d", &n);
scanf("%s", s + 1);
F(i, 1, n)
if (s[i] == '1')
a[i] = 1, ++tot;
LL all = 0;
for (int i = n; i; --i)
all += a[i] * (1LL << (n - i));
int tmp = 1;
if (tot > 1) {
F(i, 1, n) sum1 = (2 * sum1 + a[i]) % (tot - 1);
for (int i = n; i; --i)
pw1[i] = tmp, tmp = tmp * 2 % (tot - 1);
}
if (tot < n) {
tmp = 1;
F(i, 1, n)
sum2 = (2 * sum2 + a[i]) % (tot + 1);
for (int i = n; i; --i)
pw2[i] = tmp, tmp = tmp * 2 % (tot + 1);
}
F(i, 1, n) run(i);
F(i, 1, n) printf("%d\n", f[i]);
return 0;
} | replace | 44 | 45 | 44 | 45 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, int>
const ll MOD = 1e9 + 7;
const int INF = 2e9;
const double PI = acos(-1);
const int MAX = 200010;
int main() {
ios_base::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
reverse(s.begin(), s.end());
int cnt = 0;
rep(i, n) {
if (s[i] == '1')
++cnt;
}
vector<ll> b1(n), b2(n);
b1[0] = 1, b2[0] = 1;
ll s1 = 0, s2 = 0;
if (cnt - 1 > 0) {
rep(i, n - 1) b1[i + 1] = (2 * b1[i]) % (cnt - 1);
rep(i, n) {
if (s[i] == '1')
s1 = (s1 + b1[i]) % (cnt - 1);
}
}
rep(i, n - 1) b2[i + 1] = (2 * b2[i]) % (cnt + 1);
rep(i, n) {
if (s[i] == '1')
s2 = (s2 + b2[i]) % (cnt + 1);
}
vector<int> p(60);
repr(i, 1, 60) {
int j = i, m = 0;
while (j > 0) {
if (j % 2 == 1)
++m;
j /= 2;
}
p[i] = p[i % m] + 1;
}
invrep(i, n) {
int ans = 0;
if (s[i] == '1') {
if (cnt > 1) {
ll tmp = (s1 + (cnt - 1) - b1[i]) % (cnt - 1);
ans = p[tmp] + 1;
}
} else {
ll tmp = (s2 + b2[i]) % (cnt + 1);
ans = p[tmp] + 1;
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, int>
const ll MOD = 1e9 + 7;
const int INF = 2e9;
const double PI = acos(-1);
const int MAX = 200010;
int main() {
ios_base::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
reverse(s.begin(), s.end());
int cnt = 0;
rep(i, n) {
if (s[i] == '1')
++cnt;
}
vector<ll> b1(n), b2(n);
b1[0] = 1, b2[0] = 1;
ll s1 = 0, s2 = 0;
if (cnt - 1 > 0) {
rep(i, n - 1) b1[i + 1] = (2 * b1[i]) % (cnt - 1);
rep(i, n) {
if (s[i] == '1')
s1 = (s1 + b1[i]) % (cnt - 1);
}
}
rep(i, n - 1) b2[i + 1] = (2 * b2[i]) % (cnt + 1);
rep(i, n) {
if (s[i] == '1')
s2 = (s2 + b2[i]) % (cnt + 1);
}
vector<int> p(200010);
repr(i, 1, 200010) {
int j = i, m = 0;
while (j > 0) {
if (j % 2 == 1)
++m;
j /= 2;
}
p[i] = p[i % m] + 1;
}
invrep(i, n) {
int ans = 0;
if (s[i] == '1') {
if (cnt > 1) {
ll tmp = (s1 + (cnt - 1) - b1[i]) % (cnt - 1);
ans = p[tmp] + 1;
}
} else {
ll tmp = (s2 + b2[i]) % (cnt + 1);
ans = p[tmp] + 1;
}
cout << ans << endl;
}
return 0;
}
| replace | 42 | 44 | 42 | 44 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <typename T> T mod_pow(T x, T n, const T &p) {
T ret = 1;
while (n > 0) {
if (n & 1)
(ret *= x) %= p;
(x *= x) %= p;
n >>= 1;
}
return ret;
}
void solve(long long N, std::string X) {
ll originalOnes = 0;
for (int i = N - 1; i >= 0; --i) {
if (X[i] == '1') {
originalOnes++;
}
}
// for(int i=N-1;i>=0;--i){
// plusNum*=2;
// minusNum*=2;
// if(X[i] == '1'){
// plusNum++;
// minusNum++;
// }
// plusNum%=(originalOnes+1);
// minusNum%=(originalOnes-1);
// }
ll plusNum = 0;
ll minusNum = 0;
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
plusNum += mod_pow(2ll, N - 1 - i, originalOnes + 1);
minusNum += mod_pow(2ll, N - 1 - i, originalOnes - 1);
}
plusNum %= (originalOnes + 1);
if (originalOnes == 1) {
minusNum = 0;
} else {
minusNum %= (originalOnes - 1);
}
}
// cerr <<"debug=" <<debug << endl;
// cerr <<"plus=" <<plusNum <<"minusNum =" <<minusNum << endl;
for (ll i = 0; i < N; i++) {
if (X[i] == '0') {
ll ones = originalOnes + 1;
ll num = plusNum + mod_pow(2ll, N - 1 - i, ones);
num %= ones;
ll ans = 1;
while (num > 0) {
num %= __builtin_popcount(num);
ans++;
}
cout << ans << "\n";
} else {
if (originalOnes == 1) {
cout << 0 << "\n";
continue;
}
ll ones = originalOnes - 1;
ll num = minusNum + ones - mod_pow(2ll, N - 1 - i, ones);
// cerr <<"pow=" <<mod_pow(2ll,N-1-i,ones)<< endl;
// cerr <<"i="<<i <<"num=" <<num<<"ones=" <<ones<< endl;
num %= ones;
ll ans = 1;
while (num > 0) {
num %= __builtin_popcount(num);
ans++;
}
cout << ans << "\n";
}
}
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
long long N;
scanf("%lld", &N);
std::string X;
std::cin >> X;
solve(N, X);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <typename T> T mod_pow(T x, T n, const T &p) {
T ret = 1;
while (n > 0) {
if (n & 1)
(ret *= x) %= p;
(x *= x) %= p;
n >>= 1;
}
return ret;
}
void solve(long long N, std::string X) {
ll originalOnes = 0;
for (int i = N - 1; i >= 0; --i) {
if (X[i] == '1') {
originalOnes++;
}
}
// for(int i=N-1;i>=0;--i){
// plusNum*=2;
// minusNum*=2;
// if(X[i] == '1'){
// plusNum++;
// minusNum++;
// }
// plusNum%=(originalOnes+1);
// minusNum%=(originalOnes-1);
// }
ll plusNum = 0;
ll minusNum = 0;
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
plusNum += mod_pow(2ll, N - 1 - i, originalOnes + 1);
if (originalOnes != 1) {
minusNum += mod_pow(2ll, N - 1 - i, originalOnes - 1);
}
}
plusNum %= (originalOnes + 1);
if (originalOnes == 1) {
minusNum = 0;
} else {
minusNum %= (originalOnes - 1);
}
}
// cerr <<"debug=" <<debug << endl;
// cerr <<"plus=" <<plusNum <<"minusNum =" <<minusNum << endl;
for (ll i = 0; i < N; i++) {
if (X[i] == '0') {
ll ones = originalOnes + 1;
ll num = plusNum + mod_pow(2ll, N - 1 - i, ones);
num %= ones;
ll ans = 1;
while (num > 0) {
num %= __builtin_popcount(num);
ans++;
}
cout << ans << "\n";
} else {
if (originalOnes == 1) {
cout << 0 << "\n";
continue;
}
ll ones = originalOnes - 1;
ll num = minusNum + ones - mod_pow(2ll, N - 1 - i, ones);
// cerr <<"pow=" <<mod_pow(2ll,N-1-i,ones)<< endl;
// cerr <<"i="<<i <<"num=" <<num<<"ones=" <<ones<< endl;
num %= ones;
ll ans = 1;
while (num > 0) {
num %= __builtin_popcount(num);
ans++;
}
cout << ans << "\n";
}
}
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
long long N;
scanf("%lld", &N);
std::string X;
std::cin >> X;
solve(N, X);
return 0;
}
| replace | 39 | 40 | 39 | 42 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lli long long
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define rep0(i, j) for (int i = 0; i < j; i++)
#define rep1(i, j) for (int i = 1; i <= j; i++)
#define rep0d(i, j) for (int i = j - 1; i >= 0; i--)
#define MOD 1000000007
#define MAX (lli)1e12
typedef pair<lli, lli> p;
class Graph {
int V;
vector<list<p>> adj;
const int INF = (int)1e6;
public:
Graph(lli V) : adj(V) { this->V = V; }
void addEdge(int u, int v, int w) { adj[u].push_back(make_pair(v, w)); }
lli edgeNum() {
lli sum = 0;
rep0(i, V) sum += adj[i].size();
return sum;
}
bool route(lli from, lli to) { // vec[i]==j: j->iっていうもとに戻れる道がある
vector<lli> vec(V, -1);
dfs(1, from, vec);
return vec[to] >= 0;
}
void dfs(lli ed, lli num, vector<lli> &vec) {
for (auto e : adj[num]) {
if (vec[e.first] != -1)
continue;
vec[e.first] = num;
dfs(ed + 1, e.first, vec);
}
}
vector<int> bfs(int n) {
queue<int> q;
vector<int> vec(V, -1);
q.push(n);
vec[n] = 0;
while (!q.empty()) {
int p = q.front();
q.pop();
for (auto e : adj[p]) {
if (vec[e.first] == -1) {
q.push(e.first);
vec[e.first] = e.second + vec[p];
}
}
}
return vec;
}
vector<int> shortestPath(int src) {
priority_queue<p, vector<p>, greater<p>> pq;
vector<int> dist(V, INF);
pq.push(make_pair(0, src));
dist[src] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
list<p>::iterator i;
for (auto i = adj[u].begin(); i != adj[u].end(); ++i) {
int v = i->first;
int weight = i->second;
if (dist[v] > dist[u] + weight) {
dist[v] = dist[u] + weight;
pq.push(make_pair(dist[v], v));
}
}
}
for (int i = 0; i < V; i++)
if (dist[i] == INF)
dist[i] = -1;
return dist;
}
};
struct UF {
vector<int> par, size;
UF(int N) : par(N), size(N, 1) { rep0(i, N) par[i] = i; }
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
par[rx] = ry;
size[rx] += size[ry];
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int getSize(int x) { return size[x]; }
};
struct BIT {
vector<lli> tab; // bit table
BIT(int n) : tab(n + 1) { rep0(i, n + 1) tab[i] = 0; }
void add(int p, lli num) {
for (++p; p < tab.size(); p += p & -p)
tab[p] += num;
}
lli sum(int p) { // from 0 to p
lli ans = 0;
for (++p; p > 0; p -= p & -p)
ans += tab[p];
return ans;
}
void debug() {
rep0(i, tab.size()) cout << tab[i] << ' ';
cout << endl;
}
};
// pairに関するもの
lli sum(p c) { return (c.first + c.second); }
p operator-(const p &l, const p &r) {
return {l.first - r.first, l.second - r.second};
}
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.first < right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.second < right.second;
}
lli gcd(lli a, lli b) {
if (a < b)
return gcd(b, a);
lli temp;
while ((temp = a % b)) {
a = b;
b = temp;
}
return b;
}
struct nCr {
vector<lli> f, rf;
lli count = 0;
nCr(lli num) : f(num), rf(num) {
count = num;
f[0] = 1;
rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
rep0(i, num + 1) rf[i] = inv(f[i]);
}
lli inv(lli x) {
lli res = 1;
lli k = MOD - 2;
lli y = x;
while (k) {
if (k & 1)
res = (res * y) % MOD;
y = (y * y) % MOD;
k /= 2;
}
return res;
}
lli C(lli n, lli k) {
if (k > n || k < 0)
return 0;
lli a = f[n];
lli b = rf[n - k];
lli c = rf[k];
lli bc = (b * c) % MOD;
return (a * bc) % MOD;
}
};
int main() {
string s;
lli n;
cin >> n >> s;
lli tab[200001];
tab[0] = 0;
rep1(i, 200000) {
lli tp = i, ct = 0;
while (tp > 0) {
ct += (tp & 1);
tp >>= 1;
}
tab[i] = tab[i % ct] + 1;
}
lli count = 0;
rep0(i, n) count += (s[i] == '1');
vector<lli> num1(n, 1), num2(n, 1);
rep1(i, n - 1) { num1[i] = (num1[i - 1] * 2) % (count + 1); }
if (count > 0) {
rep1(i, n - 1) { num2[i] = (num2[i - 1] * 2) % (count - 1); }
}
lli tp1 = 0;
rep0(j, n) { tp1 += num1[n - j - 1] * (s[j] == '1'); }
lli tp2 = 0;
rep0(j, n) { tp2 += num2[n - j - 1] * (s[j] == '1'); }
rep0(i, n) {
if (s[i] == '0') {
tp1 += num1[n - i - 1];
lli tp = 0;
cout << tab[tp1 % (count + 1)] + 1 << '\n';
tp1 -= num1[n - i - 1];
} else {
if (count == 1) {
cout << 0 << '\n';
continue;
}
tp2 -= num2[n - i - 1];
tp2 += count - 1;
cout << tab[tp2 % (count - 1)] + 1 << '\n';
tp2 += num2[n - i - 1];
tp2 -= count - 1;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define lli long long
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define rep0(i, j) for (int i = 0; i < j; i++)
#define rep1(i, j) for (int i = 1; i <= j; i++)
#define rep0d(i, j) for (int i = j - 1; i >= 0; i--)
#define MOD 1000000007
#define MAX (lli)1e12
typedef pair<lli, lli> p;
class Graph {
int V;
vector<list<p>> adj;
const int INF = (int)1e6;
public:
Graph(lli V) : adj(V) { this->V = V; }
void addEdge(int u, int v, int w) { adj[u].push_back(make_pair(v, w)); }
lli edgeNum() {
lli sum = 0;
rep0(i, V) sum += adj[i].size();
return sum;
}
bool route(lli from, lli to) { // vec[i]==j: j->iっていうもとに戻れる道がある
vector<lli> vec(V, -1);
dfs(1, from, vec);
return vec[to] >= 0;
}
void dfs(lli ed, lli num, vector<lli> &vec) {
for (auto e : adj[num]) {
if (vec[e.first] != -1)
continue;
vec[e.first] = num;
dfs(ed + 1, e.first, vec);
}
}
vector<int> bfs(int n) {
queue<int> q;
vector<int> vec(V, -1);
q.push(n);
vec[n] = 0;
while (!q.empty()) {
int p = q.front();
q.pop();
for (auto e : adj[p]) {
if (vec[e.first] == -1) {
q.push(e.first);
vec[e.first] = e.second + vec[p];
}
}
}
return vec;
}
vector<int> shortestPath(int src) {
priority_queue<p, vector<p>, greater<p>> pq;
vector<int> dist(V, INF);
pq.push(make_pair(0, src));
dist[src] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
list<p>::iterator i;
for (auto i = adj[u].begin(); i != adj[u].end(); ++i) {
int v = i->first;
int weight = i->second;
if (dist[v] > dist[u] + weight) {
dist[v] = dist[u] + weight;
pq.push(make_pair(dist[v], v));
}
}
}
for (int i = 0; i < V; i++)
if (dist[i] == INF)
dist[i] = -1;
return dist;
}
};
struct UF {
vector<int> par, size;
UF(int N) : par(N), size(N, 1) { rep0(i, N) par[i] = i; }
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
par[rx] = ry;
size[rx] += size[ry];
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int getSize(int x) { return size[x]; }
};
struct BIT {
vector<lli> tab; // bit table
BIT(int n) : tab(n + 1) { rep0(i, n + 1) tab[i] = 0; }
void add(int p, lli num) {
for (++p; p < tab.size(); p += p & -p)
tab[p] += num;
}
lli sum(int p) { // from 0 to p
lli ans = 0;
for (++p; p > 0; p -= p & -p)
ans += tab[p];
return ans;
}
void debug() {
rep0(i, tab.size()) cout << tab[i] << ' ';
cout << endl;
}
};
// pairに関するもの
lli sum(p c) { return (c.first + c.second); }
p operator-(const p &l, const p &r) {
return {l.first - r.first, l.second - r.second};
}
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.first < right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.second < right.second;
}
lli gcd(lli a, lli b) {
if (a < b)
return gcd(b, a);
lli temp;
while ((temp = a % b)) {
a = b;
b = temp;
}
return b;
}
struct nCr {
vector<lli> f, rf;
lli count = 0;
nCr(lli num) : f(num), rf(num) {
count = num;
f[0] = 1;
rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
rep0(i, num + 1) rf[i] = inv(f[i]);
}
lli inv(lli x) {
lli res = 1;
lli k = MOD - 2;
lli y = x;
while (k) {
if (k & 1)
res = (res * y) % MOD;
y = (y * y) % MOD;
k /= 2;
}
return res;
}
lli C(lli n, lli k) {
if (k > n || k < 0)
return 0;
lli a = f[n];
lli b = rf[n - k];
lli c = rf[k];
lli bc = (b * c) % MOD;
return (a * bc) % MOD;
}
};
int main() {
string s;
lli n;
cin >> n >> s;
lli tab[200001];
tab[0] = 0;
rep1(i, 200000) {
lli tp = i, ct = 0;
while (tp > 0) {
ct += (tp & 1);
tp >>= 1;
}
tab[i] = tab[i % ct] + 1;
}
lli count = 0;
rep0(i, n) count += (s[i] == '1');
vector<lli> num1(n, 1), num2(n, 1);
rep1(i, n - 1) { num1[i] = (num1[i - 1] * 2) % (count + 1); }
if (count > 1) {
rep1(i, n - 1) { num2[i] = (num2[i - 1] * 2) % (count - 1); }
}
lli tp1 = 0;
rep0(j, n) { tp1 += num1[n - j - 1] * (s[j] == '1'); }
lli tp2 = 0;
rep0(j, n) { tp2 += num2[n - j - 1] * (s[j] == '1'); }
rep0(i, n) {
if (s[i] == '0') {
tp1 += num1[n - i - 1];
lli tp = 0;
cout << tab[tp1 % (count + 1)] + 1 << '\n';
tp1 -= num1[n - i - 1];
} else {
if (count == 1) {
cout << 0 << '\n';
continue;
}
tp2 -= num2[n - i - 1];
tp2 += count - 1;
cout << tab[tp2 % (count - 1)] + 1 << '\n';
tp2 += num2[n - i - 1];
tp2 -= count - 1;
}
}
}
| replace | 217 | 218 | 217 | 218 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
using namespace std;
const LL MOD = 1e9 + 7;
LL n, pwm1[200020], pw[200020], pwp1[200020], num = 0, resm1 = 0, res = 0,
resp1 = 0;
string s;
int get(LL x) {
int ret = 0, y;
while (x > 0) {
y = __builtin_popcount(x);
x %= y;
ret++;
}
return ret;
}
int main() {
cin >> n >> s;
rep(i, n) num += s[i] - '0';
pwm1[0] = pw[0] = pwp1[0] = 1;
repn(i, 200010) {
if (num - 1 > 0)
pwm1[i] = pwm1[i - 1] * 2 % (num - 1);
if (num > 0)
pw[i] = pw[i - 1] * 2 % num;
pwp1[i] = pwp1[i - 1] * 2 % (num + 1);
}
rep(i, n) {
if (num - 1 > 0)
resm1 = (resm1 + (s[i] == '1') * pwm1[n - i - 1]) % (num - 1);
if (num > 0)
res = (res + (s[i] == '1') * pw[n - i - 1]) % num;
resp1 = (resp1 + (s[i] == '1') * pwp1[n - i - 1]) % (num + 1);
}
rep(i, n) {
if (s[i] == '0') {
LL tmp = (resp1 + pwp1[n - i - 1]) % (num + 1);
printf("%d\n", get(tmp) + 1);
} else {
LL tmp = (resm1 - pwm1[n - i - 1] + num - 1 + num - 1) % (num - 1);
printf("%d\n", get(tmp) + 1);
}
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
using namespace std;
const LL MOD = 1e9 + 7;
LL n, pwm1[200020], pw[200020], pwp1[200020], num = 0, resm1 = 0, res = 0,
resp1 = 0;
string s;
int get(LL x) {
int ret = 0, y;
while (x > 0) {
y = __builtin_popcount(x);
x %= y;
ret++;
}
return ret;
}
int main() {
cin >> n >> s;
rep(i, n) num += s[i] - '0';
pwm1[0] = pw[0] = pwp1[0] = 1;
repn(i, 200010) {
if (num - 1 > 0)
pwm1[i] = pwm1[i - 1] * 2 % (num - 1);
if (num > 0)
pw[i] = pw[i - 1] * 2 % num;
pwp1[i] = pwp1[i - 1] * 2 % (num + 1);
}
rep(i, n) {
if (num - 1 > 0)
resm1 = (resm1 + (s[i] == '1') * pwm1[n - i - 1]) % (num - 1);
if (num > 0)
res = (res + (s[i] == '1') * pw[n - i - 1]) % num;
resp1 = (resp1 + (s[i] == '1') * pwp1[n - i - 1]) % (num + 1);
}
rep(i, n) {
if (s[i] == '0') {
LL tmp = (resp1 + pwp1[n - i - 1]) % (num + 1);
printf("%d\n", get(tmp) + 1);
} else {
if (num == 1) {
puts("0");
continue;
}
LL tmp = (resm1 - pwm1[n - i - 1] + num - 1 + num - 1) % (num - 1);
printf("%d\n", get(tmp) + 1);
}
}
return 0;
} | insert | 52 | 52 | 52 | 56 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) \
for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) \
for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e9 + 10;
ll MOD = 1e9 + 7;
const ll LINF = 1e18;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
(a *= a) %= MOD;
n >>= 1;
}
return res;
}
ll n;
string x;
ll popcnt(string x) {
ll res = 0;
rep(i, n) if (x[i] == '1') res++;
return res;
}
void rev(ll i) {
if (x[i] == '1')
x[i] = '0';
else
x[i] = '1';
}
ll bitcount(ll x) {
if (x == 0)
return 0;
return bitcount(x >> 1) + (x & 1);
}
ll f(ll a) {
ll cnt = bitcount(a);
return a % cnt;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> x;
ll cnt = popcnt(x);
// 1回目の+1, -1のmodを求めたい
ll aa = 0, bb = 0;
MOD = cnt + 1;
rep(i, n) {
if (x[i] == '1')
(aa += modpow(2, n - i - 1)) %= MOD;
}
MOD = cnt - 1;
rep(i, n) {
if (x[i] == '1')
(bb += modpow(2, n - i - 1)) %= MOD;
}
// cout<<aa<<bb<<endl;
rep(i, n) {
ll ans = 1;
if (x[i] == '1') {
MOD = cnt - 1;
if (MOD == 0) {
cout << 0 << endl;
continue;
}
ll tmp = modpow(2, n - i - 1);
ll mo = (bb - tmp + MOD) % MOD;
while (mo > 0) {
mo = f(mo);
ans++;
}
} else {
MOD = cnt + 1;
ll tmp = modpow(2, n - i - 1);
ll mo = (aa + tmp) % MOD;
while (mo > 0) {
mo = f(mo);
ans++;
}
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) \
for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) \
for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e9 + 10;
ll MOD = 1e9 + 7;
const ll LINF = 1e18;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
(a *= a) %= MOD;
n >>= 1;
}
return res;
}
ll n;
string x;
ll popcnt(string x) {
ll res = 0;
rep(i, n) if (x[i] == '1') res++;
return res;
}
void rev(ll i) {
if (x[i] == '1')
x[i] = '0';
else
x[i] = '1';
}
ll bitcount(ll x) {
if (x == 0)
return 0;
return bitcount(x >> 1) + (x & 1);
}
ll f(ll a) {
ll cnt = bitcount(a);
return a % cnt;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> x;
ll cnt = popcnt(x);
// 1回目の+1, -1のmodを求めたい
ll aa = 0, bb = 0;
MOD = cnt + 1;
rep(i, n) {
if (x[i] == '1')
(aa += modpow(2, n - i - 1)) %= MOD;
}
MOD = cnt - 1;
if (MOD)
rep(i, n) {
if (x[i] == '1')
(bb += modpow(2, n - i - 1)) %= MOD;
}
// cout<<aa<<bb<<endl;
rep(i, n) {
ll ans = 1;
if (x[i] == '1') {
MOD = cnt - 1;
if (MOD == 0) {
cout << 0 << endl;
continue;
}
ll tmp = modpow(2, n - i - 1);
ll mo = (bb - tmp + MOD) % MOD;
while (mo > 0) {
mo = f(mo);
ans++;
}
} else {
MOD = cnt + 1;
ll tmp = modpow(2, n - i - 1);
ll mo = (aa + tmp) % MOD;
while (mo > 0) {
mo = f(mo);
ans++;
}
}
cout << ans << endl;
}
} | replace | 107 | 111 | 107 | 112 | 0 | |
p02609 | C++ | Runtime Error | #include <bits/stdc++.h>
#define del(a, i) memset(a, i, sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l + r) >> 1)
#define lowbit(x) (x & (-x))
#define INF 0x3f3f3f3f
using namespace std;
template <class T> inl T read() {
T x = 0;
int f = 1;
char k = getchar();
for (; k > '9' || k < '0'; k = getchar())
if (k == '-')
f = -1;
for (; k >= '0' && k <= '9'; k = getchar())
x = x * 10 + k - '0';
return x * f;
}
template <class T> inl T read(T &x) { return x = read<T>(); }
int _num, _buf[20];
template <class T> il print(T x) {
if (x == 0)
return putchar('0'), void();
if (x < 0)
putchar('-'), x = -x;
while (x)
_buf[++_num] = x % 10, x /= 10;
while (_num)
putchar(_buf[_num--] + '0');
}
ll mul(ll a, ll b, ll mod) {
long double c = 1.;
return (a * b - (ll)(c * a * b / mod) * mod) % mod;
}
it qpow(int x, int m, int mod) {
int res = 1, bas = x;
while (m) {
if (m & 1)
res = (1ll * res * bas) % mod;
bas = (1ll * bas * bas) % mod, m >>= 1;
}
return res;
}
const int N = 2e5 + 5;
int n, sum, num[2], val[N], ans[N], popc[N], bit[N][2];
char s[N];
int main() {
// freopen( ".in", "r", stdin ) ;
// freopen( ".out", "w", stdout ) ;
n = read<int>(), scanf("%s", s + 1);
for (ri i = 1; i <= n; ++i) {
val[i] = s[i] - '0';
sum += val[i], popc[i] = popc[i - lowbit(i)] + 1;
}
bit[0][0] = bit[0][1] = 1;
for (ri i = 1; i <= n; ++i) {
num[0] = (num[0] * 2 + val[i]) % (sum + 1);
bit[i][0] = bit[i - 1][0] * 2 % (sum + 1);
if (sum > 1) {
num[1] = (num[1] * 2 + val[i]) % (sum - 1);
bit[i][1] = bit[i - 1][1] * 2 % (sum - 1);
}
}
for (ri i = 1; i <= n; ++i)
ans[i] = ans[i % popc[i]] + 1;
for (ri i = 1; i <= n; ++i) {
if (val[i] == 1) {
int tmp = (num[1] + sum - 1 - bit[n - i][1]) % (sum - 1);
print(ans[tmp] + 1), puts("");
} else {
int tmp = (num[0] + bit[n - i][0]) % (sum + 1);
print(ans[tmp] + 1), puts("");
}
}
cerr << 1. * clock() / CLOCKS_PER_SEC << "\n";
return 0;
} | #include <bits/stdc++.h>
#define del(a, i) memset(a, i, sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l + r) >> 1)
#define lowbit(x) (x & (-x))
#define INF 0x3f3f3f3f
using namespace std;
template <class T> inl T read() {
T x = 0;
int f = 1;
char k = getchar();
for (; k > '9' || k < '0'; k = getchar())
if (k == '-')
f = -1;
for (; k >= '0' && k <= '9'; k = getchar())
x = x * 10 + k - '0';
return x * f;
}
template <class T> inl T read(T &x) { return x = read<T>(); }
int _num, _buf[20];
template <class T> il print(T x) {
if (x == 0)
return putchar('0'), void();
if (x < 0)
putchar('-'), x = -x;
while (x)
_buf[++_num] = x % 10, x /= 10;
while (_num)
putchar(_buf[_num--] + '0');
}
ll mul(ll a, ll b, ll mod) {
long double c = 1.;
return (a * b - (ll)(c * a * b / mod) * mod) % mod;
}
it qpow(int x, int m, int mod) {
int res = 1, bas = x;
while (m) {
if (m & 1)
res = (1ll * res * bas) % mod;
bas = (1ll * bas * bas) % mod, m >>= 1;
}
return res;
}
const int N = 2e5 + 5;
int n, sum, num[2], val[N], ans[N], popc[N], bit[N][2];
char s[N];
int main() {
// freopen( ".in", "r", stdin ) ;
// freopen( ".out", "w", stdout ) ;
n = read<int>(), scanf("%s", s + 1);
for (ri i = 1; i <= n; ++i) {
val[i] = s[i] - '0';
sum += val[i], popc[i] = popc[i - lowbit(i)] + 1;
}
bit[0][0] = bit[0][1] = 1;
for (ri i = 1; i <= n; ++i) {
num[0] = (num[0] * 2 + val[i]) % (sum + 1);
bit[i][0] = bit[i - 1][0] * 2 % (sum + 1);
if (sum > 1) {
num[1] = (num[1] * 2 + val[i]) % (sum - 1);
bit[i][1] = bit[i - 1][1] * 2 % (sum - 1);
}
}
for (ri i = 1; i <= n; ++i)
ans[i] = ans[i % popc[i]] + 1;
for (ri i = 1; i <= n; ++i) {
if (val[i] == 1) {
if (sum == 1) {
puts("0");
continue;
}
int tmp = (num[1] + sum - 1 - bit[n - i][1]) % (sum - 1);
print(ans[tmp] + 1), puts("");
} else {
int tmp = (num[0] + bit[n - i][0]) % (sum + 1);
print(ans[tmp] + 1), puts("");
}
}
cerr << 1. * clock() / CLOCKS_PER_SEC << "\n";
return 0;
} | insert | 74 | 74 | 74 | 78 | 0 | 0.023342
|
p02609 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
using lint = long long;
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif
struct init {
init() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} init_;
inline int popcount(lint n) {
n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
return n;
}
int main() {
lint N;
string X;
cin >> N >> X;
lint cnt = 0;
for (int i = 0; i < N; i++) {
if (X[i] - '0')
cnt++;
}
DMP(X, cnt);
if (cnt == 0) {
for (int i = 0; i < N; i++) {
cout << 1 << "\n";
}
return 0;
}
vector<lint> remp(N), remm(N);
lint rp = 1, rm = 1;
for (int i = 0; i < N; i++) {
remp[i] = rp;
remm[i] = rm;
rp <<= 1;
rm <<= 1;
rp %= cnt + 1;
rm %= cnt - 1;
}
DMP(remp, remm);
lint sump = 0, summ = 0;
reverse(remp.begin(), remp.end());
reverse(remm.begin(), remm.end());
for (int i = 0; i < N; i++) {
if (X[i] - '0')
(sump += remp[i]) %= cnt + 1;
if (X[i] - '0' && cnt != 1)
(summ += remm[i]) %= cnt - 1;
}
DMP(summ, sump);
vector<lint> st(N);
for (int i = 0; i < N; i++) {
if (X[i] - '0') {
if (cnt == 1) {
st[i] = -1;
continue;
}
st[i] = summ;
st[i] -= remm[i];
st[i] += cnt - 1;
st[i] %= cnt - 1;
} else {
st[i] = sump;
st[i] += remp[i];
st[i] %= cnt + 1;
}
}
for (int i = 0; i < N; i++) {
if (st[i] < 0) {
cout << 0 << "\n";
continue;
}
int ans = 1;
while (st[i]) {
int p = popcount(st[i]);
if (p == 0)
break;
st[i] %= p;
ans++;
}
cout << ans << "\n";
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
using lint = long long;
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif
struct init {
init() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} init_;
inline int popcount(lint n) {
n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
return n;
}
int main() {
lint N;
string X;
cin >> N >> X;
lint cnt = 0;
for (int i = 0; i < N; i++) {
if (X[i] - '0')
cnt++;
}
DMP(X, cnt);
if (cnt == 0) {
for (int i = 0; i < N; i++) {
cout << 1 << "\n";
}
return 0;
}
vector<lint> remp(N), remm(N);
lint rp = 1, rm = 1;
for (int i = 0; i < N; i++) {
remp[i] = rp;
remm[i] = rm;
rp <<= 1;
rm <<= 1;
rp %= cnt + 1;
if (cnt != 1)
rm %= cnt - 1;
}
DMP(remp, remm);
lint sump = 0, summ = 0;
reverse(remp.begin(), remp.end());
reverse(remm.begin(), remm.end());
for (int i = 0; i < N; i++) {
if (X[i] - '0')
(sump += remp[i]) %= cnt + 1;
if (X[i] - '0' && cnt != 1)
(summ += remm[i]) %= cnt - 1;
}
DMP(summ, sump);
vector<lint> st(N);
for (int i = 0; i < N; i++) {
if (X[i] - '0') {
if (cnt == 1) {
st[i] = -1;
continue;
}
st[i] = summ;
st[i] -= remm[i];
st[i] += cnt - 1;
st[i] %= cnt - 1;
} else {
st[i] = sump;
st[i] += remp[i];
st[i] %= cnt + 1;
}
}
for (int i = 0; i < N; i++) {
if (st[i] < 0) {
cout << 0 << "\n";
continue;
}
int ans = 1;
while (st[i]) {
int p = popcount(st[i]);
if (p == 0)
break;
st[i] %= p;
ans++;
}
cout << ans << "\n";
}
return 0;
}
| replace | 69 | 70 | 69 | 71 | 0 | |
p02609 | C++ | Runtime Error | const int LG = 21;
const int N = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
#define forn(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) \
sort(all(x)); \
(x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
ll inq(ll x, ll y) {
if (!y)
re 1 % MOD;
ll l = inq(x, y / 2);
if (y % 2)
re l *l % MOD *x % MOD;
re l *l % MOD;
}
ll rev(ll x) { return inq(x, MOD - 2); }
bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;
void __precompute_combinatorics() {
__precomputed_combinatorics = 1;
__fact.resize(N);
__ufact.resize(N);
__rev.resize(N);
__rev[1] = 1;
for (int i = 2; i < N; i++)
__rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
__fact[0] = 1, __ufact[0] = 1;
for (int i = 1; i < N; i++)
__fact[i] = __fact[i - 1] * i % MOD,
__ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}
ll fact(int x) {
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[x];
}
ll cnk(int n, int k) {
if (k < 0 || k > n)
return 0;
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}
int Root(int x, vector<int> &root) {
if (x == root[x])
return x;
return root[x] = Root(root[x], root);
}
void Merge(int v, int u, vector<int> &root, vector<int> &sz) {
v = Root(v, root), u = Root(u, root);
if (v == u)
return;
if (sz[v] < sz[u]) {
sz[u] += sz[v];
root[v] = u;
} else {
sz[v] += sz[u];
root[u] = v;
}
}
int ok(int x, int n) { return 0 <= x && x < n; }
void bfs(int v, vi &dist, vector<vi> &graph) {
fill(all(dist), -1);
dist[v] = 0;
vi q = {v};
for (int i = 0; i < q.size(); i++) {
for (auto u : graph[q[i]]) {
if (dist[u] == -1) {
dist[u] = dist[q[i]] + 1;
q.push_back(u);
}
}
}
}
vector<int> z_func(string &s) {
vector<int> z(s.size());
z[0] = s.size();
int L = 0, R = 0;
for (int i = 1; i < s.size(); i++) {
z[i] = max(0, min(z[i - L], R - i));
while (i + z[i] < s.size() && s[i + z[i]] == s[z[i]])
z[i]++;
if (i + z[i] > R) {
R = i + z[i];
L = i;
}
}
return z;
}
vector<int> p_func(string &s) {
vector<int> p(s.size());
for (int i = 1; i < s.size(); i++) {
int j = p[i - 1];
while (j > 0 && s[i] != s[j])
j = p[j - 1];
if (s[i] == s[j])
j++;
p[i] = j;
}
return p;
}
vector<int> d1_func(string &s) {
vector<int> d1(s.size());
int L = 0, R = -1;
for (int i = 0; i < s.size(); i++) {
int k = 0;
if (i <= R)
k = min(R - i + 1, d1[R - i + L]);
while (i + k < s.size() && i - k >= 0 && s[i - k] == s[i + k])
k++;
d1[i] = k--;
if (i + k > R) {
L = i - k;
R = i + k;
}
}
return d1;
}
vector<int> d2_func(string &s) {
vector<int> d2(s.size());
int L = 0, R = -1;
for (int i = 1; i < s.size(); i++) {
int k = 0;
if (i <= R)
k = min(R - i + 1, d2[R - i + L + 1]);
while (i + k < s.size() && i - k - 1 >= 0 && s[i - k - 1] == s[i + k])
k++;
d2[i] = k--;
if (i + k > R) {
L = i - k - 1;
R = i + k;
}
}
return d2;
}
ll log10(ll x) {
if (x < 10)
re 1;
re 1 + log10(x / 10);
}
ll ds(ll x) {
if (x < 10)
return x;
re x % 10 + ds(x / 10);
}
double sqr(double x) { return x * x; }
bool in(int bit, int mask) { return (mask & (1 << bit)) > 0; }
void Del(vector<int> &v, int pos) {
swap(v[pos], v[v.size() - 1]);
v.pop_back();
}
long long g(vector<long long> &p, int pos) {
if (ok(pos, p.size()))
return p[pos];
if (pos < 0 || p.size() == 0)
return 0;
return p.back();
}
int g(vector<int> &p, int pos) {
if (ok(pos, p.size()))
return p[pos];
if (pos < 0 || p.size() == 0)
return 0;
return p.back();
}
long long inq(long long x, long long y, long long mod) {
if (y == 0)
return 1;
long long l = inq(x, y / 2, mod);
if (y % 2)
return l * l % mod * x % mod;
return l * l % mod;
}
signed main() {
srand(time(NULL));
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
string s;
cin >> n >> s;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
cnt++;
}
int mod1 = cnt - 1;
int mod2 = cnt + 1;
int r1 = 0;
int r2 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
r1 = (r1 + inq(2, n - i - 1, mod1)) % mod1;
r2 = (r2 + inq(2, n - i - 1, mod2)) % mod2;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
r1 = ((r1 - inq(2, n - i - 1, mod1)) % mod1 + mod1) % mod1;
int x = r1;
int cnt = 1;
while (x != 0) {
x = x % popcount(x);
cnt++;
}
cout << cnt << "\n";
r1 = ((r1 + inq(2, n - i - 1, mod1)) % mod1 + mod1) % mod1;
} else {
r2 = ((r2 + inq(2, n - i - 1, mod2)) % mod2 + mod2) % mod2;
int x = r2;
int cnt = 1;
while (x != 0) {
x = x % popcount(x);
cnt++;
}
cout << cnt << "\n";
r2 = ((r2 - inq(2, n - i - 1, mod2)) % mod2 + mod2) % mod2;
}
}
}
/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Setting N in every problem is more effective.
Check corner cases.
N = 1
No def int long long for now.
Add something here.
*/
| const int LG = 21;
const int N = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
#define forn(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) \
sort(all(x)); \
(x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
ll inq(ll x, ll y) {
if (!y)
re 1 % MOD;
ll l = inq(x, y / 2);
if (y % 2)
re l *l % MOD *x % MOD;
re l *l % MOD;
}
ll rev(ll x) { return inq(x, MOD - 2); }
bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;
void __precompute_combinatorics() {
__precomputed_combinatorics = 1;
__fact.resize(N);
__ufact.resize(N);
__rev.resize(N);
__rev[1] = 1;
for (int i = 2; i < N; i++)
__rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
__fact[0] = 1, __ufact[0] = 1;
for (int i = 1; i < N; i++)
__fact[i] = __fact[i - 1] * i % MOD,
__ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}
ll fact(int x) {
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[x];
}
ll cnk(int n, int k) {
if (k < 0 || k > n)
return 0;
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}
int Root(int x, vector<int> &root) {
if (x == root[x])
return x;
return root[x] = Root(root[x], root);
}
void Merge(int v, int u, vector<int> &root, vector<int> &sz) {
v = Root(v, root), u = Root(u, root);
if (v == u)
return;
if (sz[v] < sz[u]) {
sz[u] += sz[v];
root[v] = u;
} else {
sz[v] += sz[u];
root[u] = v;
}
}
int ok(int x, int n) { return 0 <= x && x < n; }
void bfs(int v, vi &dist, vector<vi> &graph) {
fill(all(dist), -1);
dist[v] = 0;
vi q = {v};
for (int i = 0; i < q.size(); i++) {
for (auto u : graph[q[i]]) {
if (dist[u] == -1) {
dist[u] = dist[q[i]] + 1;
q.push_back(u);
}
}
}
}
vector<int> z_func(string &s) {
vector<int> z(s.size());
z[0] = s.size();
int L = 0, R = 0;
for (int i = 1; i < s.size(); i++) {
z[i] = max(0, min(z[i - L], R - i));
while (i + z[i] < s.size() && s[i + z[i]] == s[z[i]])
z[i]++;
if (i + z[i] > R) {
R = i + z[i];
L = i;
}
}
return z;
}
vector<int> p_func(string &s) {
vector<int> p(s.size());
for (int i = 1; i < s.size(); i++) {
int j = p[i - 1];
while (j > 0 && s[i] != s[j])
j = p[j - 1];
if (s[i] == s[j])
j++;
p[i] = j;
}
return p;
}
vector<int> d1_func(string &s) {
vector<int> d1(s.size());
int L = 0, R = -1;
for (int i = 0; i < s.size(); i++) {
int k = 0;
if (i <= R)
k = min(R - i + 1, d1[R - i + L]);
while (i + k < s.size() && i - k >= 0 && s[i - k] == s[i + k])
k++;
d1[i] = k--;
if (i + k > R) {
L = i - k;
R = i + k;
}
}
return d1;
}
vector<int> d2_func(string &s) {
vector<int> d2(s.size());
int L = 0, R = -1;
for (int i = 1; i < s.size(); i++) {
int k = 0;
if (i <= R)
k = min(R - i + 1, d2[R - i + L + 1]);
while (i + k < s.size() && i - k - 1 >= 0 && s[i - k - 1] == s[i + k])
k++;
d2[i] = k--;
if (i + k > R) {
L = i - k - 1;
R = i + k;
}
}
return d2;
}
ll log10(ll x) {
if (x < 10)
re 1;
re 1 + log10(x / 10);
}
ll ds(ll x) {
if (x < 10)
return x;
re x % 10 + ds(x / 10);
}
double sqr(double x) { return x * x; }
bool in(int bit, int mask) { return (mask & (1 << bit)) > 0; }
void Del(vector<int> &v, int pos) {
swap(v[pos], v[v.size() - 1]);
v.pop_back();
}
long long g(vector<long long> &p, int pos) {
if (ok(pos, p.size()))
return p[pos];
if (pos < 0 || p.size() == 0)
return 0;
return p.back();
}
int g(vector<int> &p, int pos) {
if (ok(pos, p.size()))
return p[pos];
if (pos < 0 || p.size() == 0)
return 0;
return p.back();
}
long long inq(long long x, long long y, long long mod) {
if (y == 0)
return 1;
long long l = inq(x, y / 2, mod);
if (y % 2)
return l * l % mod * x % mod;
return l * l % mod;
}
signed main() {
srand(time(NULL));
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
string s;
cin >> n >> s;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
cnt++;
}
if (cnt == 0) {
for (int i = 0; i < n; i++) {
cout << 1 << "\n";
}
return 0;
}
if (cnt == 1) {
int mod2 = cnt + 1;
int r2 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
r2 = (r2 + inq(2, n - i - 1, mod2)) % mod2;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
cout << 0 << "\n";
} else {
r2 = ((r2 + inq(2, n - i - 1, mod2)) % mod2 + mod2) % mod2;
int x = r2;
int cnt = 1;
while (x != 0) {
x = x % popcount(x);
cnt++;
}
cout << cnt << "\n";
r2 = ((r2 - inq(2, n - i - 1, mod2)) % mod2 + mod2) % mod2;
}
}
return 0;
}
int mod1 = cnt - 1;
int mod2 = cnt + 1;
int r1 = 0;
int r2 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
r1 = (r1 + inq(2, n - i - 1, mod1)) % mod1;
r2 = (r2 + inq(2, n - i - 1, mod2)) % mod2;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
r1 = ((r1 - inq(2, n - i - 1, mod1)) % mod1 + mod1) % mod1;
int x = r1;
int cnt = 1;
while (x != 0) {
x = x % popcount(x);
cnt++;
}
cout << cnt << "\n";
r1 = ((r1 + inq(2, n - i - 1, mod1)) % mod1 + mod1) % mod1;
} else {
r2 = ((r2 + inq(2, n - i - 1, mod2)) % mod2 + mod2) % mod2;
int x = r2;
int cnt = 1;
while (x != 0) {
x = x % popcount(x);
cnt++;
}
cout << cnt << "\n";
r2 = ((r2 - inq(2, n - i - 1, mod2)) % mod2 + mod2) % mod2;
}
}
}
/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Setting N in every problem is more effective.
Check corner cases.
N = 1
No def int long long for now.
Add something here.
*/
| insert | 244 | 244 | 244 | 275 | 0 | |
p02610 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
#define ten(n) ((int)1e##n)
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <typename...> static inline int getchar_unlocked(void) {
return getchar();
}
template <typename...> static inline void putchar_unlocked(int c) {
putchar(c);
}
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = k - '0';
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
if (m)
x = -x;
}
void reader(ll &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = k - '0';
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
if (m)
x = -x;
}
int reader(char c[]) {
int i, s = 0;
for (;;) {
mygc(i);
if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF)
break;
}
c[s++] = i;
for (;;) {
mygc(i);
if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF)
break;
c[s++] = i;
}
c[s] = '\0';
return s;
}
int reader(string &c) {
int i;
for (;;) {
mygc(i);
if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF)
break;
}
c.push_back(i);
for (;;) {
mygc(i);
if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF)
break;
c.push_back(i);
};
return sz(c);
}
template <class T, class S> void reader(T &x, S &y) {
reader(x);
reader(y);
}
template <class T, class S, class U> void reader(T &x, S &y, U &z) {
reader(x);
reader(y);
reader(z);
}
template <class T, class S, class U, class V>
void reader(T &x, S &y, U &z, V &w) {
reader(x);
reader(y);
reader(z);
reader(w);
}
void writer(int x, char c) {
int s = 0, m = 0;
char f[10];
if (x < 0)
m = 1, x = -x;
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
void writer(ll x, char c) {
int s = 0, m = 0;
char f[20];
if (x < 0)
m = 1, x = -x;
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
void writer(const char c[]) {
int i;
for (i = 0; c[i] != '\0'; i++)
mypc(c[i]);
}
void writer(const string &x, char c) {
int i;
for (i = 0; x[i] != '\0'; i++)
mypc(x[i]);
mypc(c);
}
void writer(const char x[], char c) {
int i;
for (i = 0; x[i] != '\0'; i++)
mypc(x[i]);
mypc(c);
}
template <class T> void writerLn(T x) { writer(x, '\n'); }
template <class T, class S> void writerLn(T x, S y) {
writer(x, ' ');
writer(y, '\n');
}
template <class T, class S, class U> void writerLn(T x, S y, U z) {
writer(x, ' ');
writer(y, ' ');
writer(z, '\n');
}
template <class T, class S, class U, class V>
void writerLn(T x, S y, U z, V v) {
writer(x, ' ');
writer(y, ' ');
writer(z, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
if (!n) {
mypc('\n');
return;
}
FOR(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerArr(vector<T> &x) {
writerArr(x.data(), (int)x.size());
}
void reader(ull &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = ull(k - '0');
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
}
void writer(ull x, char c) {
int s = 0, m = 0;
char f[20];
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
template <class T> vector<T> readerArray(int n) {
vector<T> ret(n);
for (int i = 0; i < n; i++)
reader(ret[i]);
return ret;
}
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll mod_pow(ll a, ll n, ll mod) {
ll ret = 1;
ll p = a % mod;
while (n) {
if (n & 1)
ret = ret * p % mod;
p = p * p % mod;
n >>= 1;
}
return ret;
}
template <class T> T extgcd(T a, T b, T &x, T &y) {
for (T u = y = 1, v = x = 0; a;) {
T q = b / a;
swap(x -= q * u, u);
swap(y -= q * v, v);
swap(b -= q * a, a);
}
return b;
}
ll mod_inv(ll a, ll m) {
ll x, y;
extgcd<ll>(a, m, x, y);
return (m + x % m) % m;
}
#ifdef _MSC_VER
// #ifdef _DEBUG
template <typename... Args>
void debugPrintf(const char *format, Args const &...args) {
fprintf(stderr, format, args...);
fflush(stderr);
}
#else
#define debugPrintf(...)
#endif
using P = pair<int, ll>;
ll f(vector<P> &vp) {
int n = sz(vp);
sort(vp.begin(), vp.end(),
[](const P &l, const P &r) { return l.second > r.second; });
set<int> st;
FOR(i, n) st.insert(i + 1);
ll ret = 0;
for (auto &kv : vp) {
int k;
ll v;
tie(k, v) = kv;
if (k > n) {
ret += v;
continue;
}
auto it = st.lower_bound(k);
if (*it > k) {
if (it == st.begin())
continue;
it--;
}
st.erase(it);
ret += v;
}
return ret;
}
void solve() {
int n;
reader(n);
vector<P> up, down;
ll sm = 0;
FOR(i, n) {
int k;
ll l, r;
reader(k, l, r);
if (k == n || l == r) {
sm += l;
continue;
}
ll diff;
if (l < r) {
sm += l;
diff = r - l;
down.push_back(P{n - k, diff});
} else {
sm += r;
diff = l - r;
up.push_back(P{k, diff});
}
}
ll a1 = f(up);
ll a2 = f(down);
ll ans = sm + a1 + a2;
writerLn(ans);
}
int main() {
int t;
reader(t);
while (t--) {
solve();
}
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())
#define ten(n) ((int)1e##n)
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <typename...> static inline int getchar_unlocked(void) {
return getchar();
}
template <typename...> static inline void putchar_unlocked(int c) {
putchar(c);
}
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = k - '0';
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
if (m)
x = -x;
}
void reader(ll &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = k - '0';
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
if (m)
x = -x;
}
int reader(char c[]) {
int i, s = 0;
for (;;) {
mygc(i);
if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF)
break;
}
c[s++] = i;
for (;;) {
mygc(i);
if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF)
break;
c[s++] = i;
}
c[s] = '\0';
return s;
}
int reader(string &c) {
int i;
for (;;) {
mygc(i);
if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF)
break;
}
c.push_back(i);
for (;;) {
mygc(i);
if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF)
break;
c.push_back(i);
};
return sz(c);
}
template <class T, class S> void reader(T &x, S &y) {
reader(x);
reader(y);
}
template <class T, class S, class U> void reader(T &x, S &y, U &z) {
reader(x);
reader(y);
reader(z);
}
template <class T, class S, class U, class V>
void reader(T &x, S &y, U &z, V &w) {
reader(x);
reader(y);
reader(z);
reader(w);
}
void writer(int x, char c) {
int s = 0, m = 0;
char f[10];
if (x < 0)
m = 1, x = -x;
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
void writer(ll x, char c) {
int s = 0, m = 0;
char f[20];
if (x < 0)
m = 1, x = -x;
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
void writer(const char c[]) {
int i;
for (i = 0; c[i] != '\0'; i++)
mypc(c[i]);
}
void writer(const string &x, char c) {
int i;
for (i = 0; x[i] != '\0'; i++)
mypc(x[i]);
mypc(c);
}
void writer(const char x[], char c) {
int i;
for (i = 0; x[i] != '\0'; i++)
mypc(x[i]);
mypc(c);
}
template <class T> void writerLn(T x) { writer(x, '\n'); }
template <class T, class S> void writerLn(T x, S y) {
writer(x, ' ');
writer(y, '\n');
}
template <class T, class S, class U> void writerLn(T x, S y, U z) {
writer(x, ' ');
writer(y, ' ');
writer(z, '\n');
}
template <class T, class S, class U, class V>
void writerLn(T x, S y, U z, V v) {
writer(x, ' ');
writer(y, ' ');
writer(z, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
if (!n) {
mypc('\n');
return;
}
FOR(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerArr(vector<T> &x) {
writerArr(x.data(), (int)x.size());
}
void reader(ull &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = ull(k - '0');
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
}
void writer(ull x, char c) {
int s = 0, m = 0;
char f[20];
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
template <class T> vector<T> readerArray(int n) {
vector<T> ret(n);
for (int i = 0; i < n; i++)
reader(ret[i]);
return ret;
}
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll mod_pow(ll a, ll n, ll mod) {
ll ret = 1;
ll p = a % mod;
while (n) {
if (n & 1)
ret = ret * p % mod;
p = p * p % mod;
n >>= 1;
}
return ret;
}
template <class T> T extgcd(T a, T b, T &x, T &y) {
for (T u = y = 1, v = x = 0; a;) {
T q = b / a;
swap(x -= q * u, u);
swap(y -= q * v, v);
swap(b -= q * a, a);
}
return b;
}
ll mod_inv(ll a, ll m) {
ll x, y;
extgcd<ll>(a, m, x, y);
return (m + x % m) % m;
}
#ifdef _MSC_VER
// #ifdef _DEBUG
template <typename... Args>
void debugPrintf(const char *format, Args const &...args) {
fprintf(stderr, format, args...);
fflush(stderr);
}
#else
#define debugPrintf(...)
#endif
using P = pair<int, ll>;
ll f(vector<P> &vp) {
int n = sz(vp);
sort(vp.begin(), vp.end(),
[](const P &l, const P &r) { return l.second > r.second; });
set<int> st;
FOR(i, n) st.insert(i + 1);
ll ret = 0;
for (auto &kv : vp) {
int k;
ll v;
tie(k, v) = kv;
if (k >= n) {
ret += v;
continue;
}
auto it = st.lower_bound(k);
if (*it > k) {
if (it == st.begin())
continue;
it--;
}
st.erase(it);
ret += v;
}
return ret;
}
void solve() {
int n;
reader(n);
vector<P> up, down;
ll sm = 0;
FOR(i, n) {
int k;
ll l, r;
reader(k, l, r);
if (k == n || l == r) {
sm += l;
continue;
}
ll diff;
if (l < r) {
sm += l;
diff = r - l;
down.push_back(P{n - k, diff});
} else {
sm += r;
diff = l - r;
up.push_back(P{k, diff});
}
}
ll a1 = f(up);
ll a2 = f(down);
ll ans = sm + a1 + a2;
writerLn(ans);
}
int main() {
int t;
reader(t);
while (t--) {
solve();
}
return 0;
}
| replace | 316 | 317 | 316 | 317 | -6 | free(): invalid pointer
|
p02610 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n) \
for (int vari = 0; vari < (n)-1; ++vari) \
for (int varj = vari + 1; varj < (n); ++varj)
#define repC3(vari, varj, vark, n) \
for (int vari = 0; vari < (n)-2; ++vari) \
for (int varj = vari + 1; varj < (n)-1; ++varj) \
for (int vark = varj + 1; vark < (n); ++vark)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair
#define clamp(v, lo, hi) min(max(v, lo), hi)
#define ABS(x) max((x), -(x))
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) {
if (a < b)
a = b;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
while (a)
swap(a, b %= a);
return b;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; }
template <typename T> int find_left(vector<T> &v, T elem) {
return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1;
}
template <typename T> int find_right(vector<T> &v, T elem) {
return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin());
}
const ll MOD = 1000000007LL;
inline ll ADD(ll x, ll y) { return (x + y) % MOD; }
inline ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; }
inline ll MUL(ll x, ll y) { return x * y % MOD; }
inline ll POW(ll x, ll e) {
ll v = 1;
for (; e; x = MUL(x, x), e >>= 1)
if (e & 1)
v = MUL(v, x);
return v;
}
inline ll INV(ll y) { /*assert(y%MOD!=0);*/
return POW(y, MOD - 2);
}
inline ll DIV(ll x, ll y) { return MUL(x, INV(y)); }
#define INTSPACE 12
char _buf[INTSPACE * 1000000 + 3];
int loadint() {
if (fgets(_buf, INTSPACE + 3, stdin) == NULL)
return 0;
return atoi(_buf);
}
int loadvec(vector<int> &v, int N = -1) {
if (N == 0) {
v.clear();
return 0;
}
if (N == -1) {
N = loadint();
if (N == 0)
return 0;
}
int bufsize = INTSPACE * N + 3;
if (fgets(_buf, bufsize, stdin) == NULL)
return 0;
v.resize(N);
int i = 0;
bool last = false;
for (char *p = &_buf[0];;) {
char *q = p;
while (*q > ' ')
++q;
if (*q == 0x0D || *q == 0x0A)
last = true;
*q = 0;
v[i++] = atoi(p);
if (last || i == N)
break;
p = q + 1;
}
return i;
}
void read_cr() { fgets(_buf, 256, stdin); }
void horizontal(vector<int> &v) {
int L = v.size();
for (int i = 0; i < L; ++i) {
printf("%d%c", v[i], (i == L - 1) ? '\n' : ' ');
}
}
void horizontall(vector<long long> &v) {
int L = v.size();
for (int i = 0; i < L; ++i) {
printf("%lld%c", v[i], (i == L - 1) ? '\n' : ' ');
}
}
ll sub(vii &a) {
ll totalpen = 0;
sort(ALL(a));
int L = a.size();
PQ(int) pq;
int ent = 0;
for (int i = 0, j = 0; i < L; ++i) {
while (j < L && a[j].first <= 1 + i) {
pq.push(a[j].second);
++j;
++ent;
}
while (ent > 1 + i) {
totalpen += pq.top();
pq.pop();
}
}
return totalpen;
}
ll solve(int N, vi &k, vi &l, vi &r) {
ll score = 0;
vii left, right;
rep(i, N) {
if (k[i] == N || l[i] == r[i]) {
score += l[i];
continue;
}
if (l[i] > r[i]) {
left.eb(k[i], l[i] - r[i]);
score += l[i];
} else {
right.eb(N - k[i], r[i] - l[i]);
score += r[i];
}
}
return score - sub(left) - sub(right);
}
int main() {
int T;
scanf("%d%*c", &T);
rep(t, T) {
int N;
scanf("%d%*c", &N);
vi k(N), l(N), r(N);
rep(i, N) { scanf("%d %d %d%*c", &k[i], &l[i], &r[i]); }
ll ans = solve(N, k, l, r);
printf("%lld\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n) \
for (int vari = 0; vari < (n)-1; ++vari) \
for (int varj = vari + 1; varj < (n); ++varj)
#define repC3(vari, varj, vark, n) \
for (int vari = 0; vari < (n)-2; ++vari) \
for (int varj = vari + 1; varj < (n)-1; ++varj) \
for (int vark = varj + 1; vark < (n); ++vark)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair
#define clamp(v, lo, hi) min(max(v, lo), hi)
#define ABS(x) max((x), -(x))
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) {
if (a < b)
a = b;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
while (a)
swap(a, b %= a);
return b;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; }
template <typename T> int find_left(vector<T> &v, T elem) {
return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1;
}
template <typename T> int find_right(vector<T> &v, T elem) {
return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin());
}
const ll MOD = 1000000007LL;
inline ll ADD(ll x, ll y) { return (x + y) % MOD; }
inline ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; }
inline ll MUL(ll x, ll y) { return x * y % MOD; }
inline ll POW(ll x, ll e) {
ll v = 1;
for (; e; x = MUL(x, x), e >>= 1)
if (e & 1)
v = MUL(v, x);
return v;
}
inline ll INV(ll y) { /*assert(y%MOD!=0);*/
return POW(y, MOD - 2);
}
inline ll DIV(ll x, ll y) { return MUL(x, INV(y)); }
#define INTSPACE 12
char _buf[INTSPACE * 1000000 + 3];
int loadint() {
if (fgets(_buf, INTSPACE + 3, stdin) == NULL)
return 0;
return atoi(_buf);
}
int loadvec(vector<int> &v, int N = -1) {
if (N == 0) {
v.clear();
return 0;
}
if (N == -1) {
N = loadint();
if (N == 0)
return 0;
}
int bufsize = INTSPACE * N + 3;
if (fgets(_buf, bufsize, stdin) == NULL)
return 0;
v.resize(N);
int i = 0;
bool last = false;
for (char *p = &_buf[0];;) {
char *q = p;
while (*q > ' ')
++q;
if (*q == 0x0D || *q == 0x0A)
last = true;
*q = 0;
v[i++] = atoi(p);
if (last || i == N)
break;
p = q + 1;
}
return i;
}
void read_cr() { fgets(_buf, 256, stdin); }
void horizontal(vector<int> &v) {
int L = v.size();
for (int i = 0; i < L; ++i) {
printf("%d%c", v[i], (i == L - 1) ? '\n' : ' ');
}
}
void horizontall(vector<long long> &v) {
int L = v.size();
for (int i = 0; i < L; ++i) {
printf("%lld%c", v[i], (i == L - 1) ? '\n' : ' ');
}
}
ll sub(vii &a) {
ll totalpen = 0;
sort(ALL(a));
int L = a.size();
PQ(int) pq;
int ent = 0;
for (int i = 0, j = 0; i < L; ++i) {
while (j < L && a[j].first <= 1 + i) {
pq.push(a[j].second);
++j;
++ent;
}
while (ent > 1 + i) {
totalpen += pq.top();
pq.pop();
--ent;
}
}
return totalpen;
}
ll solve(int N, vi &k, vi &l, vi &r) {
ll score = 0;
vii left, right;
rep(i, N) {
if (k[i] == N || l[i] == r[i]) {
score += l[i];
continue;
}
if (l[i] > r[i]) {
left.eb(k[i], l[i] - r[i]);
score += l[i];
} else {
right.eb(N - k[i], r[i] - l[i]);
score += r[i];
}
}
return score - sub(left) - sub(right);
}
int main() {
int T;
scanf("%d%*c", &T);
rep(t, T) {
int N;
scanf("%d%*c", &N);
vi k(N), l(N), r(N);
rep(i, N) { scanf("%d %d %d%*c", &k[i], &l[i], &r[i]); }
ll ans = solve(N, k, l, r);
printf("%lld\n", ans);
}
return 0;
}
| insert | 170 | 170 | 170 | 171 | TLE | |
p02610 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long li;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define df 0
template <class T> void print(const T &t) { cout << t << "\n"; }
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
cout << t;
if (sizeof...(ts))
cout << " ";
print(ts...);
}
li calc(vector<pair<int, li>> &vec) {
int n = vec.size();
rep(i, n) vec[i].first *= -1;
sort(vec.begin(), vec.end());
rep(i, n) vec[i].first *= -1;
li s = 0;
int i = 0, i0 = vec[0].first;
multiset<li> st;
while (i0) {
while (i < n and vec[i].first == i0)
st.insert(-vec[i++].second);
if (st.size()) {
s -= *st.begin();
st.erase(st.begin());
}
i0--;
}
return s;
}
void solve(vector<int> &k, vector<li> &l, vector<li> r) {
int n = k.size();
vector<pair<int, li>> lft, rgt;
li s = 0;
rep(i, n) {
if (r[i] < l[i]) {
lft.push_back({k[i], l[i] - r[i]});
s += r[i];
} else if (l[i] < r[i]) {
rgt.push_back({n - k[i], r[i] - l[i]});
s += l[i];
} else {
s += l[i];
}
}
print(s + calc(rgt) + calc(lft));
}
int main() {
int t;
cin >> t;
rep(_, t) {
int n;
cin >> n;
vector<int> k(n);
vector<li> l(n), r(n);
rep(i, n) { cin >> k[i] >> l[i] >> r[i]; }
solve(k, l, r);
}
}
| #include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long li;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define df 0
template <class T> void print(const T &t) { cout << t << "\n"; }
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
cout << t;
if (sizeof...(ts))
cout << " ";
print(ts...);
}
li calc(vector<pair<int, li>> &vec) {
int n = vec.size();
if (n == 0)
return 0;
rep(i, n) vec[i].first *= -1;
sort(vec.begin(), vec.end());
rep(i, n) vec[i].first *= -1;
li s = 0;
int i = 0, i0 = vec[0].first;
multiset<li> st;
while (i0) {
while (i < n and vec[i].first == i0)
st.insert(-vec[i++].second);
if (st.size()) {
s -= *st.begin();
st.erase(st.begin());
}
i0--;
}
return s;
}
void solve(vector<int> &k, vector<li> &l, vector<li> r) {
int n = k.size();
vector<pair<int, li>> lft, rgt;
li s = 0;
rep(i, n) {
if (r[i] < l[i]) {
lft.push_back({k[i], l[i] - r[i]});
s += r[i];
} else if (l[i] < r[i]) {
rgt.push_back({n - k[i], r[i] - l[i]});
s += l[i];
} else {
s += l[i];
}
}
print(s + calc(rgt) + calc(lft));
}
int main() {
int t;
cin >> t;
rep(_, t) {
int n;
cin >> n;
vector<int> k(n);
vector<li> l(n), r(n);
rep(i, n) { cin >> k[i] >> l[i] >> r[i]; }
solve(k, l, r);
}
}
| insert | 18 | 18 | 18 | 20 | 0 | |
p02610 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int msbp(int x) { return 31 - __builtin_clz(x); }
inline int msb(int x) { return 1 << msbp(x); }
typedef long long ll;
typedef pair<int, int> pii;
// const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f3f;
// const int INF = INT_MAX;
// const int nINF = INT_MIN;
// const ll INF = LLONG_MAX;
// const ll nINF = LLONG_MIN;
/////////////////////////////////////////////////////////////////////
const int N = 2e5 + 10;
int t, n;
ll solve(vector<pii> &v) {
sort(v.begin(), v.end());
ll res = 0;
multiset<int> cur;
for (auto [k, add] : v) {
if (cur.size() < k) {
cur.insert(add);
} else if (add > *cur.begin()) {
cur.erase(cur.begin());
cur.insert(add);
}
}
for (int x : cur)
res += x;
return res;
}
signed main() {
ios::sync_with_stdio(false);
// cout << fixed << setprecision(7);
cin >> t;
while (t--) {
cin >> n;
ll ans = 0;
vector<pii> v1, v2;
REP(i, n) {
int k, l, r;
cin >> k >> l >> r;
ans += min(l, r);
if (l >= r)
v1.push_back({k, l - r});
else
v2.push_back({n - k, r - l});
}
cout << ans + solve(v1) + solve(v2) << endl;
}
return 0;
}
// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!!
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)
// Rare mistakes made in the past:
// - division by 0 (WA)
// - negative arithmetic, ceiling division, modulo (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)
// - forgetting to rename recursive call when copy/pasting recursive function
// (WA)
// - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int msbp(int x) { return 31 - __builtin_clz(x); }
inline int msb(int x) { return 1 << msbp(x); }
typedef long long ll;
typedef pair<int, int> pii;
// const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f3f;
// const int INF = INT_MAX;
// const int nINF = INT_MIN;
// const ll INF = LLONG_MAX;
// const ll nINF = LLONG_MIN;
/////////////////////////////////////////////////////////////////////
const int N = 2e5 + 10;
int t, n;
ll solve(vector<pii> &v) {
sort(v.begin(), v.end());
ll res = 0;
multiset<int> cur;
for (auto [k, add] : v) {
if (cur.size() < k) {
cur.insert(add);
} else if (add > *cur.begin()) {
cur.erase(cur.begin());
cur.insert(add);
}
}
for (int x : cur)
res += x;
return res;
}
signed main() {
ios::sync_with_stdio(false);
// cout << fixed << setprecision(7);
cin >> t;
while (t--) {
cin >> n;
ll ans = 0;
vector<pii> v1, v2;
REP(i, n) {
int k, l, r;
cin >> k >> l >> r;
if (k == n) {
ans += l;
continue;
}
ans += min(l, r);
if (l >= r)
v1.push_back({k, l - r});
else
v2.push_back({n - k, r - l});
}
cout << ans + solve(v1) + solve(v2) << endl;
}
return 0;
}
// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!!
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)
// Rare mistakes made in the past:
// - division by 0 (WA)
// - negative arithmetic, ceiling division, modulo (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)
// - forgetting to rename recursive call when copy/pasting recursive function
// (WA)
// - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)
| insert | 53 | 53 | 53 | 57 | TLE | |
p02610 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 1e5 + 10;
vector<pair<int, int>> adj[mxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
adj[i].clear();
vector<pair<int, pair<int, int>>> camels;
for (int i = 0; i < n; i++) {
int k, l, r;
pair<int, pair<int, int>> tmp;
cin >> k >> l >> r;
tmp.first = k;
tmp.second = {l, r};
camels.push_back(tmp);
}
for (auto x : camels)
if (x.second.first >= x.second.second)
adj[x.first].push_back(x.second);
multiset<int> Set;
ll added = 0ll;
for (int i = 1; i <= n; i++) {
for (auto x : adj[i]) {
Set.insert(x.first - x.second);
assert(x.first - x.second >= 0);
added += 1ll * (x.first - x.second);
}
while (i < (int)Set.size()) {
added -= 1ll * (*Set.begin());
Set.erase(Set.begin());
}
}
// cout << "added is " << added << '\n';
for (int i = 1; i <= n; i++)
adj[i].clear();
for (auto x : camels)
if (x.second.first < x.second.second)
adj[x.first + 1].push_back(x.second);
Set.clear();
ll addedmore = 0ll;
for (int i = n + 1; i >= 2; i--) {
for (auto x : adj[i]) {
Set.insert(x.second - x.first);
assert(x.second - x.first > 0);
addedmore += 1ll * (x.second - x.first);
}
while (n + 1 - i < (int)Set.size()) {
addedmore -= 1ll * (*Set.begin());
Set.erase(Set.begin());
}
}
// cout << "addedmore is " << addedmore << '\n';
ll ans = 0;
for (auto x : camels)
ans += 1ll * min(x.second.first, x.second.second);
// cout << "Original ans = " << ans << '\n';
ans += added;
ans += addedmore;
cout << ans << '\n';
}
return 0;
}
| #include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 2e5 + 20;
vector<pair<int, int>> adj[mxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
adj[i].clear();
vector<pair<int, pair<int, int>>> camels;
for (int i = 0; i < n; i++) {
int k, l, r;
pair<int, pair<int, int>> tmp;
cin >> k >> l >> r;
tmp.first = k;
tmp.second = {l, r};
camels.push_back(tmp);
}
for (auto x : camels)
if (x.second.first >= x.second.second)
adj[x.first].push_back(x.second);
multiset<int> Set;
ll added = 0ll;
for (int i = 1; i <= n; i++) {
for (auto x : adj[i]) {
Set.insert(x.first - x.second);
assert(x.first - x.second >= 0);
added += 1ll * (x.first - x.second);
}
while (i < (int)Set.size()) {
added -= 1ll * (*Set.begin());
Set.erase(Set.begin());
}
}
// cout << "added is " << added << '\n';
for (int i = 1; i <= n; i++)
adj[i].clear();
for (auto x : camels)
if (x.second.first < x.second.second)
adj[x.first + 1].push_back(x.second);
Set.clear();
ll addedmore = 0ll;
for (int i = n + 1; i >= 2; i--) {
for (auto x : adj[i]) {
Set.insert(x.second - x.first);
assert(x.second - x.first > 0);
addedmore += 1ll * (x.second - x.first);
}
while (n + 1 - i < (int)Set.size()) {
addedmore -= 1ll * (*Set.begin());
Set.erase(Set.begin());
}
}
// cout << "addedmore is " << addedmore << '\n';
ll ans = 0;
for (auto x : camels)
ans += 1ll * min(x.second.first, x.second.second);
// cout << "Original ans = " << ans << '\n';
ans += added;
ans += addedmore;
cout << ans << '\n';
}
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02610 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
constexpr int inf = 1e9 + 7;
constexpr ll longinf = 1LL << 60;
constexpr ll mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
ll ans = 0;
vector<pair<int, int>> l, r;
rep(i, n) {
int k, x, y;
cin >> k >> x >> y;
if (x >= y) {
ans += y;
l.emplace_back(x - y, k - 1);
} else {
ans += x;
r.emplace_back(y - x, k - 1);
}
}
set<int> L, R;
rep(i, l.size()) L.insert(i);
rep(i, r.size()) R.insert(i + l.size());
sort(l.rbegin(), l.rend());
sort(r.rbegin(), r.rend());
for (auto e : l) {
auto itr = L.upper_bound(e.second);
if (itr != L.begin()) {
--itr;
ans += e.first;
L.erase(itr);
}
}
for (auto e : r) {
auto itr = R.upper_bound(e.second);
if (itr != R.end()) {
ans += e.first;
L.erase(itr);
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
solve();
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
constexpr int inf = 1e9 + 7;
constexpr ll longinf = 1LL << 60;
constexpr ll mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
ll ans = 0;
vector<pair<int, int>> l, r;
rep(i, n) {
int k, x, y;
cin >> k >> x >> y;
if (x >= y) {
ans += y;
l.emplace_back(x - y, k - 1);
} else {
ans += x;
r.emplace_back(y - x, k - 1);
}
}
set<int> L, R;
rep(i, l.size()) L.insert(i);
rep(i, r.size()) R.insert(i + l.size());
sort(l.rbegin(), l.rend());
sort(r.rbegin(), r.rend());
for (auto e : l) {
auto itr = L.upper_bound(e.second);
if (itr != L.begin()) {
--itr;
ans += e.first;
L.erase(itr);
}
}
for (auto e : r) {
auto itr = R.upper_bound(e.second);
if (itr != R.end()) {
ans += e.first;
R.erase(itr);
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
solve();
return 0;
} | replace | 57 | 58 | 57 | 58 | -6 | free(): double free detected in tcache 2
|
p02610 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct deve {
long long k;
long long l;
long long r;
} deva[200005];
bool us1[200005], us2[200005];
long long n, ans, ki, li, ri;
multiset<pair<long long, int>> prve, zadnje;
bool sort_deve(deve a, deve b) {
if (a.k != b.k)
return a.k < b.k;
return abs(a.l - a.r) > abs(b.l - a.r);
}
void solve() {
cin >> n;
ans = 0;
zadnje.clear();
prve.clear();
for (int i = 0; i < n; i++) {
cin >> ki >> li >> ri;
deva[i].k = ki;
deva[i].l = li;
deva[i].r = ri;
us1[i] = 0;
us2[i] = 0;
}
sort(deva, deva + n, sort_deve);
for (int i = 0; i < n; i++) {
if (deva[i].l > deva[i].r) {
long long razlika = deva[i].l - deva[i].r;
prve.insert(make_pair(razlika, i));
ans += deva[i].l;
us1[n - i - 1] = 1;
if (prve.size() == deva[i].k + 1) {
ans -= deva[(*prve.begin()).second].l;
us1[n - (*prve.begin()).second - 1] = 0;
prve.erase(prve.find(*prve.begin()));
}
}
}
reverse(deva, deva + n);
// cout << "DEVA: " << deva[0].k << " " << deva[0].l << " " << deva[0].r <<
//endl;
for (int i = 0; i < n; i++) {
if (deva[i].r > deva[i].l) {
long long razlika = deva[i].r - deva[i].l;
zadnje.insert(make_pair(razlika, i));
ans += deva[i].r;
us2[i] = 1;
if (zadnje.size() == (n - deva[i].k + 1)) {
ans -= deva[(*zadnje.begin()).second].r;
us2[(*zadnje.begin()).second] = 0;
zadnje.erase(zadnje.find(*zadnje.begin()));
}
}
}
for (int i = 0; i < n; i++)
if (!(us1[i] or us2[i]))
ans += min(deva[i].r, deva[i].l);
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
struct deve {
long long k;
long long l;
long long r;
} deva[200005];
bool us1[200005], us2[200005];
long long n, ans, ki, li, ri;
multiset<pair<long long, int>> prve, zadnje;
bool sort_deve(deve a, deve b) {
if (a.k != b.k)
return a.k < b.k;
return a.l > b.l;
}
void solve() {
cin >> n;
ans = 0;
zadnje.clear();
prve.clear();
for (int i = 0; i < n; i++) {
cin >> ki >> li >> ri;
deva[i].k = ki;
deva[i].l = li;
deva[i].r = ri;
us1[i] = 0;
us2[i] = 0;
}
sort(deva, deva + n, sort_deve);
for (int i = 0; i < n; i++) {
if (deva[i].l > deva[i].r) {
long long razlika = deva[i].l - deva[i].r;
prve.insert(make_pair(razlika, i));
ans += deva[i].l;
us1[n - i - 1] = 1;
if (prve.size() == deva[i].k + 1) {
ans -= deva[(*prve.begin()).second].l;
us1[n - (*prve.begin()).second - 1] = 0;
prve.erase(prve.find(*prve.begin()));
}
}
}
reverse(deva, deva + n);
// cout << "DEVA: " << deva[0].k << " " << deva[0].l << " " << deva[0].r <<
//endl;
for (int i = 0; i < n; i++) {
if (deva[i].r > deva[i].l) {
long long razlika = deva[i].r - deva[i].l;
zadnje.insert(make_pair(razlika, i));
ans += deva[i].r;
us2[i] = 1;
if (zadnje.size() == (n - deva[i].k + 1)) {
ans -= deva[(*zadnje.begin()).second].r;
us2[(*zadnje.begin()).second] = 0;
zadnje.erase(zadnje.find(*zadnje.begin()));
}
}
}
for (int i = 0; i < n; i++)
if (!(us1[i] or us2[i]))
ans += min(deva[i].r, deva[i].l);
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02610 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
// #define T int
class T {
public:
int index;
bool vacant;
T() : index(-1), vacant(false) {}
T(int index) : index(index), vacant(true) {}
T(const T &value) : index(value.index), vacant(value.vacant) {}
T &operator=(const T &value) {
this->index = value.index;
this->vacant = value.vacant;
return *this;
}
};
const T *merge(const T *L, const T *R) {
if (R->vacant) {
return R;
} else {
return L;
}
}
template <size_t W> class SegmentTree;
template <size_t W> class SegmentTreeNode {
private:
const size_t start;
const size_t end;
SegmentTreeNode<(W + 1) / 2> L;
SegmentTreeNode<W / 2> R;
public:
SegmentTreeNode(const std::vector<T> &values, size_t start)
: start(start), end(start + W), L(values, start),
R(values, start + (W + 1) / 2) {
value = merge(L.value, R.value);
}
const T *value;
void print() {
L.print();
R.print();
}
inline void update(size_t index, const T &value) {
if (start <= index && index < end) {
L.update(index, value);
R.update(index, value);
this->value = merge(L.value, R.value);
}
}
inline void update() {
L.update();
R.update();
this->value = merge(L.value, R.value);
}
inline const T *pick(size_t start, size_t end) {
if (start <= this->start && this->end <= end) {
return value;
} else if (this->start<end &&this->end> start) {
auto l = L.pick(start, end);
auto r = R.pick(start, end);
if (l == NULL) {
return r;
} else if (r == NULL) {
return l;
}
return merge(l, r);
} else {
return NULL;
}
}
};
template <> class SegmentTreeNode<1> {
private:
const size_t index;
public:
SegmentTreeNode(const std::vector<T> &values, size_t start)
: index(start), value(&values[start]) {}
const T *value;
void print() { std::cout << index << std::endl; }
inline void update(size_t index, const T &value) {}
inline void update() {}
inline const T *pick(size_t start, size_t end) {
if (start <= this->index && this->index < end) {
return value;
} else {
return NULL;
}
}
};
template <size_t W> class SegmentTree {
private:
std::vector<T> values;
SegmentTreeNode<W> *root;
public:
SegmentTree() : values(W) { root = new SegmentTreeNode<W>(values, 0); }
SegmentTree(const std::vector<T> &values) : values(values) {
root = new SegmentTreeNode<W>(values, 0);
}
SegmentTree(const std::vector<T> &&values) : values(values) {
root = new SegmentTreeNode<W>(values, 0);
}
~SegmentTree() { delete root; }
void print() { root->print(); }
void update(size_t index, const T &&value) {
values[index] = value;
root->update(index, values[index]);
}
void clear(const T &value) {
for (auto i = values.begin(); i != values.end(); i++) {
*i = value;
}
root->update();
}
const T *pick(size_t start, size_t end) { return root->pick(start, end); }
const std::vector<T> &get_values() { return values; }
};
const int MAX = 200000;
class Camel {
public:
long long D, L, R, K;
Camel(long long D, long long L, long long R, long long K)
: D(D), L(L), R(R), K(K) {}
bool operator<(const Camel &value) { return D > value.D; }
};
using namespace std;
// #include "print.cpp"
long long calc(SegmentTree<MAX> &st, vector<Camel> &camels) {
sort(camels.begin(), camels.end());
long long count = camels.size();
st.clear(T());
for (int i = 0; i < count; i++) {
st.update(i, T(i));
}
long long score = 0;
// vector<pair<int, int>> train(count, pair<int, int>(-1, -1));
for (auto &camel : camels) {
if (camel.K > 0) {
auto p = st.pick(0, min(camel.K, count));
// printe(camel.D, camel.L, camel.R, camel.K,
//p->index, p->vacant);
if (p != NULL && p->index >= 0 && p->vacant) {
// train[p->index] = pair<int, int>(camel.L,
//camel.R); printe(st.get_values()[0].vacant);
st.update(p->index, T());
// printe(st.get_values()[0].vacant);
score += camel.L;
} else {
score += camel.R;
}
} else {
score += camel.R;
}
}
// printe(train);
return score;
}
int main(void) {
SegmentTree<MAX> st;
int T;
cin >> T;
for (int i = 0; i < T; i++) {
int N;
cin >> N;
vector<Camel> camels_l;
vector<Camel> camels_r;
for (int j = 0; j < N; j++) {
long long K, L, R;
cin >> K;
cin >> L;
cin >> R;
const long long D = L - R;
if (D >= 0) {
camels_l.push_back(Camel(D, L, R, K));
} else {
camels_r.push_back(Camel(-D, R, L, N - K));
}
}
cout << calc(st, camels_l) + calc(st, camels_r) << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
// #define T int
class T {
public:
int index;
bool vacant;
T() : index(-1), vacant(false) {}
T(int index) : index(index), vacant(true) {}
T(const T &value) : index(value.index), vacant(value.vacant) {}
T &operator=(const T &value) {
this->index = value.index;
this->vacant = value.vacant;
return *this;
}
};
const T *merge(const T *L, const T *R) {
if (R->vacant) {
return R;
} else {
return L;
}
}
template <size_t W> class SegmentTree;
template <size_t W> class SegmentTreeNode {
private:
const size_t start;
const size_t end;
SegmentTreeNode<(W + 1) / 2> L;
SegmentTreeNode<W / 2> R;
public:
SegmentTreeNode(const std::vector<T> &values, size_t start)
: start(start), end(start + W), L(values, start),
R(values, start + (W + 1) / 2) {
value = merge(L.value, R.value);
}
const T *value;
void print() {
L.print();
R.print();
}
inline void update(size_t index, const T &value) {
if (start <= index && index < end) {
L.update(index, value);
R.update(index, value);
this->value = merge(L.value, R.value);
}
}
inline void update() {
L.update();
R.update();
this->value = merge(L.value, R.value);
}
inline const T *pick(size_t start, size_t end) {
if (start <= this->start && this->end <= end) {
return value;
} else if (this->start<end &&this->end> start) {
auto l = L.pick(start, end);
auto r = R.pick(start, end);
if (l == NULL) {
return r;
} else if (r == NULL) {
return l;
}
return merge(l, r);
} else {
return NULL;
}
}
};
template <> class SegmentTreeNode<1> {
private:
const size_t index;
public:
SegmentTreeNode(const std::vector<T> &values, size_t start)
: index(start), value(&values[start]) {}
const T *value;
void print() { std::cout << index << std::endl; }
inline void update(size_t index, const T &value) {}
inline void update() {}
inline const T *pick(size_t start, size_t end) {
if (start <= this->index && this->index < end) {
return value;
} else {
return NULL;
}
}
};
template <size_t W> class SegmentTree {
private:
std::vector<T> values;
SegmentTreeNode<W> *root;
public:
SegmentTree() : values(W) { root = new SegmentTreeNode<W>(values, 0); }
SegmentTree(const std::vector<T> &values) : values(values) {
root = new SegmentTreeNode<W>(values, 0);
}
SegmentTree(const std::vector<T> &&values) : values(values) {
root = new SegmentTreeNode<W>(values, 0);
}
~SegmentTree() { delete root; }
void print() { root->print(); }
void update(size_t index, const T &&value) {
values[index] = value;
root->update(index, values[index]);
}
void clear(const T &value) {
for (auto i = values.begin(); i != values.end(); i++) {
*i = value;
}
root->update();
}
const T *pick(size_t start, size_t end) { return root->pick(start, end); }
const std::vector<T> &get_values() { return values; }
};
const int MAX = 200000;
class Camel {
public:
long long D, L, R, K;
Camel(long long D, long long L, long long R, long long K)
: D(D), L(L), R(R), K(K) {}
bool operator<(const Camel &value) { return D > value.D; }
};
using namespace std;
// #include "print.cpp"
long long calc(SegmentTree<MAX> &st, vector<Camel> &camels) {
sort(camels.begin(), camels.end());
long long count = camels.size();
// st.clear(T());
for (int i = 0; i < count; i++) {
st.update(i, T(i));
}
long long score = 0;
// vector<pair<int, int>> train(count, pair<int, int>(-1, -1));
for (auto &camel : camels) {
if (camel.K > 0) {
auto p = st.pick(0, min(camel.K, count));
// printe(camel.D, camel.L, camel.R, camel.K,
//p->index, p->vacant);
if (p != NULL && p->index >= 0 && p->vacant) {
// train[p->index] = pair<int, int>(camel.L,
//camel.R); printe(st.get_values()[0].vacant);
st.update(p->index, T());
// printe(st.get_values()[0].vacant);
score += camel.L;
} else {
score += camel.R;
}
} else {
score += camel.R;
}
}
// printe(train);
return score;
}
int main(void) {
SegmentTree<MAX> st;
int T;
cin >> T;
for (int i = 0; i < T; i++) {
int N;
cin >> N;
vector<Camel> camels_l;
vector<Camel> camels_r;
for (int j = 0; j < N; j++) {
long long K, L, R;
cin >> K;
cin >> L;
cin >> R;
const long long D = L - R;
if (D >= 0) {
camels_l.push_back(Camel(D, L, R, K));
} else {
camels_r.push_back(Camel(-D, R, L, N - K));
}
}
cout << calc(st, camels_l) + calc(st, camels_r) << endl;
}
return 0;
}
| replace | 146 | 147 | 146 | 147 | TLE | |
p02610 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int T, n;
vector<int> G[maxn], H[maxn];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
G[i].clear(), H[i].clear();
}
long long ans = 0;
for (int i = 1, K, L, R; i <= n; i++) {
scanf("%d %d %d", &K, &L, &R);
if (L > R)
ans += R, G[K].push_back(L - R);
else
ans += L, H[K].push_back(R - L);
}
multiset<int> S;
for (int i = 1; i <= n; i++) {
for (int j : G[i]) {
S.insert(j), ans += j;
}
while (S.size() > i) {
auto it = S.begin();
ans -= *it, S.erase(it);
}
}
S.clear();
for (int i = n; i; i--) {
for (int j : H[i]) {
S.insert(j), ans += j;
}
while (S.size() > n - i) {
auto it = S.begin();
ans -= *it, S.erase(it);
}
}
printf("%lld\n", ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int T, n;
vector<int> G[maxn], H[maxn];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
G[i].clear(), H[i].clear();
}
long long ans = 0;
for (int i = 1, K, L, R; i <= n; i++) {
scanf("%d %d %d", &K, &L, &R);
if (L > R)
ans += R, G[K].push_back(L - R);
else
ans += L, H[K].push_back(R - L);
}
multiset<int> S;
for (int i = 1; i <= n; i++) {
for (int j : G[i]) {
S.insert(j), ans += j;
}
while (S.size() > i) {
auto it = S.begin();
ans -= *it, S.erase(it);
}
}
S.clear();
for (int i = n; i; i--) {
for (int j : H[i]) {
S.insert(j), ans += j;
}
while (S.size() > n - i) {
auto it = S.begin();
ans -= *it, S.erase(it);
}
}
printf("%lld\n", ans);
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02610 | C++ | Runtime Error | // #pragma GCC target ("avx")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'
#pragma region TEMPLATE
/* TYPE */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
template <typename T, typename Cmp = less<>>
using prique = priority_queue<T, vector<T>, Cmp>;
template <typename T> using prique_r = prique<T, greater<>>;
/* CONSTANT */
#define ln '\n'
const int INF = 1 << 30;
const ll INFF = 1LL << 60;
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int MOD = 1e9 + 7;
const int MODD = 998244353;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const double EPS = 1e-9;
const ld PI = 3.14159265358979323846264338327950288;
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, -1, -1, 1, 1, 0};
/* CONTAINER */
#define PB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(RALL(v))
#define LESS(x, val) (lower_bound(x.begin(), x.end(), val) - x.begin())
#define LEQ(x, val) (upper_bound(x.begin(), x.end(), val) - x.begin())
#define GREATER(x, val) (int)(x).size() - LEQ((x), (val))
#define GEQ(x, val) (int)(x).size() - LESS((x), (val))
#define UNIQUE(v) \
sort(ALL(v)); \
(v).erase(unique(ALL(v)), (v).end())
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename U, typename... V>
enable_if_t<is_same<T, U>::value != 0> fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
enable_if_t<is_same<T, U>::value == 0> fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
/* LOOP */
#define _overload3(_1, _2, _3, name, ...) name
#define _REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i)
#define REP(...) _overload3(__VA_ARGS__, REPI, _REP, )(__VA_ARGS__)
#define _RREP(i, n) RREPI(i, n, 0)
#define RREPI(i, a, b) for (ll i = (ll)a; i >= (ll)b; --i)
#define RREP(...) _overload3(__VA_ARGS__, RREPI, _RREP, )(__VA_ARGS__)
#define EACH(e, v) for (auto &e : v)
#define PERM(v) \
sort(ALL(v)); \
for (bool c##p = true; c##p; c##p = next_permutation(ALL(v)))
/* INPUT */
template <typename T> void SSS(T &t) { cin >> t; }
template <typename Head, typename... Tail>
void SSS(Head &&head, Tail &&...tail) {
cin >> head;
SSS(tail...);
}
#define SS(T, ...) \
T __VA_ARGS__; \
SSS(__VA_ARGS__);
#define SV(T, v, n) \
vector<T> v(n); \
for (auto &i : v) \
cin >> i;
#define SVV(T, v, n, m) \
vector<vector<T>> v(n, vector<T>(m)); \
for (auto &r : v) \
for (auto &i : r) \
cin >> i;
/* OUTPUT */
// Yes / No
inline int YES(bool x) {
cout << (x ? "YES" : "NO") << endl;
return 0;
}
inline int Yes(bool x) {
cout << (x ? "Yes" : "No") << endl;
return 0;
}
inline int yes(bool x) {
cout << (x ? "yes" : "no") << endl;
return 0;
}
inline int yES(bool x) {
cout << (x ? "yES" : "nO") << endl;
return 0;
}
inline int Yay(bool x) {
cout << (x ? "Yay!" : ":(") << endl;
return 0;
}
// PROTOTYPE DECLARATION
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &j);
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &t);
template <class C, enable_if_t<!is_same<C, string>::value,
decltype(declval<const C &>().begin(),
nullptr)> = nullptr>
ostream &operator<<(ostream &os, const C &c);
template <typename T> ostream &operator<<(ostream &os, const stack<T> &j);
template <typename T> ostream &operator<<(ostream &os, const queue<T> &j);
template <typename T, typename C, typename Cmp>
ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j);
// IMPLEMENTATION
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &j) {
return os << '{' << j.first << ", " << j.second << '}';
}
template <size_t num = 0, typename... T>
enable_if_t<num == sizeof...(T)> PRINT_TUPLE(ostream &os,
const tuple<T...> &t) {}
template <size_t num = 0, typename... T>
enable_if_t <
num<sizeof...(T)> PRINT_TUPLE(ostream &os, const tuple<T...> &t) {
os << get<num>(t);
if (num + 1 < sizeof...(T))
os << ", ";
PRINT_TUPLE<num + 1>(os, t);
}
template <typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &t) {
PRINT_TUPLE(os << '{', t);
return os << '}';
}
template <class C, enable_if_t<!is_same<C, string>::value,
decltype(declval<const C &>().begin(), nullptr)>>
ostream &operator<<(ostream &os, const C &c) {
os << '{';
for (auto it = begin(c); it != end(c); it++) {
if (begin(c) != it)
os << ", ";
os << *it;
}
return os << '}';
}
template <typename T> ostream &operator<<(ostream &os, const stack<T> &j) {
deque<T> d;
for (auto c = j; !c.empty(); c.pop())
d.push_front(c.top());
return os << d;
}
template <typename T> ostream &operator<<(ostream &os, const queue<T> &j) {
deque<T> d;
for (auto c = j; !c.empty(); c.pop())
d.push_back(c.front());
return os << d;
}
template <typename T, typename C, typename Cmp>
ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j) {
deque<T> d;
for (auto c = j; !c.empty(); c.pop())
d.push_front(c.top());
return os << d;
}
// OUTPUT FUNCTION
template <typename T> int PV(T &v) {
int sz = v.size();
for (int i = 0; i < sz; ++i)
cout << v[i] << " \n"[i == sz - 1];
return 0;
}
inline int print() {
cout << endl;
return 0;
}
template <typename Head> int print(Head &&head) {
cout << head;
return print();
}
template <typename Head, typename... Tail>
int print(Head &&head, Tail &&...tail) {
cout << head << " ";
return print(forward<Tail>(tail)...);
}
#ifdef LOCAL
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
cerr << head;
dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&...tail) {
cerr << head << ", ";
dump(forward<Tail>(tail)...);
}
#define debug(...) \
do { \
cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
dump(__VA_ARGS__); \
} while (false)
#else
#define dump(...)
#define debug(...)
#endif
/* OTHER */
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
template <typename T, typename A, typename B>
inline bool between(T x, A a, B b) {
return ((a <= x) && (x < b));
}
template <typename A, typename B> inline bool chmax(A &a, const B &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename A, typename B> inline bool chmin(A &a, const B &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline ll POW(ll a, ll b) {
ll r = 1;
do {
if (b & 1)
r *= a;
a *= a;
} while (b >>= 1);
return r;
}
struct abracadabra {
abracadabra() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cerr << fixed << setprecision(5);
};
} ABRACADABRA;
#pragma endregion
void solve() {
SS(int, N);
ll res = 0;
vector<vector<ll>> d_l(N, vector<ll>());
vector<vector<ll>> d_r(N, vector<ll>());
REP(i, N) {
SS(ll, K, L, R);
--K;
if (L == R) {
res += L;
} else if (L > R) {
res += R;
d_l[K].emplace_back(L - R);
} else {
res += L;
d_r[K + 1].emplace_back(R - L);
}
}
{
prique_r<ll> pq;
REP(i, N) {
EACH(e, d_l[i]) pq.emplace(e);
while (pq.size() > i + 1)
pq.pop();
}
while (not pq.empty()) {
res += pq.top();
pq.pop();
}
}
{
prique_r<ll> pq;
RREP(i, N - 1) {
EACH(e, d_r[i]) pq.emplace(e);
while (pq.size() > N - i)
pq.pop();
}
while (not pq.empty()) {
res += pq.top();
pq.pop();
}
}
print(res);
}
signed main() {
int T;
cin >> T;
REP(i, T) { solve(); }
}
| // #pragma GCC target ("avx")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'
#pragma region TEMPLATE
/* TYPE */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
template <typename T, typename Cmp = less<>>
using prique = priority_queue<T, vector<T>, Cmp>;
template <typename T> using prique_r = prique<T, greater<>>;
/* CONSTANT */
#define ln '\n'
const int INF = 1 << 30;
const ll INFF = 1LL << 60;
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int MOD = 1e9 + 7;
const int MODD = 998244353;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const double EPS = 1e-9;
const ld PI = 3.14159265358979323846264338327950288;
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, -1, -1, 1, 1, 0};
/* CONTAINER */
#define PB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(RALL(v))
#define LESS(x, val) (lower_bound(x.begin(), x.end(), val) - x.begin())
#define LEQ(x, val) (upper_bound(x.begin(), x.end(), val) - x.begin())
#define GREATER(x, val) (int)(x).size() - LEQ((x), (val))
#define GEQ(x, val) (int)(x).size() - LESS((x), (val))
#define UNIQUE(v) \
sort(ALL(v)); \
(v).erase(unique(ALL(v)), (v).end())
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename U, typename... V>
enable_if_t<is_same<T, U>::value != 0> fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
enable_if_t<is_same<T, U>::value == 0> fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
/* LOOP */
#define _overload3(_1, _2, _3, name, ...) name
#define _REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i)
#define REP(...) _overload3(__VA_ARGS__, REPI, _REP, )(__VA_ARGS__)
#define _RREP(i, n) RREPI(i, n, 0)
#define RREPI(i, a, b) for (ll i = (ll)a; i >= (ll)b; --i)
#define RREP(...) _overload3(__VA_ARGS__, RREPI, _RREP, )(__VA_ARGS__)
#define EACH(e, v) for (auto &e : v)
#define PERM(v) \
sort(ALL(v)); \
for (bool c##p = true; c##p; c##p = next_permutation(ALL(v)))
/* INPUT */
template <typename T> void SSS(T &t) { cin >> t; }
template <typename Head, typename... Tail>
void SSS(Head &&head, Tail &&...tail) {
cin >> head;
SSS(tail...);
}
#define SS(T, ...) \
T __VA_ARGS__; \
SSS(__VA_ARGS__);
#define SV(T, v, n) \
vector<T> v(n); \
for (auto &i : v) \
cin >> i;
#define SVV(T, v, n, m) \
vector<vector<T>> v(n, vector<T>(m)); \
for (auto &r : v) \
for (auto &i : r) \
cin >> i;
/* OUTPUT */
// Yes / No
inline int YES(bool x) {
cout << (x ? "YES" : "NO") << endl;
return 0;
}
inline int Yes(bool x) {
cout << (x ? "Yes" : "No") << endl;
return 0;
}
inline int yes(bool x) {
cout << (x ? "yes" : "no") << endl;
return 0;
}
inline int yES(bool x) {
cout << (x ? "yES" : "nO") << endl;
return 0;
}
inline int Yay(bool x) {
cout << (x ? "Yay!" : ":(") << endl;
return 0;
}
// PROTOTYPE DECLARATION
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &j);
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &t);
template <class C, enable_if_t<!is_same<C, string>::value,
decltype(declval<const C &>().begin(),
nullptr)> = nullptr>
ostream &operator<<(ostream &os, const C &c);
template <typename T> ostream &operator<<(ostream &os, const stack<T> &j);
template <typename T> ostream &operator<<(ostream &os, const queue<T> &j);
template <typename T, typename C, typename Cmp>
ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j);
// IMPLEMENTATION
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &j) {
return os << '{' << j.first << ", " << j.second << '}';
}
template <size_t num = 0, typename... T>
enable_if_t<num == sizeof...(T)> PRINT_TUPLE(ostream &os,
const tuple<T...> &t) {}
template <size_t num = 0, typename... T>
enable_if_t <
num<sizeof...(T)> PRINT_TUPLE(ostream &os, const tuple<T...> &t) {
os << get<num>(t);
if (num + 1 < sizeof...(T))
os << ", ";
PRINT_TUPLE<num + 1>(os, t);
}
template <typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &t) {
PRINT_TUPLE(os << '{', t);
return os << '}';
}
template <class C, enable_if_t<!is_same<C, string>::value,
decltype(declval<const C &>().begin(), nullptr)>>
ostream &operator<<(ostream &os, const C &c) {
os << '{';
for (auto it = begin(c); it != end(c); it++) {
if (begin(c) != it)
os << ", ";
os << *it;
}
return os << '}';
}
template <typename T> ostream &operator<<(ostream &os, const stack<T> &j) {
deque<T> d;
for (auto c = j; !c.empty(); c.pop())
d.push_front(c.top());
return os << d;
}
template <typename T> ostream &operator<<(ostream &os, const queue<T> &j) {
deque<T> d;
for (auto c = j; !c.empty(); c.pop())
d.push_back(c.front());
return os << d;
}
template <typename T, typename C, typename Cmp>
ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j) {
deque<T> d;
for (auto c = j; !c.empty(); c.pop())
d.push_front(c.top());
return os << d;
}
// OUTPUT FUNCTION
template <typename T> int PV(T &v) {
int sz = v.size();
for (int i = 0; i < sz; ++i)
cout << v[i] << " \n"[i == sz - 1];
return 0;
}
inline int print() {
cout << endl;
return 0;
}
template <typename Head> int print(Head &&head) {
cout << head;
return print();
}
template <typename Head, typename... Tail>
int print(Head &&head, Tail &&...tail) {
cout << head << " ";
return print(forward<Tail>(tail)...);
}
#ifdef LOCAL
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
cerr << head;
dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&...tail) {
cerr << head << ", ";
dump(forward<Tail>(tail)...);
}
#define debug(...) \
do { \
cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
dump(__VA_ARGS__); \
} while (false)
#else
#define dump(...)
#define debug(...)
#endif
/* OTHER */
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
template <typename T, typename A, typename B>
inline bool between(T x, A a, B b) {
return ((a <= x) && (x < b));
}
template <typename A, typename B> inline bool chmax(A &a, const B &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename A, typename B> inline bool chmin(A &a, const B &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline ll POW(ll a, ll b) {
ll r = 1;
do {
if (b & 1)
r *= a;
a *= a;
} while (b >>= 1);
return r;
}
struct abracadabra {
abracadabra() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cerr << fixed << setprecision(5);
};
} ABRACADABRA;
#pragma endregion
void solve() {
SS(int, N);
ll res = 0;
vector<vector<ll>> d_l(N, vector<ll>());
vector<vector<ll>> d_r(N, vector<ll>());
REP(i, N) {
SS(ll, K, L, R);
--K;
if (L == R) {
res += L;
} else if (K == N - 1) {
res += L;
} else if (L > R) {
res += R;
d_l[K].emplace_back(L - R);
} else {
res += L;
d_r[K + 1].emplace_back(R - L);
}
}
{
prique_r<ll> pq;
REP(i, N) {
EACH(e, d_l[i]) pq.emplace(e);
while (pq.size() > i + 1)
pq.pop();
}
while (not pq.empty()) {
res += pq.top();
pq.pop();
}
}
{
prique_r<ll> pq;
RREP(i, N - 1) {
EACH(e, d_r[i]) pq.emplace(e);
while (pq.size() > N - i)
pq.pop();
}
while (not pq.empty()) {
res += pq.top();
pq.pop();
}
}
print(res);
}
signed main() {
int T;
cin >> T;
REP(i, T) { solve(); }
}
| insert | 279 | 279 | 279 | 281 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02610 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (int i = a; i <= b; ++i)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep3(i, a, b) for (int i = a; i >= b; i--)
#define REP(e, v) for (auto e : v)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(), (c).end()
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
string stin() {
string s;
cin >> s;
return s;
}
void func() {
int n = in();
ll ans = 0;
vector<vector<pii>> que(2);
rep(i, n) {
int k = in(), l = in(), r = in();
if (l > r) {
ans += r;
l -= r;
que[0].pb(mp(-k, l));
} else {
ans += l;
r -= l;
que[1].pb(mp(-(n - k), r));
}
}
rep(x, 2) {
sort(ALL(que[x]));
pq p;
int tmp = n;
int id = 0;
while (tmp >= 1) {
while (id < n) {
if (que[x][id].first == -tmp) {
p.push(que[x][id].second);
id++;
} else {
break;
}
}
if (!p.empty()) {
ans += p.top();
p.pop();
}
tmp--;
}
}
cout << ans << endl;
}
int main() {
int t = in();
rep(i, t) func();
} | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (int i = a; i <= b; ++i)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep3(i, a, b) for (int i = a; i >= b; i--)
#define REP(e, v) for (auto e : v)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(), (c).end()
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
string stin() {
string s;
cin >> s;
return s;
}
void func() {
int n = in();
ll ans = 0;
vector<vector<pii>> que(2);
rep(i, n) {
int k = in(), l = in(), r = in();
if (l > r) {
ans += r;
l -= r;
que[0].pb(mp(-k, l));
} else {
ans += l;
r -= l;
que[1].pb(mp(-(n - k), r));
}
}
rep(x, 2) {
sort(ALL(que[x]));
pq p;
int tmp = n;
int id = 0;
while (tmp >= 1) {
while (id < que[x].size()) {
if (-que[x][id].first == tmp) {
p.push(que[x][id].second);
id++;
} else {
break;
}
}
if (!p.empty()) {
ans += p.top();
p.pop();
}
tmp--;
}
}
cout << ans << endl;
}
int main() {
int t = in();
rep(i, t) func();
}
| replace | 75 | 77 | 75 | 77 | 0 | |
p02611 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) {
return a < b ? (a = b, true) : false;
}
template <typename T, typename U> inline bool chmin(T &a, U b) {
return a > b ? (a = b, true) : false;
}
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
int mod = MOD;
struct ModInt {
unsigned val;
ModInt() : val(0) {}
ModInt(ll x) : val(x >= 0 ? x % mod : x % mod + mod) {}
ModInt pow(ll exponent) const {
ModInt tmp = *this, res = 1;
while (exponent > 0) {
if (exponent & 1)
res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
ModInt &operator+=(const ModInt &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
ModInt &operator-=(const ModInt &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
ModInt &operator*=(const ModInt &x) {
val = static_cast<unsigned long long>(val) * x.val % mod;
return *this;
}
ModInt &operator/=(const ModInt &x) {
// assert(__gcd(static_cast<int>(x.val), mod) == 1);
unsigned a = x.val, b = mod;
int u = 1, v = 0;
while (b) {
unsigned tmp = a / b;
swap(a -= tmp * b, b);
swap(u -= tmp * v, v);
}
return *this *= u;
}
bool operator==(const ModInt &x) const { return val == x.val; }
bool operator!=(const ModInt &x) const { return val != x.val; }
bool operator<(const ModInt &x) const { return val < x.val; }
bool operator<=(const ModInt &x) const { return val <= x.val; }
bool operator>(const ModInt &x) const { return val > x.val; }
bool operator>=(const ModInt &x) const { return val >= x.val; }
ModInt &operator++() {
if (++val == mod)
val = 0;
return *this;
}
ModInt operator++(int) {
ModInt res = *this;
++*this;
return res;
}
ModInt &operator--() {
val = (val == 0 ? mod : val) - 1;
return *this;
}
ModInt operator--(int) {
ModInt res = *this;
--*this;
return res;
}
ModInt operator+() const { return *this; }
ModInt operator-() const { return ModInt(val ? mod - val : 0); }
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
friend ostream &operator<<(ostream &os, const ModInt &x) {
return os << x.val;
}
friend istream &operator>>(istream &is, ModInt &x) {
ll val;
is >> val;
x = ModInt(val);
return is;
}
};
ModInt abs(const ModInt &x) { return x; }
struct Combinatorics {
int val; // "val!" and "mod" must be disjoint.
vector<ModInt> fact, fact_inv, inv;
Combinatorics(int val = 10000000)
: val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {
fact[0] = 1;
FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i;
fact_inv[val] = ModInt(1) / fact[val];
for (int i = val; i > 0; --i)
fact_inv[i - 1] = fact_inv[i] * i;
FOR(i, 1, val + 1) inv[i] = fact[i - 1] * fact_inv[i];
}
ModInt nCk(int n, int k) const {
if (n < 0 || n < k || k < 0)
return ModInt(0);
// assert(n <= val && k <= val);
return fact[n] * fact_inv[k] * fact_inv[n - k];
}
ModInt nPk(int n, int k) const {
if (n < 0 || n < k || k < 0)
return ModInt(0);
// assert(n <= val);
return fact[n] * fact_inv[n - k];
}
ModInt nHk(int n, int k) const {
if (n < 0 || k < 0)
return ModInt(0);
return k == 0 ? ModInt(1) : nCk(n + k - 1, k);
}
};
template <typename T> struct Matrix {
vector<vector<T>> dat;
Matrix(int m, int n, T val = 0) : dat(m, vector<T>(n, val)) {}
int height() const { return dat.size(); }
int width() const { return dat.front().size(); }
Matrix pow(ll exponent) const {
int n = height();
Matrix<T> tmp = *this, res(n, n, 0);
REP(i, n) res[i][i] = 1;
while (exponent > 0) {
if (exponent & 1)
res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
inline const vector<T> &operator[](const int idx) const { return dat[idx]; }
inline vector<T> &operator[](const int idx) { return dat[idx]; }
Matrix &operator=(const Matrix &x) {
int m = x.height(), n = x.width();
dat.resize(m, vector<T>(n));
REP(i, m) REP(j, n) dat[i][j] = x[i][j];
return *this;
}
Matrix &operator+=(const Matrix &x) {
int m = height(), n = width();
REP(i, m) REP(j, n) dat[i][j] += x[i][j];
return *this;
}
Matrix &operator-=(const Matrix &x) {
int m = height(), n = width();
REP(i, m) REP(j, n) dat[i][j] -= x[i][j];
return *this;
}
Matrix &operator*=(const Matrix &x) {
int m = height(), n = x.width(), l = width();
vector<vector<T>> res(m, vector<T>(n, 0));
REP(i, m) REP(j, n) { REP(k, l) res[i][j] += dat[i][k] * x[k][j]; }
swap(dat, res);
return *this;
}
Matrix operator+(const Matrix &x) const { return Matrix(*this) += x; }
Matrix operator-(const Matrix &x) const { return Matrix(*this) -= x; }
Matrix operator*(const Matrix &x) const { return Matrix(*this) *= x; }
};
int main() {
const int X = 15;
Matrix<ModInt> m((X + 1) * 2, (X + 1) * 2), x((X + 1) * 2, 1);
REP(j, X + 1) REP(p, 2) {
if (j + 1 <= X && (j >= 5 || !p)) {
// dp[i][j][p] -> dp[i + 1][k][1] (k > j)
FOR(k, j + 1, X + 1) m[(X + 1) + k][p * (X + 1) + j] = 1;
}
// dp[i][j][p] -> dp[i + 1][j][p ^ 1]
m[(p ^ 1) * (X + 1) + j][p * (X + 1) + j] = 1;
}
x[0][0] = 1;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << (n < 5 ? ModInt(0)
: (m.pow(n - 4) * x)[X][0] +
(m.pow(n - 4) * x)[(X + 1) + X][0])
<< '\n';
}
return 0;
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) {
return a < b ? (a = b, true) : false;
}
template <typename T, typename U> inline bool chmin(T &a, U b) {
return a > b ? (a = b, true) : false;
}
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
int mod = MOD;
struct ModInt {
unsigned val;
ModInt() : val(0) {}
ModInt(ll x) : val(x >= 0 ? x % mod : x % mod + mod) {}
ModInt pow(ll exponent) const {
ModInt tmp = *this, res = 1;
while (exponent > 0) {
if (exponent & 1)
res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
ModInt &operator+=(const ModInt &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
ModInt &operator-=(const ModInt &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
ModInt &operator*=(const ModInt &x) {
val = static_cast<unsigned long long>(val) * x.val % mod;
return *this;
}
ModInt &operator/=(const ModInt &x) {
// assert(__gcd(static_cast<int>(x.val), mod) == 1);
unsigned a = x.val, b = mod;
int u = 1, v = 0;
while (b) {
unsigned tmp = a / b;
swap(a -= tmp * b, b);
swap(u -= tmp * v, v);
}
return *this *= u;
}
bool operator==(const ModInt &x) const { return val == x.val; }
bool operator!=(const ModInt &x) const { return val != x.val; }
bool operator<(const ModInt &x) const { return val < x.val; }
bool operator<=(const ModInt &x) const { return val <= x.val; }
bool operator>(const ModInt &x) const { return val > x.val; }
bool operator>=(const ModInt &x) const { return val >= x.val; }
ModInt &operator++() {
if (++val == mod)
val = 0;
return *this;
}
ModInt operator++(int) {
ModInt res = *this;
++*this;
return res;
}
ModInt &operator--() {
val = (val == 0 ? mod : val) - 1;
return *this;
}
ModInt operator--(int) {
ModInt res = *this;
--*this;
return res;
}
ModInt operator+() const { return *this; }
ModInt operator-() const { return ModInt(val ? mod - val : 0); }
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
friend ostream &operator<<(ostream &os, const ModInt &x) {
return os << x.val;
}
friend istream &operator>>(istream &is, ModInt &x) {
ll val;
is >> val;
x = ModInt(val);
return is;
}
};
ModInt abs(const ModInt &x) { return x; }
struct Combinatorics {
int val; // "val!" and "mod" must be disjoint.
vector<ModInt> fact, fact_inv, inv;
Combinatorics(int val = 10000000)
: val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {
fact[0] = 1;
FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i;
fact_inv[val] = ModInt(1) / fact[val];
for (int i = val; i > 0; --i)
fact_inv[i - 1] = fact_inv[i] * i;
FOR(i, 1, val + 1) inv[i] = fact[i - 1] * fact_inv[i];
}
ModInt nCk(int n, int k) const {
if (n < 0 || n < k || k < 0)
return ModInt(0);
// assert(n <= val && k <= val);
return fact[n] * fact_inv[k] * fact_inv[n - k];
}
ModInt nPk(int n, int k) const {
if (n < 0 || n < k || k < 0)
return ModInt(0);
// assert(n <= val);
return fact[n] * fact_inv[n - k];
}
ModInt nHk(int n, int k) const {
if (n < 0 || k < 0)
return ModInt(0);
return k == 0 ? ModInt(1) : nCk(n + k - 1, k);
}
};
template <typename T> struct Matrix {
vector<vector<T>> dat;
Matrix(int m, int n, T val = 0) : dat(m, vector<T>(n, val)) {}
int height() const { return dat.size(); }
int width() const { return dat.front().size(); }
Matrix pow(ll exponent) const {
int n = height();
Matrix<T> tmp = *this, res(n, n, 0);
REP(i, n) res[i][i] = 1;
while (exponent > 0) {
if (exponent & 1)
res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
inline const vector<T> &operator[](const int idx) const { return dat[idx]; }
inline vector<T> &operator[](const int idx) { return dat[idx]; }
Matrix &operator=(const Matrix &x) {
int m = x.height(), n = x.width();
dat.resize(m, vector<T>(n));
REP(i, m) REP(j, n) dat[i][j] = x[i][j];
return *this;
}
Matrix &operator+=(const Matrix &x) {
int m = height(), n = width();
REP(i, m) REP(j, n) dat[i][j] += x[i][j];
return *this;
}
Matrix &operator-=(const Matrix &x) {
int m = height(), n = width();
REP(i, m) REP(j, n) dat[i][j] -= x[i][j];
return *this;
}
Matrix &operator*=(const Matrix &x) {
int m = height(), n = x.width(), l = width();
vector<vector<T>> res(m, vector<T>(n, 0));
REP(i, m) REP(j, n) { REP(k, l) res[i][j] += dat[i][k] * x[k][j]; }
swap(dat, res);
return *this;
}
Matrix operator+(const Matrix &x) const { return Matrix(*this) += x; }
Matrix operator-(const Matrix &x) const { return Matrix(*this) -= x; }
Matrix operator*(const Matrix &x) const { return Matrix(*this) *= x; }
};
int main() {
const int X = 15;
Matrix<ModInt> m((X + 1) * 2, (X + 1) * 2), x((X + 1) * 2, 1);
REP(j, X + 1) REP(p, 2) {
if (j + 1 <= X && (j >= 5 || !p)) {
// dp[i][j][p] -> dp[i + 1][k][1] (k > j)
FOR(k, j + 1, X + 1) m[(X + 1) + k][p * (X + 1) + j] = 1;
}
// dp[i][j][p] -> dp[i + 1][j][p ^ 1]
m[(p ^ 1) * (X + 1) + j][p * (X + 1) + j] = 1;
}
x[0][0] = 1;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n < 5) {
cout << 0 << '\n';
} else {
Matrix<ModInt> ans = m.pow(n - 4) * x;
cout << ans[X][0] + ans[(X + 1) + X][0] << '\n';
}
}
return 0;
}
| replace | 218 | 222 | 218 | 224 | TLE | |
p02612 | Python | Runtime Error | n = input()
n = int(n[1:])
if 1000 - n == 1000:
print(0)
else:
print(1000 - n)
| n = int(input())
n = n % 1000
if 1000 - n == 1000:
print(0)
else:
print(1000 - n)
| replace | 0 | 2 | 0 | 2 | 0 | |
p02612 | C++ | Time Limit Exceeded | #include <iostream>
int main() {
int N = {}; // 商品代金
int change = {}; // お釣り
int Min_value = 1; // 下限値
int Max_value = 10000; // 上限値
std::cin >> N;
if (Min_value > N || N > Max_value) {
std::cout << "予算を10000円を超えてます!" << std::endl;
}
while (N >= 1000) {
if (N == 1000) {
change = 0;
std::cout << change << std::endl;
return 0;
}
N - 1000;
}
change = 1000 - N;
std::cout << change << std::endl;
} | #include <iostream>
int main() {
int N = {}; // 商品代金
int change = {}; // お釣り
int Min_value = 1; // 下限値
int Max_value = 10000; // 上限値
std::cin >> N;
if (Min_value > N || N > Max_value) {
std::cout << "予算を10000円を超えてます!" << std::endl;
}
while (N >= 1000) {
if (N == 1000) {
change = 0;
std::cout << change << std::endl;
return 0;
}
N = N - 1000;
}
change = 1000 - N;
std::cout << change << std::endl;
} | replace | 20 | 21 | 20 | 21 | TLE | |
p02612 | Python | Runtime Error | # input
N = int(input())
noguchi = [1000 * n for n in range(1, 11)]
# check
print(min([ngc - N for ngc in noguchi if (ngc - N) > 0]))
| # input
N = int(input())
noguchi = [1000 * n for n in range(1, 11)]
# check
print(min([ngc - N for ngc in noguchi if (ngc - N) >= 0]))
| replace | 5 | 6 | 5 | 6 | 0 | |
p02612 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", n);
int ans = n % 1000;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans;
ans = (1000 - n % 1000) % 1000;
cout << ans << endl;
return 0;
} | replace | 3 | 6 | 3 | 7 | -11 | |
p02612 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int t = n % 1000;
return 1000 - t;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int t = n % 1000;
if (t == 0)
cout << "0";
else
cout << 1000 - t;
} | replace | 6 | 7 | 6 | 10 | 100 | |
p02612 | C++ | Runtime Error | // author rhythmicankur
// god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
#define ll int
#define ld long double
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define vi vector<int>
#define pii pair<int, int>
#define pip pair<int, pii>
#define vpi vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define fill(a, val) memset(a, val, sizeof(a))
#define PI acos(-1)
#define coud(a, b) cout << fixed << setprecision((b)) << (a)
#define M1 998244353
#define M2 1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T> T gcd(T a, T b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
#define test4(x, y, z, a) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #a << ": " << a << endl;
#define test1(x) cerr << #x << ": " << x << endl
#define test2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define test3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
ll power(ll a, ll b, ll m = M2) {
ll answer = 1;
while (b) {
if (b & 1)
answer = (answer * a) % m;
b /= 2;
a = (a * a) % m;
}
return answer;
}
using namespace std;
void ctrl() { cout << "Control" << endl; }
int make_num(string p) {
stringstream geek(p);
int x = 0;
geek >> x;
return x;
}
string make_str(int x) {
ostringstream str1;
str1 << x;
string geek = str1.str();
return geek;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int tc;
tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
int n;
cin >> n;
int x = 1000 - (n % 1000);
cout << x % 1000;
}
return 0;
} | // author rhythmicankur
// god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
#define ll int
#define ld long double
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define vi vector<int>
#define pii pair<int, int>
#define pip pair<int, pii>
#define vpi vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define fill(a, val) memset(a, val, sizeof(a))
#define PI acos(-1)
#define coud(a, b) cout << fixed << setprecision((b)) << (a)
#define M1 998244353
#define M2 1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T> T gcd(T a, T b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
#define test4(x, y, z, a) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #a << ": " << a << endl;
#define test1(x) cerr << #x << ": " << x << endl
#define test2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define test3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
ll power(ll a, ll b, ll m = M2) {
ll answer = 1;
while (b) {
if (b & 1)
answer = (answer * a) % m;
b /= 2;
a = (a * a) % m;
}
return answer;
}
using namespace std;
void ctrl() { cout << "Control" << endl; }
int make_num(string p) {
stringstream geek(p);
int x = 0;
geek >> x;
return x;
}
string make_str(int x) {
ostringstream str1;
str1 << x;
string geek = str1.str();
return geek;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int tc;
tc = 1;
// cin>>tc;
for (int t = 1; t <= tc; t++) {
int n;
cin >> n;
int x = 1000 - (n % 1000);
cout << x % 1000;
}
return 0;
} | replace | 72 | 73 | 72 | 73 | -6 | terminate called after throwing an instance of 'std::__ios_failure'
what(): basic_ios::clear: iostream error
|
p02612 | C++ | Time Limit Exceeded | #include <stdio.h>
int main() {
int p, c;
scanf("%d", &p);
for (c = 0; c < p; c = +1000) {
c;
}
printf("%d", c - p);
} | #include <stdio.h>
int main() {
int a;
scanf("%d", &a);
printf("%d\n", (1000 - (a - a / 1000 * 1000)) % 1000);
return 0;
} | replace | 2 | 8 | 2 | 6 | TLE | |
p02612 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int cost;
cin >> cost;
int money = 0;
while (money < cost) {
money + 1000;
}
cout << money - cost << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int cost;
cin >> cost;
int money = 0;
while (money < cost) {
money += 1000;
}
cout << money - cost << endl;
} | replace | 8 | 9 | 8 | 9 | TLE | |
p02612 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
if (n % 1000 != 0) {
n %= 1000;
cout << 1000 - n;
} else
cout << 0;
}
}
| #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 1000 != 0) {
n %= 1000;
cout << 1000 - n;
} else
cout << 0;
}
| replace | 5 | 12 | 5 | 11 | TLE | |
p02612 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define fo(i, n) for (i = 0; i < n; i++)
#define sortall(x) sort(all(x))
#define vi vector<int>
#define vs vector<string>
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, int> pii;
typedef vector<psi> vpsi;
typedef vector<psi> vpci;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
int a[N];
int n, m, k;
//=======================
void solve() { cin >> n; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t >= 1000) {
t -= 1000;
}
cout << (1000 % t == 0 ? 0 : 1000 % t) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define fo(i, n) for (i = 0; i < n; i++)
#define sortall(x) sort(all(x))
#define vi vector<int>
#define vs vector<string>
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, int> pii;
typedef vector<psi> vpsi;
typedef vector<psi> vpci;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
int a[N];
int n, m, k;
//=======================
void solve() { cin >> n; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t >= 1000) {
t -= 1000;
}
if (t != 0) {
t = abs(t - 1000);
}
cout << t << endl;
} | replace | 42 | 43 | 42 | 46 | 0 | |
p02612 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int cost;
cin >> cost;
if (cost < 1000)
return 1000 - cost;
else
return cost % 1000;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int cost;
cin >> cost;
int change;
if (cost % 1000) {
change = 1000 - cost % 1000;
} else {
change = 0;
}
cout << change;
return 0;
} | replace | 6 | 10 | 6 | 15 | 132 | |
p02612 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
cout << S.substr(S.length() - 3) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
cout << (1000 - N % 1000) % 1000 << endl;
} | replace | 4 | 7 | 4 | 7 | 0 | |
p02612 | 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;
int S = N / 1000;
int T = S * 1000;
cout << N % T << 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;
int S = N % 1000;
if (S == 0) {
cout << 0 << endl;
} else {
cout << 1000 - S << endl;
}
}
| replace | 8 | 11 | 8 | 15 | 0 | |
p02612 | C++ | Runtime Error |
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
if (N % 1000) {
cout << (1000 - N % 1000) << std::endl;
} else {
cout << N % 1000 << endl;
}
return 1;
} |
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
if (N % 1000) {
cout << (1000 - N % 1000) << std::endl;
} else {
cout << N % 1000 << endl;
}
return 0;
} | replace | 16 | 17 | 16 | 17 | 1 | |
p02612 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i; i = 1; i++) {
if (i * 1000 >= n) {
cout << i * 1000 - n << endl;
break;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 1000 != 0)
cout << 1000 - n % 1000 << endl;
else
cout << 0 << endl;
}
| replace | 7 | 13 | 7 | 11 | TLE | |
p02612 | C++ | Runtime Error | // ABC173.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
using namespace std;
int main() {
int price, change, thousands;
cin >> price;
thousands = price / 1000;
if (price % 1000 == 0) {
cout << 0;
return 0;
} else {
change = (thousands + 1) * 1000 - price;
cout << change;
return change;
}
}
| // ABC173.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
using namespace std;
int main() {
int price, change, thousands;
cin >> price;
thousands = price / 1000;
if (price % 1000 == 0) {
cout << 0;
return 0;
} else {
change = (thousands + 1) * 1000 - price;
cout << change;
return 0;
}
}
| replace | 20 | 21 | 20 | 21 | 100 | |
p02612 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
n = n % 1000;
n = 1000 - n;
if (n == 1000)
return 0;
return n;
}
| #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
n = n % 1000;
n = 1000 - n;
if (n == 1000)
cout << 0 << endl;
else
cout << n << endl;
}
| replace | 8 | 10 | 8 | 11 | 100 | |
p02612 | Python | Runtime Error | def main():
N = input()
return N % 1000
if __name__ == "__main__":
main()
| def main():
N = int(input())
if N % 1000 == 0:
print(0)
else:
print(1000 - (N % 1000))
if __name__ == "__main__":
main()
| replace | 1 | 3 | 1 | 6 | TypeError: not all arguments converted during string formatting | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02612/Python/s991643016.py", line 7, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02612/Python/s991643016.py", line 3, in main
return N % 1000
TypeError: not all arguments converted during string formatting
|
p02612 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, a, b) for (int i = (a); i > (b); --i)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int mod = 1e9 + 7;
const ll inf = 2e18 + 5;
void solve() {
int n, k;
cin >> n;
int m = n % m;
m = n - m;
if (m == n)
cout << 0 << endl;
else
cout << m << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("fin.txt", "r", stdin);
freopen("fout.txt", "w", stdout);
#endif
int cases = 1;
// cin>>cases;
for (int iter = 0; iter < cases; iter++) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, a, b) for (int i = (a); i > (b); --i)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int mod = 1e9 + 7;
const ll inf = 2e18 + 5;
void solve() {
int n, k;
cin >> n;
int m = n % 1000;
m = 1000 - m;
if (m == 1000)
cout << 0 << endl;
else
cout << m << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("fin.txt", "r", stdin);
freopen("fout.txt", "w", stdout);
#endif
int cases = 1;
// cin>>cases;
for (int iter = 0; iter < cases; iter++) {
solve();
}
return 0;
} | replace | 21 | 24 | 21 | 24 | 0 | |
p02612 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
cout << 1000 - n % 1000;
return 1000 - n % 1000;
}
| #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 1000 == 0)
cout << 0;
else
cout << 1000 - n % 1000;
return 0;
}
| replace | 5 | 7 | 5 | 10 | 100 | |
p02612 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(), (v).end()
#define sz(v) (v).size()
// #define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout << (x) << " "
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define d5(a, b, c, d, e) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << endl
#define d6(a, b, c, d, e, f) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << " " \
<< (f) << endl
bool desc_sort(const int &lhs, const int &rhs) { return lhs > rhs; }
bool desc_pii_sort(const pii &lhs, const pii &rhs) { return lhs > rhs; }
bool second_sort(const pii &lhs, const pii &rhs) {
pii a, b;
a.F = lhs.S;
a.S = lhs.F;
b.F = rhs.S;
b.S = rhs.F;
return a < b;
}
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.F << ":" << m.S << ") ";
return os << "}";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << 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 trace(...)
#endif
// #define int long long
#define modd 1e0
inline ll fast_expo(ll base, ll power, ll modulo = modd) {
base %= modulo;
if (base < 0LL)
base += modulo;
ll x = base, cnt = power, ans = 1LL;
while (cnt) {
if (cnt & 1LL)
ans = (ans * x) % modulo;
x = (x * x) % modulo;
cnt >>= 1LL;
}
// int tmp=ans;
return ans;
}
inline ll inv(ll base, ll modulo = modd) {
return fast_expo(base, modulo - 2LL, modulo);
}
signed main() {
#ifdef _SUBLIME
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif
fio;
int n;
cin >> n;
n = n % 1000;
n = (1000 - n) % n;
d1(n);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(), (v).end()
#define sz(v) (v).size()
// #define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout << (x) << " "
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define d5(a, b, c, d, e) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << endl
#define d6(a, b, c, d, e, f) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << " " \
<< (f) << endl
bool desc_sort(const int &lhs, const int &rhs) { return lhs > rhs; }
bool desc_pii_sort(const pii &lhs, const pii &rhs) { return lhs > rhs; }
bool second_sort(const pii &lhs, const pii &rhs) {
pii a, b;
a.F = lhs.S;
a.S = lhs.F;
b.F = rhs.S;
b.S = rhs.F;
return a < b;
}
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.F << ":" << m.S << ") ";
return os << "}";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << 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 trace(...)
#endif
// #define int long long
#define modd 1e0
inline ll fast_expo(ll base, ll power, ll modulo = modd) {
base %= modulo;
if (base < 0LL)
base += modulo;
ll x = base, cnt = power, ans = 1LL;
while (cnt) {
if (cnt & 1LL)
ans = (ans * x) % modulo;
x = (x * x) % modulo;
cnt >>= 1LL;
}
// int tmp=ans;
return ans;
}
inline ll inv(ll base, ll modulo = modd) {
return fast_expo(base, modulo - 2LL, modulo);
}
signed main() {
#ifdef _SUBLIME
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif
fio;
int n;
cin >> n;
n = n % 1000;
n = 1000 - n;
n = n % 1000;
d1(n);
return 0;
} | replace | 107 | 108 | 107 | 109 | 0 | |
p02612 | C++ | Time Limit Exceeded | #define LOCAL
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <stdbool.h>
#define io() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << ":" << x << endl;
#define show2(x, y) cout << (#x) << ":" << x << " " << (#y) << ":" << y << endl;
#define ll long long
#define ld long double
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, set<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T, class R> ostream &operator<<(ostream &os, map<T, R> V) {
os << "[ ";
for (auto v : V)
os << "(" << v.first << ":" << v.second << ")";
return os << "]";
}
template <class T, class R> ostream &operator<<(ostream &os, pair<T, R> V) {
return os << "(" << V.first << "," << V.second << ")";
}
#define cerr cout
#ifdef LOCAL
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << "T->";
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
cerr << "T->";
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
clock_t clk = clock();
#define checktime() \
cout << "\nTime Elapsed : " << float(clock() - clk) / CLOCKS_PER_SEC << endl
#else
#define trace(...) ;
#define checktime() ;
#endif
#define d0(x) cout << (x) << " "
#define d1(x) cout << (x) << "\n"
#define d2(x, y) cout << (x) << " " << (y) << "\n"
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define d4(a, b, c, d) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << "\n"
#define d5(a, b, c, d, e) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << "\n"
#define d6(a, b, c, d, e, f) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << " " \
<< (f) << "\n"
#define print(a) \
for (auto x : a) \
cout << x << " "; \
cout << "\n";
// Use max({a,b,c,d,....}) instead
// #define max3(a,b,c) max(max((a),(b)),(c))
// #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
void solve() {
int n;
cin >> n;
int x = n;
int c = 0;
while (true) {
if (x % 1000 == 0) {
break;
}
c++;
}
cout << c << endl;
}
int main() {
io();
// int t;
// cin >> t;
// rep(i,0,t){
solve();
//}
return 0;
} | #define LOCAL
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <stdbool.h>
#define io() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << ":" << x << endl;
#define show2(x, y) cout << (#x) << ":" << x << " " << (#y) << ":" << y << endl;
#define ll long long
#define ld long double
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, set<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T, class R> ostream &operator<<(ostream &os, map<T, R> V) {
os << "[ ";
for (auto v : V)
os << "(" << v.first << ":" << v.second << ")";
return os << "]";
}
template <class T, class R> ostream &operator<<(ostream &os, pair<T, R> V) {
return os << "(" << V.first << "," << V.second << ")";
}
#define cerr cout
#ifdef LOCAL
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << "T->";
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
cerr << "T->";
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
clock_t clk = clock();
#define checktime() \
cout << "\nTime Elapsed : " << float(clock() - clk) / CLOCKS_PER_SEC << endl
#else
#define trace(...) ;
#define checktime() ;
#endif
#define d0(x) cout << (x) << " "
#define d1(x) cout << (x) << "\n"
#define d2(x, y) cout << (x) << " " << (y) << "\n"
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define d4(a, b, c, d) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << "\n"
#define d5(a, b, c, d, e) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << "\n"
#define d6(a, b, c, d, e, f) \
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << " " \
<< (f) << "\n"
#define print(a) \
for (auto x : a) \
cout << x << " "; \
cout << "\n";
// Use max({a,b,c,d,....}) instead
// #define max3(a,b,c) max(max((a),(b)),(c))
// #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
void solve() {
int n;
cin >> n;
int x = n;
int c = 0;
while (true) {
if (x % 1000 == 0) {
break;
}
c++;
x++;
}
cout << c << endl;
}
int main() {
io();
// int t;
// cin >> t;
// rep(i,0,t){
solve();
//}
return 0;
} | insert | 99 | 99 | 99 | 100 | TLE | |
p02612 | C++ | Runtime Error | /// You just can't beat the person who never gives up
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
bool Never_give_up() {
cin >> n;
cout << (n + 999) / 1000 * 1000 - n << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// scanf("%d",&t);
while (t--)
Never_give_up();
return 0;
} | /// You just can't beat the person who never gives up
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
bool Never_give_up() {
cin >> n;
cout << (n + 999) / 1000 * 1000 - n << endl;
return 0;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// scanf("%d",&t);
while (t--)
Never_give_up();
return 0;
} | insert | 13 | 13 | 13 | 14 | 0 | |
p02613 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main() {
int N;
char tmp;
scanf("%d%c", &N, &tmp);
int ac = 0, wa = 0, tle = 0, re = 0;
char *s;
for (int i = 0; i < N; i++) {
fgets(s, 5, stdin);
if (!strcmp(s, "AC\n"))
ac++;
if (!strcmp(s, "WA\n"))
wa++;
if (!strcmp(s, "TLE\n"))
tle++;
if (!strcmp(s, "RE\n"))
re++;
}
printf("AC x %d\n", ac);
printf("WA x %d\n", wa);
printf("TLE x %d\n", tle);
printf("RE x %d\n", re);
return 0;
} | #include <stdio.h>
#include <string.h>
int main() {
int N;
char tmp;
scanf("%d%c", &N, &tmp);
int ac = 0, wa = 0, tle = 0, re = 0;
char s[5];
for (int i = 0; i < N; i++) {
fgets(s, 5, stdin);
if (!strcmp(s, "AC\n"))
ac++;
if (!strcmp(s, "WA\n"))
wa++;
if (!strcmp(s, "TLE\n"))
tle++;
if (!strcmp(s, "RE\n"))
re++;
}
printf("AC x %d\n", ac);
printf("WA x %d\n", wa);
printf("TLE x %d\n", tle);
printf("RE x %d\n", re);
return 0;
} | replace | 9 | 10 | 9 | 10 | -11 | |
p02613 | Python | Runtime Error | n = input()
s = [input() for _ in range(n)]
print("AC x ", s.count("AC"))
print("WA x ", s.count("WA"))
print("TLE x ", s.count("TLE"))
print("RE x ", s.count("RE"))
| n = int(input())
s = [input() for _ in range(n)]
print("AC x ", s.count("AC"))
print("WA x ", s.count("WA"))
print("TLE x ", s.count("TLE"))
print("RE x ", s.count("RE"))
| replace | 0 | 1 | 0 | 1 | TypeError: 'str' object cannot be interpreted as an integer | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02613/Python/s682758054.py", line 3, in <module>
s = [input() for _ in range(n)]
TypeError: 'str' object cannot be interpreted as an integer
|
p02613 | Python | Runtime Error | N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
while True:
ia = input()
if ia == "AC":
ac += 1
elif ia == "WA":
wa += 1
elif ia == "TLE":
tle += 1
elif ia == "RE":
re += 1
else:
break
print(
f"""\
AC x {ac}
WA x {wa}
TLE x {tle}
RE x {re}"""
)
| N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for x in range(N):
ia = input()
if ia == "AC":
ac += 1
elif ia == "WA":
wa += 1
elif ia == "TLE":
tle += 1
elif ia == "RE":
re += 1
else:
break
print(
f"""\
AC x {ac}
WA x {wa}
TLE x {tle}
RE x {re}"""
)
| replace | 5 | 6 | 5 | 6 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02613/Python/s899780656.py", line 7, in <module>
ia = input()
EOFError: EOF when reading a line
|
p02613 | Python | Runtime Error | N = int(input())
a = [input() for i in range(N)]
c0 = a.count("AC")
c1 = a.count("WA")
c2 = a.count("TLE")
c3 = a.count("RE")
print("AC × " + c0)
print("WA × " + c1)
print("TLE × " + c2)
print("RE × " + c3)
| N = int(input())
a = [input() for i in range(N)]
c0 = a.count("AC")
c1 = a.count("WA")
c2 = a.count("TLE")
c3 = a.count("RE")
print("AC x", c0)
print("WA x", c1)
print("TLE x", c2)
print("RE x", c3)
| replace | 6 | 10 | 6 | 10 | TypeError: can only concatenate str (not "int") to str | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02613/Python/s511049207.py", line 7, in <module>
print("AC × " + c0)
TypeError: can only concatenate str (not "int") to str
|
p02613 | Python | Runtime Error | n = int(input())
verdict = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(n):
S = input()
verdict[S.upper()] += 1
for i, j in verdict:
print(f"{i} x {j}")
| n = int(input())
verdict = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(n):
S = input()
verdict[S.upper()] += 1
for i, j in verdict.items():
print(f"{i} x {j}")
| replace | 6 | 7 | 6 | 7 | ValueError: too many values to unpack (expected 2) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02613/Python/s165324473.py", line 7, in <module>
for i, j in verdict:
ValueError: too many values to unpack (expected 2)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.