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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02670 | C++ | Runtime Error | #include <stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline char CH() {
static char buf[100000], *ptr1 = buf, *ptr2 = buf;
return ptr1 == ptr2 && (ptr2 = (ptr1 = buf) + fread(buf, 1, 100000, stdin),
ptr1 == ptr2)
? EOF
: *ptr1++;
}
static inline int IN(void) {
int x = 0, f = 0, c = CH();
while (c < 48 || c > 57) {
f ^= c == 45, c = CH();
}
while (c > 47 && c < 58) {
x = x * 10 + c - 48, c = CH();
}
return f ? -x : x;
}
static inline void OUT(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
OUT(x / 10);
putchar(x % 10 + 48);
}
static inline int min(const int a, const int b) { return a < b ? a : b; }
int main(void) {
int N = IN(), a = 0, across, d, down, p, q, xy, que[250000], vacant[252525],
dist[252525];
rep(i, N) {
xy = (N + 2) * (i + 1) + 1;
across = min(i, N - 1 - i), down = 3;
rep(j, across) { dist[xy++] = down++; }
rep(j, N - 2 * across) { dist[xy++] = across + 3; }
rep(j, across) { dist[xy++] = --down; }
}
rep(k, N * N) {
xy = IN();
xy += (xy - 1) / N * 2 + N + 2;
a += dist[xy];
p = 0, q = 0;
que[p++] = xy;
vacant[xy] = 1;
while (p > q) {
xy = que[q++], d = dist[xy] - vacant[xy] + 1;
if (dist[xy - N - 2] > d) {
dist[xy - N - 2] = d;
que[p++] = xy - N - 2;
}
if (dist[xy + N + 2] > d) {
dist[xy + N + 2] = d;
que[p++] = xy + N + 2;
}
if (dist[xy - 1] > d) {
dist[xy - 1] = d;
que[p++] = xy - 1;
}
if (dist[xy + 1] > d) {
dist[xy + 1] = d;
que[p++] = xy + 1;
}
}
}
OUT(a - 3 * N * N);
return puts(""), 0;
} | #include <stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline char CH() {
static char buf[100000], *ptr1 = buf, *ptr2 = buf;
return ptr1 == ptr2 && (ptr2 = (ptr1 = buf) + fread(buf, 1, 100000, stdin),
ptr1 == ptr2)
? EOF
: *ptr1++;
}
static inline int IN(void) {
int x = 0, f = 0, c = CH();
while (c < 48 || c > 57) {
f ^= c == 45, c = CH();
}
while (c > 47 && c < 58) {
x = x * 10 + c - 48, c = CH();
}
return f ? -x : x;
}
static inline void OUT(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
OUT(x / 10);
putchar(x % 10 + 48);
}
static inline int min(const int a, const int b) { return a < b ? a : b; }
int main(void) {
int N = IN(), a = 0, across, d, down, p, q, xy, que[251502], vacant[252525],
dist[252525];
rep(i, N) {
xy = (N + 2) * (i + 1) + 1;
across = min(i, N - 1 - i), down = 3;
rep(j, across) { dist[xy++] = down++; }
rep(j, N - 2 * across) { dist[xy++] = across + 3; }
rep(j, across) { dist[xy++] = --down; }
}
rep(k, N * N) {
xy = IN();
xy += (xy - 1) / N * 2 + N + 2;
a += dist[xy];
p = 0, q = 0;
que[p++] = xy;
vacant[xy] = 1;
while (p > q) {
xy = que[q++], d = dist[xy] - vacant[xy] + 1;
if (dist[xy - N - 2] > d) {
dist[xy - N - 2] = d;
que[p++] = xy - N - 2;
}
if (dist[xy + N + 2] > d) {
dist[xy + N + 2] = d;
que[p++] = xy + N + 2;
}
if (dist[xy - 1] > d) {
dist[xy - 1] = d;
que[p++] = xy - 1;
}
if (dist[xy + 1] > d) {
dist[xy + 1] = d;
que[p++] = xy + 1;
}
}
}
OUT(a - 3 * N * N);
return puts(""), 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02670 | C++ | Runtime Error | #include <stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline char CH() {
static char buf[100000], *ptr1 = buf, *ptr2 = buf;
return ptr1 == ptr2 && (ptr2 = (ptr1 = buf) + fread(buf, 1, 100000, stdin),
ptr1 == ptr2)
? EOF
: *ptr1++;
}
static inline int IN(void) {
int x = 0, f = 0, c = CH();
while (c < 48 || c > 57) {
f ^= c == 45, c = CH();
}
while (c > 47 && c < 58) {
x = x * 10 + c - 48, c = CH();
}
return f ? -x : x;
}
static inline void OUT(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
OUT(x / 10);
putchar(x % 10 + 48);
}
static inline int min(const int a, const int b) { return a < b ? a : b; }
int main(void) {
int N = IN(), a = 0, d, p, q, xy, que[125000], vacant[262144];
unsigned char dist[262144];
rep(i, N) {
xy = (N + 2) * (i + 1) + 1;
unsigned char across = min(i, N - 1 - i), down = 3;
rep(j, across) { dist[xy++] = down++; }
rep(j, N - 2 * across) { dist[xy++] = across + 3; }
rep(j, across) { dist[xy++] = --down; }
}
rep(i, N * N) {
xy = IN();
xy += ((xy - 1) / N) * 2 + N + 2;
a += dist[xy];
p = 0, q = 0;
que[p++] = xy;
vacant[xy] = 1;
while (p > q) {
xy = que[q++], d = dist[xy] - vacant[xy] + 1;
if (dist[xy - N - 2] > d) {
dist[xy - N - 2] = d;
que[p++] = xy - N - 2;
}
if (dist[xy + N + 2] > d) {
dist[xy + N + 2] = d;
que[p++] = xy + N + 2;
}
if (dist[xy - 1] > d) {
dist[xy - 1] = d;
que[p++] = xy - 1;
}
if (dist[xy + 1] > d) {
dist[xy + 1] = d;
que[p++] = xy + 1;
}
}
}
OUT(a - 3 * N * N);
return puts(""), 0;
} | #include <stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline char CH() {
static char buf[100000], *ptr1 = buf, *ptr2 = buf;
return ptr1 == ptr2 && (ptr2 = (ptr1 = buf) + fread(buf, 1, 100000, stdin),
ptr1 == ptr2)
? EOF
: *ptr1++;
}
static inline int IN(void) {
int x = 0, f = 0, c = CH();
while (c < 48 || c > 57) {
f ^= c == 45, c = CH();
}
while (c > 47 && c < 58) {
x = x * 10 + c - 48, c = CH();
}
return f ? -x : x;
}
static inline void OUT(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
OUT(x / 10);
putchar(x % 10 + 48);
}
static inline int min(const int a, const int b) { return a < b ? a : b; }
int main(void) {
int N = IN(), a = 0, d, p, q, xy, que[250000], vacant[262144];
unsigned char dist[262144];
rep(i, N) {
xy = (N + 2) * (i + 1) + 1;
unsigned char across = min(i, N - 1 - i), down = 3;
rep(j, across) { dist[xy++] = down++; }
rep(j, N - 2 * across) { dist[xy++] = across + 3; }
rep(j, across) { dist[xy++] = --down; }
}
rep(i, N * N) {
xy = IN();
xy += ((xy - 1) / N) * 2 + N + 2;
a += dist[xy];
p = 0, q = 0;
que[p++] = xy;
vacant[xy] = 1;
while (p > q) {
xy = que[q++], d = dist[xy] - vacant[xy] + 1;
if (dist[xy - N - 2] > d) {
dist[xy - N - 2] = d;
que[p++] = xy - N - 2;
}
if (dist[xy + N + 2] > d) {
dist[xy + N + 2] = d;
que[p++] = xy + N + 2;
}
if (dist[xy - 1] > d) {
dist[xy - 1] = d;
que[p++] = xy - 1;
}
if (dist[xy + 1] > d) {
dist[xy + 1] = d;
que[p++] = xy + 1;
}
}
}
OUT(a - 3 * N * N);
return puts(""), 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02670 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o << 1)
#define rs (o << 1 | 1)
#define pb push_back
const double PI = acos(-1.0);
const int M = 500 + 7;
int x[M], y[M];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int vs[M][M]; // i,j位置当前时刻 是否还有人
int d[M][M]; // i,j位置的人,最快离开剧场所需要的时间
struct node {
int x, y;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n * n; i++) {
int z;
cin >> z;
x[i] = (z - 1) / n + 1;
y[i] = (z - 1) % n + 1;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i][j] = min(min(i - 1, n - i), min(j - 1, n - j)), vs[i][j] = 1;
int ans = 0;
for (int i = 1; i <= n * n; i++) {
ans += d[x[i]][y[i]];
vs[x[i]][y[i]] = 0;
queue<node> q;
q.push(node{x[i], y[i]});
while (q.size()) {
node tp = q.front();
q.pop();
int tx = tp.x, ty = tp.y;
for (int j = 0; j < 4; j++) {
int px = tx + dx[j], py = ty + dy[j];
if (px < 1 || px > n || py < 1 || py > n ||
d[tx][ty] + vs[tx][ty] >= d[px][py])
continue; // px,py 先到 tx,ty 是否更优,如果不优没必要拓展下去
d[px][py] = d[tx][ty] + vs[tx][ty];
q.push(node{px, py});
}
}
// cout<<i<<" "<<x[i]<<" "<<y[i]<<"-----"<<endl;
// for(int j=1;j<=n;j++)
// for(int k=1;k<=n;k++)
// {
// cout<<d[j][k]<<" ";
// if(k==n)cout<<endl;
// }
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o << 1)
#define rs (o << 1 | 1)
#define pb push_back
const double PI = acos(-1.0);
const int M = 500 + 7;
int x[M * M], y[M * M];
int dx[10] = {-1, 1, 0, 0}, dy[10] = {0, 0, -1, 1};
int vs[M][M]; // i,j位置当前时刻 是否还有人
int d[M][M]; // i,j位置的人,最快离开剧场所需要的时间
struct node {
int x, y;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n * n; i++) {
int z;
cin >> z;
x[i] = (z - 1) / n + 1;
y[i] = (z - 1) % n + 1;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i][j] = min(min(i - 1, n - i), min(j - 1, n - j)), vs[i][j] = 1;
int ans = 0;
for (int i = 1; i <= n * n; i++) {
ans += d[x[i]][y[i]];
vs[x[i]][y[i]] = 0;
queue<node> q;
q.push(node{x[i], y[i]});
while (q.size()) {
node tp = q.front();
q.pop();
int tx = tp.x, ty = tp.y;
for (int j = 0; j < 4; j++) {
int px = tx + dx[j], py = ty + dy[j];
if (px < 1 || px > n || py < 1 || py > n ||
d[tx][ty] + vs[tx][ty] >= d[px][py])
continue; // px,py 先到 tx,ty 是否更优,如果不优没必要拓展下去
d[px][py] = d[tx][ty] + vs[tx][ty];
q.push(node{px, py});
}
}
// cout<<i<<" "<<x[i]<<" "<<y[i]<<"-----"<<endl;
// for(int j=1;j<=n;j++)
// for(int k=1;k<=n;k++)
// {
// cout<<d[j][k]<<" ";
// if(k==n)cout<<endl;
// }
}
cout << ans << endl;
return 0;
} | replace | 9 | 11 | 9 | 11 | 0 | |
p02670 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define MAXN 100100
#define ll long long
ll n, m, a[510][510], dis[510][510], p[50100], ans;
void dfs(ll x, ll y) {
if (dis[x - 1][y] > dis[x][y] + a[x][y]) {
dis[x - 1][y] = dis[x][y] + a[x][y];
dfs(x - 1, y);
}
if (dis[x][y - 1] > dis[x][y] + a[x][y]) {
dis[x][y - 1] = dis[x][y] + a[x][y];
dfs(x, y - 1);
}
if (dis[x + 1][y] > dis[x][y] + a[x][y]) {
dis[x + 1][y] = dis[x][y] + a[x][y];
dfs(x + 1, y);
}
if (dis[x][y + 1] > dis[x][y] + a[x][y]) {
dis[x][y + 1] = dis[x][y] + a[x][y];
dfs(x, y + 1);
}
}
int main() {
scanf("%lld", &n);
for (ll i = 1; i <= n * n; i++)
scanf("%lld", &p[i]);
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
a[i][j] = 1;
dis[i][j] = min(i - 1, min(j - 1, min(n - i, n - j)));
}
}
int x, y;
for (ll i = 1; i <= n * n; i++) {
y = p[i] % n;
if (y == 0)
y = n;
x = (p[i] - y) / n + 1;
ans += dis[x][y];
a[x][y] = 0;
dfs(x, y);
}
printf("%lld\n", ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define MAXN 100100
#define ll long long
ll n, m, a[510][510], dis[510][510], p[500100], ans;
void dfs(ll x, ll y) {
if (dis[x - 1][y] > dis[x][y] + a[x][y]) {
dis[x - 1][y] = dis[x][y] + a[x][y];
dfs(x - 1, y);
}
if (dis[x][y - 1] > dis[x][y] + a[x][y]) {
dis[x][y - 1] = dis[x][y] + a[x][y];
dfs(x, y - 1);
}
if (dis[x + 1][y] > dis[x][y] + a[x][y]) {
dis[x + 1][y] = dis[x][y] + a[x][y];
dfs(x + 1, y);
}
if (dis[x][y + 1] > dis[x][y] + a[x][y]) {
dis[x][y + 1] = dis[x][y] + a[x][y];
dfs(x, y + 1);
}
}
int main() {
scanf("%lld", &n);
for (ll i = 1; i <= n * n; i++)
scanf("%lld", &p[i]);
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
a[i][j] = 1;
dis[i][j] = min(i - 1, min(j - 1, min(n - i, n - j)));
}
}
int x, y;
for (ll i = 1; i <= n * n; i++) {
y = p[i] % n;
if (y == 0)
y = n;
x = (p[i] - y) / n + 1;
ans += dis[x][y];
a[x][y] = 0;
dfs(x, y);
}
printf("%lld\n", ans);
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 600005;
int n, rt, cnt, ind, pw[N], ch[N][3], tg[N], val[N], ans[N];
char s[N];
void bud(int &k1, int k2, int k3) {
k1 = ++cnt;
if (k2 == n) {
val[k1] = k3;
return;
}
rep(i, 0, 2) bud(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
void pst(int k1) {
if (!ch[k1][0])
return;
swap(ch[k1][1], ch[k1][2]);
tg[k1] ^= 1;
}
void psd(int k1) {
if (!ch[k1][0])
return;
if (tg[k1]) {
pst(ch[k1][0]);
pst(ch[k1][1]);
pst(ch[k1][2]);
tg[k1] ^= 1;
}
}
void go(int k1) {
if (!ch[k1][0])
return;
psd(k1);
int t = ch[k1][2];
ch[k1][2] = ch[k1][1], ch[k1][1] = ch[k1][0], ch[k1][0] = t;
go(ch[k1][0]);
}
void dfs(int k1, int k2, int k3) {
if (k2 == n) {
ans[val[k1]] = k3;
return;
}
psd(k1);
rep(i, 0, 2) dfs(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
int main() {
scanf("%d%s", &n, s);
pw[0] = 1;
rep(i, 1, n) pw[i] = pw[i - 1] * 3;
bud(rt, 0, 0);
for (int i = 0; s[i]; ++i) {
if (s[i] == 'S')
pst(rt);
else
go(rt);
}
dfs(rt, 0, 0);
rep(i, 0, pw[n] - 1) printf("%d ", ans[i]);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 1800005;
int n, rt, cnt, ind, pw[N], ch[N][3], tg[N], val[N], ans[N];
char s[N];
void bud(int &k1, int k2, int k3) {
k1 = ++cnt;
if (k2 == n) {
val[k1] = k3;
return;
}
rep(i, 0, 2) bud(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
void pst(int k1) {
if (!ch[k1][0])
return;
swap(ch[k1][1], ch[k1][2]);
tg[k1] ^= 1;
}
void psd(int k1) {
if (!ch[k1][0])
return;
if (tg[k1]) {
pst(ch[k1][0]);
pst(ch[k1][1]);
pst(ch[k1][2]);
tg[k1] ^= 1;
}
}
void go(int k1) {
if (!ch[k1][0])
return;
psd(k1);
int t = ch[k1][2];
ch[k1][2] = ch[k1][1], ch[k1][1] = ch[k1][0], ch[k1][0] = t;
go(ch[k1][0]);
}
void dfs(int k1, int k2, int k3) {
if (k2 == n) {
ans[val[k1]] = k3;
return;
}
psd(k1);
rep(i, 0, 2) dfs(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
int main() {
scanf("%d%s", &n, s);
pw[0] = 1;
rep(i, 1, n) pw[i] = pw[i - 1] * 3;
bud(rt, 0, 0);
for (int i = 0; s[i]; ++i) {
if (s[i] == 'S')
pst(rt);
else
go(rt);
}
dfs(rt, 0, 0);
rep(i, 0, pw[n] - 1) printf("%d ", ans[i]);
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02671 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int LL;
typedef pair<int, int> P;
typedef pair<LL, int> LP;
const int INF = 1 << 30;
const LL MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(LL *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<LL> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
vector<vector<int>> v1[15];
vector<vector<int>> vs;
int main() {
int n, m;
int i, j, k;
int a, b, c;
a = 0;
string sa;
cin >> n;
cin >> sa;
v1[0].push_back(vector<int>());
for (i = 0; i < sa.size(); i++) {
if (sa[i] == 'R')
a++;
else if (i + 1 < sa.size() && sa[i + 1] == 'S')
i++;
else {
v1[0][0].push_back(a);
a = 0;
}
}
v1[0][0].push_back(a);
vs.push_back(vector<int>(1, 0));
for (i = 0; i < n; i++) {
c = pow(3, i);
vs.push_back(vector<int>());
for (j = 0; j < v1[i].size(); j++) {
for (k = 0; k < 3; k++) {
v1[i + 1].push_back(vector<int>());
a = k;
int cnt = 0;
for (auto node : v1[i][j]) {
if (cnt && a > 0)
a = 3 - a;
a += node, cnt++;
b = a / 3;
a %= 3;
v1[i + 1].back().push_back(b);
/*
if(b==0 && !v1[i+1].back().empty() && v1[i+1].back().back()==0){
v1[i+1].back().pop_back();
}else v1[i+1].back().push_back(b);*/
}
vs[i + 1].push_back(vs[i][j] + c * a);
}
}
}
c = pow(3, n);
vector<int> v2(c, -1);
vector<int> vt(n, 0);
for (i = 0; i < c; i++) {
a = 0;
for (j = 0; j < n; j++) {
if (vt[j] >= 3)
vt[j] -= 3, vt[j + 1]++;
a *= 3;
a += vt[j];
}
v2[a] = vs[n][i];
vt[0]++;
}
array_show(v2);
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int LL;
typedef pair<int, int> P;
typedef pair<LL, int> LP;
const int INF = 1 << 30;
const LL MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(LL *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<LL> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
vector<vector<int>> v1[15];
vector<vector<int>> vs;
int main() {
int n, m;
int i, j, k;
int a, b, c;
a = 0;
string sa;
cin >> n;
cin >> sa;
v1[0].push_back(vector<int>());
for (i = 0; i < sa.size(); i++) {
if (sa[i] == 'R')
a++;
else if (i + 1 < sa.size() && sa[i + 1] == 'S')
i++;
else {
v1[0][0].push_back(a);
a = 0;
}
}
v1[0][0].push_back(a);
vs.push_back(vector<int>(1, 0));
for (i = 0; i < n; i++) {
c = pow(3, i);
vs.push_back(vector<int>());
for (j = 0; j < v1[i].size(); j++) {
for (k = 0; k < 3; k++) {
v1[i + 1].push_back(vector<int>());
a = k;
int cnt = 0;
for (auto node : v1[i][j]) {
if (cnt && a > 0)
a = 3 - a;
a += node, cnt++;
b = a / 3;
a %= 3;
if (b == 0 && !v1[i + 1].back().empty() &&
v1[i + 1].back().back() == 0 && cnt != v1[i][j].size()) {
v1[i + 1].back().pop_back();
} else
v1[i + 1].back().push_back(b);
}
vs[i + 1].push_back(vs[i][j] + c * a);
}
}
}
c = pow(3, n);
vector<int> v2(c, -1);
vector<int> vt(n, 0);
for (i = 0; i < c; i++) {
a = 0;
for (j = 0; j < n; j++) {
if (vt[j] >= 3)
vt[j] -= 3, vt[j + 1]++;
a *= 3;
a += vt[j];
}
v2[a] = vs[n][i];
vt[0]++;
}
array_show(v2);
} | replace | 80 | 85 | 80 | 85 | TLE | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxN = 6e5 + 10;
int n, len, cnt, root;
int ch[maxN + 1][3], a[maxN + 1];
int rev[maxN + 1], pw[15], ans[maxN + 1];
char s[maxN + 1];
inline void reverse(int x) {
if (!x)
return;
swap(ch[x][1], ch[x][2]);
rev[x] ^= 1;
}
inline void pushdown(int x) {
if (!rev[x])
return;
reverse(ch[x][0]);
reverse(ch[x][1]);
reverse(ch[x][2]);
rev[x] = 0;
}
inline void insert(int &node, int x, int k) {
if (!node)
node = ++cnt;
if (k == n) {
a[node] = x;
return;
}
int d = x / pw[k] % 3;
insert(ch[node][d], x, k + 1);
}
inline void change(int node) {
if (!node)
return;
pushdown(node);
change(ch[node][2]);
swap(ch[node][1], ch[node][2]);
swap(ch[node][0], ch[node][1]);
}
inline void dfs(int node, int k, int x) {
if (!node)
return;
if (k == n) {
ans[a[node]] = x;
return;
}
pushdown(node);
dfs(ch[node][0], k + 1, x);
dfs(ch[node][1], k + 1, x + pw[k]);
dfs(ch[node][2], k + 1, x + 2 * pw[k]);
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
len = strlen(s + 1);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 3;
for (int i = 0; i < pw[n]; i++)
insert(root, i, 0);
for (int i = 1; i <= len; i++)
if (s[i] == 'S')
reverse(root);
else
change(root);
dfs(root, 0, 0);
for (int i = 0; i < pw[n]; i++)
printf("%d ", ans[i]);
puts("");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxN = 2e6 + 10;
int n, len, cnt, root;
int ch[maxN + 1][3], a[maxN + 1];
int rev[maxN + 1], pw[15], ans[maxN + 1];
char s[maxN + 1];
inline void reverse(int x) {
if (!x)
return;
swap(ch[x][1], ch[x][2]);
rev[x] ^= 1;
}
inline void pushdown(int x) {
if (!rev[x])
return;
reverse(ch[x][0]);
reverse(ch[x][1]);
reverse(ch[x][2]);
rev[x] = 0;
}
inline void insert(int &node, int x, int k) {
if (!node)
node = ++cnt;
if (k == n) {
a[node] = x;
return;
}
int d = x / pw[k] % 3;
insert(ch[node][d], x, k + 1);
}
inline void change(int node) {
if (!node)
return;
pushdown(node);
change(ch[node][2]);
swap(ch[node][1], ch[node][2]);
swap(ch[node][0], ch[node][1]);
}
inline void dfs(int node, int k, int x) {
if (!node)
return;
if (k == n) {
ans[a[node]] = x;
return;
}
pushdown(node);
dfs(ch[node][0], k + 1, x);
dfs(ch[node][1], k + 1, x + pw[k]);
dfs(ch[node][2], k + 1, x + 2 * pw[k]);
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
len = strlen(s + 1);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 3;
for (int i = 0; i < pw[n]; i++)
insert(root, i, 0);
for (int i = 1; i <= len; i++)
if (s[i] == 'S')
reverse(root);
else
change(root);
dfs(root, 0, 0);
for (int i = 0; i < pw[n]; i++)
printf("%d ", ans[i]);
puts("");
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02671 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
using namespace std;
const int maxn = 6e5;
int n, m, tot, val[maxn + 5], ch[maxn + 5][3], cnt, res[maxn + 5];
bool sal[maxn + 5];
char s[maxn + 5];
int dfs(int k, int t, int s) {
int x = ++tot;
if (!k)
return val[x] = s, x;
ch[x][0] = dfs(k - 1, t * 3, s);
ch[x][1] = dfs(k - 1, t * 3, s + t);
ch[x][2] = dfs(k - 1, t * 3, s + t * 2);
return x;
}
void salsa(int x) { sal[x] ^= 1, swap(ch[x][1], ch[x][2]); }
void push_down(int x) {
if (sal[x]) {
rep(i, 0, 2) salsa(ch[x][i]);
sal[x] = false;
}
}
void rumba(int x) {
if (!ch[x][0])
return;
push_down(x);
int t = ch[x][0];
ch[x][0] = ch[x][2];
ch[x][2] = ch[x][1];
ch[x][1] = t;
rumba(ch[x][0]);
}
void work(int x, int t, int s) {
if (!ch[x][0]) {
res[val[x]] = s, cnt++;
return;
}
push_down(x);
rep(i, 0, 2) work(ch[x][i], t * 3, s + i * t);
}
int main() {
scanf("%d %s", &n, s + 1);
m = strlen(s + 1);
dfs(n, 1, 0);
rep(i, 1, m) {
if (s[i] == 'S')
salsa(1);
else
rumba(1);
}
work(1, 1, 0);
rep(i, 0, cnt - 1) printf("%d%c", res[i], " \n"[i == cnt - 1]);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
using namespace std;
const int maxn = 8e5;
int n, m, tot, val[maxn + 5], ch[maxn + 5][3], cnt, res[maxn + 5];
bool sal[maxn + 5];
char s[maxn + 5];
int dfs(int k, int t, int s) {
int x = ++tot;
if (!k)
return val[x] = s, x;
ch[x][0] = dfs(k - 1, t * 3, s);
ch[x][1] = dfs(k - 1, t * 3, s + t);
ch[x][2] = dfs(k - 1, t * 3, s + t * 2);
return x;
}
void salsa(int x) { sal[x] ^= 1, swap(ch[x][1], ch[x][2]); }
void push_down(int x) {
if (sal[x]) {
rep(i, 0, 2) salsa(ch[x][i]);
sal[x] = false;
}
}
void rumba(int x) {
if (!ch[x][0])
return;
push_down(x);
int t = ch[x][0];
ch[x][0] = ch[x][2];
ch[x][2] = ch[x][1];
ch[x][1] = t;
rumba(ch[x][0]);
}
void work(int x, int t, int s) {
if (!ch[x][0]) {
res[val[x]] = s, cnt++;
return;
}
push_down(x);
rep(i, 0, 2) work(ch[x][i], t * 3, s + i * t);
}
int main() {
scanf("%d %s", &n, s + 1);
m = strlen(s + 1);
dfs(n, 1, 0);
rep(i, 1, m) {
if (s[i] == 'S')
salsa(1);
else
rumba(1);
}
work(1, 1, 0);
rep(i, 0, cnt - 1) printf("%d%c", res[i], " \n"[i == cnt - 1]);
return 0;
} | replace | 4 | 5 | 4 | 5 | TLE | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
const int N = 601000;
int n, pw[20], pos[N];
char s[N];
struct node {
node *s[3];
int lab;
bool rev;
void setr() {
rev ^= 1;
swap(s[1], s[2]);
}
void push() {
if (rev) {
rep(j, 0, 3) if (s[j]) s[j]->setr();
rev = 0;
}
}
} pool[N], *cur = pool, *rt;
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 3;
rt = cur++;
rep(i, 0, pw[n]) {
node *p = rt;
rep(j, 0, n) {
int w = i / pw[j] % 3;
if (!p->s[w])
p->s[w] = cur++;
p = p->s[w];
}
p->lab = i;
}
scanf("%s", s);
int m = strlen(s);
rep(i, 0, m) if (s[i] == 'S') { rt->setr(); }
else {
node *p = rt;
rep(j, 0, n) {
p->push();
node *t = p->s[2];
p->s[2] = p->s[1];
p->s[1] = p->s[0];
p->s[0] = t;
p = p->s[0];
}
}
rep(i, 0, pw[n]) {
node *p = rt;
rep(j, 0, n) {
int w = i / pw[j] % 3;
p->push();
p = p->s[w];
}
// printf("zz %d\n",p-cur);
pos[p->lab] = i;
// printf("%d ",p->lab);
}
rep(i, 0, pw[n]) printf("%d%c", pos[i], " \n"[i == pw[n] - 1]);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
const int N = 1001000;
int n, pw[20], pos[N];
char s[N];
struct node {
node *s[3];
int lab;
bool rev;
void setr() {
rev ^= 1;
swap(s[1], s[2]);
}
void push() {
if (rev) {
rep(j, 0, 3) if (s[j]) s[j]->setr();
rev = 0;
}
}
} pool[N], *cur = pool, *rt;
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 3;
rt = cur++;
rep(i, 0, pw[n]) {
node *p = rt;
rep(j, 0, n) {
int w = i / pw[j] % 3;
if (!p->s[w])
p->s[w] = cur++;
p = p->s[w];
}
p->lab = i;
}
scanf("%s", s);
int m = strlen(s);
rep(i, 0, m) if (s[i] == 'S') { rt->setr(); }
else {
node *p = rt;
rep(j, 0, n) {
p->push();
node *t = p->s[2];
p->s[2] = p->s[1];
p->s[1] = p->s[0];
p->s[0] = t;
p = p->s[0];
}
}
rep(i, 0, pw[n]) {
node *p = rt;
rep(j, 0, n) {
int w = i / pw[j] % 3;
p->push();
p = p->s[w];
}
// printf("zz %d\n",p-cur);
pos[p->lab] = i;
// printf("%d ",p->lab);
}
rep(i, 0, pw[n]) printf("%d%c", pos[i], " \n"[i == pw[n] - 1]);
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 555555;
#define MP make_pair
#define PB push_back
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
inline ll read() {
char ch = getchar();
ll x = 0, f = 0;
while (ch < '0' || ch > '9')
f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int n, m, q, rt, cnt, ch[maxn][3], id[maxn], ans[maxn];
bool rev[maxn];
char s[maxn];
inline void setrev(int x) {
rev[x] ^= 1;
swap(ch[x][1], ch[x][2]);
}
inline void pushdown(int x) {
if (rev[x]) {
if (ch[x][0])
setrev(ch[x][0]);
if (ch[x][1])
setrev(ch[x][1]);
if (ch[x][2])
setrev(ch[x][2]);
rev[x] = false;
}
}
void build(int &x, int dep, int cur, int pr) {
x = ++cnt;
if (dep == n) {
id[x] = cur;
return;
}
build(ch[x][0], dep + 1, cur, pr * 3);
build(ch[x][1], dep + 1, cur + pr, pr * 3);
build(ch[x][2], dep + 1, cur + pr * 2, pr * 3);
}
void add(int x, int dep) {
pushdown(x);
if (dep == n)
return;
swap(ch[x][1], ch[x][2]);
swap(ch[x][0], ch[x][1]);
add(ch[x][0], dep + 1);
}
void dfs(int x, int dep, int cur, int pr) {
pushdown(x);
if (dep == n) {
ans[id[x]] = cur;
return;
}
dfs(ch[x][0], dep + 1, cur, pr * 3);
dfs(ch[x][1], dep + 1, cur + pr, pr * 3);
dfs(ch[x][2], dep + 1, cur + pr * 2, pr * 3);
}
int main() {
n = read();
build(rt, 0, 0, 1);
scanf("%s", s + 1);
q = strlen(s + 1);
FOR(i, 1, q) if (s[i] == 'S') setrev(rt);
else add(rt, 0);
dfs(rt, 0, 0, 1);
m = 1;
FOR(i, 1, n) m *= 3;
FOR(i, 0, m - 1) printf("%d ", ans[i]);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 888888;
#define MP make_pair
#define PB push_back
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
inline ll read() {
char ch = getchar();
ll x = 0, f = 0;
while (ch < '0' || ch > '9')
f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int n, m, q, rt, cnt, ch[maxn][3], id[maxn], ans[maxn];
bool rev[maxn];
char s[maxn];
inline void setrev(int x) {
rev[x] ^= 1;
swap(ch[x][1], ch[x][2]);
}
inline void pushdown(int x) {
if (rev[x]) {
if (ch[x][0])
setrev(ch[x][0]);
if (ch[x][1])
setrev(ch[x][1]);
if (ch[x][2])
setrev(ch[x][2]);
rev[x] = false;
}
}
void build(int &x, int dep, int cur, int pr) {
x = ++cnt;
if (dep == n) {
id[x] = cur;
return;
}
build(ch[x][0], dep + 1, cur, pr * 3);
build(ch[x][1], dep + 1, cur + pr, pr * 3);
build(ch[x][2], dep + 1, cur + pr * 2, pr * 3);
}
void add(int x, int dep) {
pushdown(x);
if (dep == n)
return;
swap(ch[x][1], ch[x][2]);
swap(ch[x][0], ch[x][1]);
add(ch[x][0], dep + 1);
}
void dfs(int x, int dep, int cur, int pr) {
pushdown(x);
if (dep == n) {
ans[id[x]] = cur;
return;
}
dfs(ch[x][0], dep + 1, cur, pr * 3);
dfs(ch[x][1], dep + 1, cur + pr, pr * 3);
dfs(ch[x][2], dep + 1, cur + pr * 2, pr * 3);
}
int main() {
n = read();
build(rt, 0, 0, 1);
scanf("%s", s + 1);
q = strlen(s + 1);
FOR(i, 1, q) if (s[i] == 'S') setrev(rt);
else add(rt, 0);
dfs(rt, 0, 0, 1);
m = 1;
FOR(i, 1, n) m *= 3;
FOR(i, 0, m - 1) printf("%d ", ans[i]);
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAXN 13
#define MAXM 500005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
string str;
int ans[MAXM];
int curdigit[MAXN], curres[MAXN];
string reduce(string &t) {
vector<char> st;
string ret = "";
for (auto ch : t) {
st.push_back(ch);
if (st.size() >= 2 && st[(int)st.size() - 1] == 'S' &&
st[(int)st.size() - 2] == 'S')
st.pop_back(), st.pop_back();
}
for (auto ch : st)
ret += ch;
return ret;
}
void update_ans() {
int x = 0, y = 0;
for (int i = n - 1; i >= 0; i--) {
x = x * 3 + curdigit[i];
y = y * 3 + curres[i];
}
ans[x] = y;
}
void solve(int cur, string t) {
if (cur == n) {
update_ans();
return;
}
for (int d = 0; d < 3; d++) {
string curt = "";
int curd = d;
for (auto ch : t) {
if (ch == 'S') {
if (curd)
curd = 3 - curd;
curt += 'S';
}
if (ch == 'R') {
curd++;
if (curd == 3) {
curd = 0;
curt += 'R';
}
}
}
curdigit[cur] = d;
curres[cur] = curd;
solve(cur + 1, reduce(curt));
}
}
int main() {
scanf("%d", &n);
cin >> str;
solve(0, reduce(str));
int p = 1;
for (int i = 0; i < n; i++)
p = p * 3;
for (int i = 0; i < p; i++)
printf("%d ", ans[i]);
return 0;
} | #include <bits/stdc++.h>
#define MAXN 13
#define MAXM 550005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
string str;
int ans[MAXM];
int curdigit[MAXN], curres[MAXN];
string reduce(string &t) {
vector<char> st;
string ret = "";
for (auto ch : t) {
st.push_back(ch);
if (st.size() >= 2 && st[(int)st.size() - 1] == 'S' &&
st[(int)st.size() - 2] == 'S')
st.pop_back(), st.pop_back();
}
for (auto ch : st)
ret += ch;
return ret;
}
void update_ans() {
int x = 0, y = 0;
for (int i = n - 1; i >= 0; i--) {
x = x * 3 + curdigit[i];
y = y * 3 + curres[i];
}
ans[x] = y;
}
void solve(int cur, string t) {
if (cur == n) {
update_ans();
return;
}
for (int d = 0; d < 3; d++) {
string curt = "";
int curd = d;
for (auto ch : t) {
if (ch == 'S') {
if (curd)
curd = 3 - curd;
curt += 'S';
}
if (ch == 'R') {
curd++;
if (curd == 3) {
curd = 0;
curt += 'R';
}
}
}
curdigit[cur] = d;
curres[cur] = curd;
solve(cur + 1, reduce(curt));
}
}
int main() {
scanf("%d", &n);
cin >> str;
solve(0, reduce(str));
int p = 1;
for (int i = 0; i < n; i++)
p = p * 3;
for (int i = 0; i < p; i++)
printf("%d ", ans[i]);
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define For(i, x, y) for (register int i = (x); i <= (y); i++)
#define FOR(i, x, y) for (register int i = (x); i < (y); i++)
#define Dow(i, x, y) for (register int i = (x); i >= (y); i--)
#define Debug(v) \
for (auto i : v) \
printf("%lld ", i); \
puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fil(a, b) memset((a), (b), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pa;
typedef pair<ll, ll> PA;
typedef vector<int> poly;
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 550010;
int n, m, pw[N];
char s[N];
int cnt, son[N][3], p[N];
inline void dfs(int u, int dep, int x) {
if (dep == n)
return p[u] = x, void(0);
son[u][0] = ++cnt, dfs(son[u][0], dep + 1, x);
son[u][1] = ++cnt, dfs(son[u][1], dep + 1, x + pw[dep]);
son[u][2] = ++cnt, dfs(son[u][2], dep + 1, x + 2 * pw[dep]);
}
int tag[N];
inline void upd(int u) { swap(son[u][1], son[u][2]), tag[u] ^= 1; }
inline void push_down(int u) {
if (!tag[u])
return;
FOR(i, 0, 3) upd(son[u][i]);
tag[u] = 0;
}
inline void dfs(int u, int dep) {
if (dep == n)
return;
push_down(u);
int tmp = son[u][2];
son[u][2] = son[u][1], son[u][1] = son[u][0], son[u][0] = tmp;
dfs(son[u][0], dep + 1);
}
int ans[N];
inline void print(int u, int dep, int x) {
if (dep == n)
return ans[p[u]] = x, void(0);
push_down(u);
print(son[u][0], dep + 1, x);
print(son[u][1], dep + 1, x + pw[dep]);
print(son[u][2], dep + 1, x + 2 * pw[dep]);
}
int main() {
n = read(), scanf("%s", s + 1), m = strlen(s + 1);
pw[0] = 1;
For(i, 1, n) pw[i] = pw[i - 1] * 3;
dfs(0, 0, 0);
For(i, 1, m) {
if (s[i] == 'S')
upd(0);
else
dfs(0, 0);
}
print(0, 0, 0);
FOR(i, 0, pw[n]) printf("%d ", ans[i]);
} | #include <bits/stdc++.h>
#define For(i, x, y) for (register int i = (x); i <= (y); i++)
#define FOR(i, x, y) for (register int i = (x); i < (y); i++)
#define Dow(i, x, y) for (register int i = (x); i >= (y); i--)
#define Debug(v) \
for (auto i : v) \
printf("%lld ", i); \
puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fil(a, b) memset((a), (b), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pa;
typedef pair<ll, ll> PA;
typedef vector<int> poly;
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 3e6 + 10;
int n, m, pw[N];
char s[N];
int cnt, son[N][3], p[N];
inline void dfs(int u, int dep, int x) {
if (dep == n)
return p[u] = x, void(0);
son[u][0] = ++cnt, dfs(son[u][0], dep + 1, x);
son[u][1] = ++cnt, dfs(son[u][1], dep + 1, x + pw[dep]);
son[u][2] = ++cnt, dfs(son[u][2], dep + 1, x + 2 * pw[dep]);
}
int tag[N];
inline void upd(int u) { swap(son[u][1], son[u][2]), tag[u] ^= 1; }
inline void push_down(int u) {
if (!tag[u])
return;
FOR(i, 0, 3) upd(son[u][i]);
tag[u] = 0;
}
inline void dfs(int u, int dep) {
if (dep == n)
return;
push_down(u);
int tmp = son[u][2];
son[u][2] = son[u][1], son[u][1] = son[u][0], son[u][0] = tmp;
dfs(son[u][0], dep + 1);
}
int ans[N];
inline void print(int u, int dep, int x) {
if (dep == n)
return ans[p[u]] = x, void(0);
push_down(u);
print(son[u][0], dep + 1, x);
print(son[u][1], dep + 1, x + pw[dep]);
print(son[u][2], dep + 1, x + 2 * pw[dep]);
}
int main() {
n = read(), scanf("%s", s + 1), m = strlen(s + 1);
pw[0] = 1;
For(i, 1, n) pw[i] = pw[i - 1] * 3;
dfs(0, 0, 0);
For(i, 1, m) {
if (s[i] == 'S')
upd(0);
else
dfs(0, 0);
}
print(0, 0, 0);
FOR(i, 0, pw[n]) printf("%d ", ans[i]);
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02671 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
int ret = 0, t = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-')
c = getchar();
if (c == '-')
t = -1, c = getchar();
while (c >= '0' && c <= '9')
ret = ret * 10 + c - '0', c = getchar();
return ret * t;
}
#define PR pair<int, int>
#define MP make_pair
#define TO first
#define NUM second
int n;
const int MAXN = 600600;
struct tree {
PR s[3];
int val;
bool lazy;
} t[MAXN];
int top = 1;
void build(int x, int st, int tmp, int val) {
if (st == n) {
t[x].val = val;
return;
}
t[x].s[0] = MP(++top, 0);
build(t[x].s[0].TO, st + 1, tmp * 3, val + tmp * 0);
t[x].s[1] = MP(++top, 1);
build(t[x].s[1].TO, st + 1, tmp * 3, val + tmp * 1);
t[x].s[2] = MP(++top, 2);
build(t[x].s[2].TO, st + 1, tmp * 3, val + tmp * 2);
}
PR fnd(int x) {
int u, v;
if (t[x].s[0].NUM == 1)
u = 0;
if (t[x].s[1].NUM == 1)
u = 1;
if (t[x].s[2].NUM == 1)
u = 2;
if (t[x].s[0].NUM == 2)
v = 0;
if (t[x].s[1].NUM == 2)
v = 1;
if (t[x].s[2].NUM == 2)
v = 2;
return MP(u, v);
}
void pushdown(int x) {
if (!t[x].lazy)
return;
t[x].lazy = false;
for (int i = 0; i < 3; i++) {
PR tmp = fnd(t[x].s[i].TO);
int rua = t[x].s[i].TO;
swap(t[rua].s[tmp.first].NUM, t[rua].s[tmp.second].NUM);
}
t[t[x].s[0].TO].lazy ^= 1, t[t[x].s[1].TO].lazy ^= 1,
t[t[x].s[2].TO].lazy ^= 1;
}
void mod1(int x) {
if (!t[x].s[0].TO)
return;
pushdown(x);
++t[x].s[0].NUM, ++t[x].s[1].NUM, ++t[x].s[2].NUM;
if (t[x].s[0].NUM == 3)
t[x].s[0].NUM = 0, mod1(t[x].s[0].TO);
if (t[x].s[1].NUM == 3)
t[x].s[1].NUM = 0, mod1(t[x].s[1].TO);
if (t[x].s[2].NUM == 3)
t[x].s[2].NUM = 0, mod1(t[x].s[2].TO);
}
void mod2(int x) {
if (!t[x].s[0].TO)
return;
PR tmp = fnd(x);
swap(t[x].s[tmp.first].NUM, t[x].s[tmp.second].NUM);
t[x].lazy ^= 1;
}
int ans[MAXN];
void query(int x, int st, int val) {
if (!t[x].s[0].TO) {
ans[t[x].val] = val;
return;
}
pushdown(x);
query(t[x].s[0].TO, st * 3, val + st * t[x].s[0].NUM);
query(t[x].s[1].TO, st * 3, val + st * t[x].s[1].NUM);
query(t[x].s[2].TO, st * 3, val + st * t[x].s[2].NUM);
}
int main() {
n = read();
build(1, 0, 1, 0);
char c = getchar();
while (c != 'S' && c != 'R')
c = getchar();
while (c == 'S' || c == 'R') {
if (c == 'S')
mod2(1);
else
mod1(1);
c = getchar();
}
query(1, 1, 0);
int tmp = 1;
while (n--)
tmp *= 3;
for (int i = 0; i < tmp; i++)
printf("%d ", ans[i]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
int ret = 0, t = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-')
c = getchar();
if (c == '-')
t = -1, c = getchar();
while (c >= '0' && c <= '9')
ret = ret * 10 + c - '0', c = getchar();
return ret * t;
}
#define PR pair<int, int>
#define MP make_pair
#define TO first
#define NUM second
int n;
const int MAXN = 2002000;
struct tree {
PR s[3];
int val;
bool lazy;
} t[MAXN];
int top = 1;
void build(int x, int st, int tmp, int val) {
if (st == n) {
t[x].val = val;
return;
}
t[x].s[0] = MP(++top, 0);
build(t[x].s[0].TO, st + 1, tmp * 3, val + tmp * 0);
t[x].s[1] = MP(++top, 1);
build(t[x].s[1].TO, st + 1, tmp * 3, val + tmp * 1);
t[x].s[2] = MP(++top, 2);
build(t[x].s[2].TO, st + 1, tmp * 3, val + tmp * 2);
}
PR fnd(int x) {
int u, v;
if (t[x].s[0].NUM == 1)
u = 0;
if (t[x].s[1].NUM == 1)
u = 1;
if (t[x].s[2].NUM == 1)
u = 2;
if (t[x].s[0].NUM == 2)
v = 0;
if (t[x].s[1].NUM == 2)
v = 1;
if (t[x].s[2].NUM == 2)
v = 2;
return MP(u, v);
}
void pushdown(int x) {
if (!t[x].lazy)
return;
t[x].lazy = false;
for (int i = 0; i < 3; i++) {
PR tmp = fnd(t[x].s[i].TO);
int rua = t[x].s[i].TO;
swap(t[rua].s[tmp.first].NUM, t[rua].s[tmp.second].NUM);
}
t[t[x].s[0].TO].lazy ^= 1, t[t[x].s[1].TO].lazy ^= 1,
t[t[x].s[2].TO].lazy ^= 1;
}
void mod1(int x) {
if (!t[x].s[0].TO)
return;
pushdown(x);
++t[x].s[0].NUM, ++t[x].s[1].NUM, ++t[x].s[2].NUM;
if (t[x].s[0].NUM == 3)
t[x].s[0].NUM = 0, mod1(t[x].s[0].TO);
if (t[x].s[1].NUM == 3)
t[x].s[1].NUM = 0, mod1(t[x].s[1].TO);
if (t[x].s[2].NUM == 3)
t[x].s[2].NUM = 0, mod1(t[x].s[2].TO);
}
void mod2(int x) {
if (!t[x].s[0].TO)
return;
PR tmp = fnd(x);
swap(t[x].s[tmp.first].NUM, t[x].s[tmp.second].NUM);
t[x].lazy ^= 1;
}
int ans[MAXN];
void query(int x, int st, int val) {
if (!t[x].s[0].TO) {
ans[t[x].val] = val;
return;
}
pushdown(x);
query(t[x].s[0].TO, st * 3, val + st * t[x].s[0].NUM);
query(t[x].s[1].TO, st * 3, val + st * t[x].s[1].NUM);
query(t[x].s[2].TO, st * 3, val + st * t[x].s[2].NUM);
}
int main() {
n = read();
build(1, 0, 1, 0);
char c = getchar();
while (c != 'S' && c != 'R')
c = getchar();
while (c == 'S' || c == 'R') {
if (c == 'S')
mod2(1);
else
mod1(1);
c = getchar();
}
query(1, 1, 0);
int tmp = 1;
while (n--)
tmp *= 3;
for (int i = 0; i < tmp; i++)
printf("%d ", ans[i]);
return 0;
} | replace | 25 | 26 | 25 | 26 | -11 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase \
int T; \
cin >> T; \
for (int t = 1; t <= T; t++) { \
solve(t); \
}
// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type, op, val) bind(op<type>(), std::placeholders::_1, val)
const int MAXN = 1e6 + 10;
void solve(int tt) {
// cout<<"Case #"<<tt<<": ";
}
string to_ter(int x, int k = -1) {
string res;
while (x) {
res += '0' + x % 3;
x /= 3;
}
if (k >= 0) {
while (res.size() < k)
res += '0';
}
return res;
}
int to_int(const string &s) {
int res = 0;
// rrep(i,s.size()-1,-1)
// res=res*3+(s[i]-'0');
for (int i = s.size() - 1; i >= 0; i--)
res = res * 3 + (s[i] - '0');
// print(s,res);
return res;
}
bool add(string &x, const string &y) {
int n1 = x.size(), n2 = y.size(), carry = 0;
rep(i, 0, n1) {
if (i < n1)
carry += x[i] - '0';
if (i < n2)
carry += y[i] - '0';
x[i] = carry % 3 + '0';
carry /= 3;
}
return carry == 0;
}
vi cal_inst(string &s) {
int n = s.size();
vi res(1);
int i = 0;
while (i < n) {
if (s[i] == 'R') {
res.back()++;
i++;
} else {
int j = i;
for (; j < n && s[j] == 'S'; j++)
;
if ((j - i) % 2)
res.pb(0);
i = j;
}
}
if (s.back() == 'S')
res.pop_back();
return res;
}
char rev(char c) {
if (c > '0')
return '0' + (3 - (c - '0'));
return c;
}
string rev(string s) {
for (auto &c : s)
c = rev(c);
return s;
}
int len(string &s) {
int res = s.size() - 1;
while (res >= 0 && s[res] == '0')
res--;
return res + 1;
}
int power[13] = {};
int revmap[MAXN] = {};
int tmpres[MAXN];
int rev(int x) {
for (int flag = 1; flag < power[12]; flag *= 3) {
int tmp = x / flag % 3;
if (tmp == 1)
x += flag;
else if (tmp == 2)
x -= flag;
}
return x;
}
void cal(vi inst, int n, int tot) {
// vi tmpres(tot,-1);
fill(tmpres, tmpres + tot, -1);
rep(i, 0, tot) {
if (tmpres[i] >= 0)
continue;
int cur = i, ok = 1;
for (auto x : inst) {
cur += x;
if (cur >= power[n]) {
ok = 0;
cur %= power[n];
}
cur = revmap[cur];
}
// if(i<=9) print(i,cur);
tmpres[i] = cur;
// assert(cur>=0);
if (!ok)
continue;
int flag = 1, tmp;
for (; flag <= i || flag <= cur; flag *= 3)
;
if (inst.size() % 2 == 0) {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = tmp + cur;
}
} else {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = revmap[tmp] + cur;
}
}
}
// print(1);
// print(*max_element(all(res)),*min_element(all(res)));
// return res;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// solve_testcase;
int n;
string s;
cin >> n;
cin >> s;
// n=12;
// rep(i,0,1e5) s+="RS";
power[0] = 1;
rep(i, 1, 13) power[i] = power[i - 1] * 3;
int tot = 1;
rep(i, 0, n) tot *= 3;
rep(i, 0, tot) {
if (i >= 3) {
if (i % 3 == 0)
revmap[i] = revmap[i / 3] * 3;
else
revmap[i] = revmap[i - i % 3] + rev(i % 3);
} else
revmap[i] = rev(i);
}
// printn(revmap,9);
vi inst = cal_inst(s);
for (auto &x : inst)
x %= tot;
// print(inst);
int i = 0;
int bound = 241;
vi res(tot);
iota(all(res), 0);
while (i < inst.size()) {
int cur = inst[i];
vi cur_inst({cur});
for (++i; i < inst.size() < bound; i++) {
cur += inst[i];
cur_inst.pb(inst[i]);
}
cal(cur_inst, n, tot);
// print(tmp);
rep(j, 0, tot) res[j] = tmpres[res[j]];
// print(cur_inst,tmp);
// print(res);
// sort(all(tmp)); print(tmp);
}
if (s.back() == 'R') {
rep(i, 0, tot) { res[i] = revmap[res[i]]; }
}
for (auto x : res)
cout << x << ' ';
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase \
int T; \
cin >> T; \
for (int t = 1; t <= T; t++) { \
solve(t); \
}
// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type, op, val) bind(op<type>(), std::placeholders::_1, val)
const int MAXN = 1e6 + 10;
void solve(int tt) {
// cout<<"Case #"<<tt<<": ";
}
string to_ter(int x, int k = -1) {
string res;
while (x) {
res += '0' + x % 3;
x /= 3;
}
if (k >= 0) {
while (res.size() < k)
res += '0';
}
return res;
}
int to_int(const string &s) {
int res = 0;
// rrep(i,s.size()-1,-1)
// res=res*3+(s[i]-'0');
for (int i = s.size() - 1; i >= 0; i--)
res = res * 3 + (s[i] - '0');
// print(s,res);
return res;
}
bool add(string &x, const string &y) {
int n1 = x.size(), n2 = y.size(), carry = 0;
rep(i, 0, n1) {
if (i < n1)
carry += x[i] - '0';
if (i < n2)
carry += y[i] - '0';
x[i] = carry % 3 + '0';
carry /= 3;
}
return carry == 0;
}
vi cal_inst(string &s) {
int n = s.size();
vi res(1);
int i = 0;
while (i < n) {
if (s[i] == 'R') {
res.back()++;
i++;
} else {
int j = i;
for (; j < n && s[j] == 'S'; j++)
;
if ((j - i) % 2)
res.pb(0);
i = j;
}
}
if (s.back() == 'S')
res.pop_back();
return res;
}
char rev(char c) {
if (c > '0')
return '0' + (3 - (c - '0'));
return c;
}
string rev(string s) {
for (auto &c : s)
c = rev(c);
return s;
}
int len(string &s) {
int res = s.size() - 1;
while (res >= 0 && s[res] == '0')
res--;
return res + 1;
}
int power[13] = {};
int revmap[MAXN] = {};
int tmpres[MAXN];
int rev(int x) {
for (int flag = 1; flag < power[12]; flag *= 3) {
int tmp = x / flag % 3;
if (tmp == 1)
x += flag;
else if (tmp == 2)
x -= flag;
}
return x;
}
void cal(vi inst, int n, int tot) {
// vi tmpres(tot,-1);
fill(tmpres, tmpres + tot, -1);
rep(i, 0, tot) {
if (tmpres[i] >= 0)
continue;
int cur = i, ok = 1;
for (auto x : inst) {
cur += x;
if (cur >= power[n]) {
ok = 0;
cur %= power[n];
}
cur = revmap[cur];
}
// if(i<=9) print(i,cur);
tmpres[i] = cur;
// assert(cur>=0);
if (!ok)
continue;
int flag = 1, tmp;
for (; flag <= i || flag <= cur; flag *= 3)
;
if (inst.size() % 2 == 0) {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = tmp + cur;
}
} else {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = revmap[tmp] + cur;
}
}
}
// print(1);
// print(*max_element(all(res)),*min_element(all(res)));
// return res;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// solve_testcase;
int n;
string s;
cin >> n;
cin >> s;
// n=12;
// rep(i,0,1e5) s+="RS";
power[0] = 1;
rep(i, 1, 13) power[i] = power[i - 1] * 3;
int tot = 1;
rep(i, 0, n) tot *= 3;
rep(i, 0, tot) {
if (i >= 3) {
if (i % 3 == 0)
revmap[i] = revmap[i / 3] * 3;
else
revmap[i] = revmap[i - i % 3] + rev(i % 3);
} else
revmap[i] = rev(i);
}
// printn(revmap,9);
vi inst = cal_inst(s);
for (auto &x : inst)
x %= tot;
// print(inst);
int i = 0;
int bound = 241;
vi res(tot);
iota(all(res), 0);
while (i < inst.size()) {
int cur = inst[i];
vi cur_inst({cur});
for (++i; i < inst.size() && cur < bound; i++) {
cur += inst[i];
cur_inst.pb(inst[i]);
}
cal(cur_inst, n, tot);
// print(tmp);
rep(j, 0, tot) res[j] = tmpres[res[j]];
// print(cur_inst,tmp);
// print(res);
// sort(all(tmp)); print(tmp);
}
if (s.back() == 'R') {
rep(i, 0, tot) { res[i] = revmap[res[i]]; }
}
for (auto x : res)
cout << x << ' ';
cout << endl;
return 0;
}
| replace | 231 | 232 | 231 | 232 | -11 | |
p02671 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase \
int T; \
cin >> T; \
for (int t = 1; t <= T; t++) { \
solve(t); \
}
// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type, op, val) bind(op<type>(), std::placeholders::_1, val)
const int MAXN = 1e6 + 10;
void solve(int tt) {
// cout<<"Case #"<<tt<<": ";
}
string to_ter(int x, int k = -1) {
string res;
while (x) {
res += '0' + x % 3;
x /= 3;
}
if (k >= 0) {
while (res.size() < k)
res += '0';
}
return res;
}
int to_int(const string &s) {
int res = 0;
// rrep(i,s.size()-1,-1)
// res=res*3+(s[i]-'0');
for (int i = s.size() - 1; i >= 0; i--)
res = res * 3 + (s[i] - '0');
// print(s,res);
return res;
}
bool add(string &x, const string &y) {
int n1 = x.size(), n2 = y.size(), carry = 0;
rep(i, 0, n1) {
if (i < n1)
carry += x[i] - '0';
if (i < n2)
carry += y[i] - '0';
x[i] = carry % 3 + '0';
carry /= 3;
}
return carry == 0;
}
vi cal_inst(string &s) {
int n = s.size();
vi res(1);
int i = 0;
while (i < n) {
if (s[i] == 'R') {
res.back()++;
i++;
} else {
int j = i;
for (; j < n && s[j] == 'S'; j++)
;
if ((j - i) % 2)
res.pb(0);
i = j;
}
}
if (s.back() == 'S')
res.pop_back();
return res;
}
char rev(char c) {
if (c > '0')
return '0' + (3 - (c - '0'));
return c;
}
string rev(string s) {
for (auto &c : s)
c = rev(c);
return s;
}
int len(string &s) {
int res = s.size() - 1;
while (res >= 0 && s[res] == '0')
res--;
return res + 1;
}
int power[13] = {};
int revmap[MAXN] = {};
int tmpres[MAXN];
int rev(int x) {
for (int flag = 1; flag < power[12]; flag *= 3) {
int tmp = x / flag % 3;
if (tmp == 1)
x += flag;
else if (tmp == 2)
x -= flag;
}
return x;
}
void cal(vi inst, int n, int tot) {
// vi tmpres(tot,-1);
fill(tmpres, tmpres + tot, -1);
rep(i, 0, tot) {
if (tmpres[i] >= 0)
continue;
int cur = i, ok = 1;
for (auto x : inst) {
cur += x;
if (cur >= power[n]) {
ok = 0;
cur %= power[n];
}
cur = revmap[cur];
}
// if(i<=9) print(i,cur);
tmpres[i] = cur;
// assert(cur>=0);
if (!ok)
continue;
int flag = 1, tmp;
for (; flag <= i || flag <= cur; flag *= 3)
;
if (inst.size() % 2 == 0) {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = tmp + cur;
}
} else {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = revmap[tmp] + cur;
}
}
}
// print(1);
// print(*max_element(all(res)),*min_element(all(res)));
// return res;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// solve_testcase;
int n;
string s;
cin >> n;
cin >> s;
// n=12;
// rep(i,0,1e5) s+="RS";
power[0] = 1;
rep(i, 1, 13) power[i] = power[i - 1] * 3;
int tot = 1;
rep(i, 0, n) tot *= 3;
rep(i, 0, tot) {
if (i >= 3) {
if (i % 3 == 0)
revmap[i] = revmap[i / 3] * 3;
else
revmap[i] = revmap[i - i % 3] + rev(i % 3);
} else
revmap[i] = rev(i);
}
// printn(revmap,9);
vi inst = cal_inst(s);
for (auto &x : inst)
x %= tot;
// print(inst);
int i = 0;
int bound = 81;
vi res(tot);
iota(all(res), 0);
while (i < inst.size()) {
int cur = inst[i];
vi cur_inst({cur});
for (++i; i < inst.size() && cur + inst[i] < bound; i++) {
cur += inst[i];
cur_inst.pb(inst[i]);
}
cal(cur_inst, n, tot);
// print(tmp);
rep(j, 0, tot) res[j] = tmpres[res[j]];
// print(cur_inst,tmp);
// print(res);
// sort(all(tmp)); print(tmp);
}
if (s.back() == 'R') {
rep(i, 0, tot) { res[i] = revmap[res[i]]; }
}
for (auto x : res)
cout << x << ' ';
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase \
int T; \
cin >> T; \
for (int t = 1; t <= T; t++) { \
solve(t); \
}
// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type, op, val) bind(op<type>(), std::placeholders::_1, val)
const int MAXN = 1e6 + 10;
void solve(int tt) {
// cout<<"Case #"<<tt<<": ";
}
string to_ter(int x, int k = -1) {
string res;
while (x) {
res += '0' + x % 3;
x /= 3;
}
if (k >= 0) {
while (res.size() < k)
res += '0';
}
return res;
}
int to_int(const string &s) {
int res = 0;
// rrep(i,s.size()-1,-1)
// res=res*3+(s[i]-'0');
for (int i = s.size() - 1; i >= 0; i--)
res = res * 3 + (s[i] - '0');
// print(s,res);
return res;
}
bool add(string &x, const string &y) {
int n1 = x.size(), n2 = y.size(), carry = 0;
rep(i, 0, n1) {
if (i < n1)
carry += x[i] - '0';
if (i < n2)
carry += y[i] - '0';
x[i] = carry % 3 + '0';
carry /= 3;
}
return carry == 0;
}
vi cal_inst(string &s) {
int n = s.size();
vi res(1);
int i = 0;
while (i < n) {
if (s[i] == 'R') {
res.back()++;
i++;
} else {
int j = i;
for (; j < n && s[j] == 'S'; j++)
;
if ((j - i) % 2)
res.pb(0);
i = j;
}
}
if (s.back() == 'S')
res.pop_back();
return res;
}
char rev(char c) {
if (c > '0')
return '0' + (3 - (c - '0'));
return c;
}
string rev(string s) {
for (auto &c : s)
c = rev(c);
return s;
}
int len(string &s) {
int res = s.size() - 1;
while (res >= 0 && s[res] == '0')
res--;
return res + 1;
}
int power[13] = {};
int revmap[MAXN] = {};
int tmpres[MAXN];
int rev(int x) {
for (int flag = 1; flag < power[12]; flag *= 3) {
int tmp = x / flag % 3;
if (tmp == 1)
x += flag;
else if (tmp == 2)
x -= flag;
}
return x;
}
void cal(vi inst, int n, int tot) {
// vi tmpres(tot,-1);
fill(tmpres, tmpres + tot, -1);
rep(i, 0, tot) {
if (tmpres[i] >= 0)
continue;
int cur = i, ok = 1;
for (auto x : inst) {
cur += x;
if (cur >= power[n]) {
ok = 0;
cur %= power[n];
}
cur = revmap[cur];
}
// if(i<=9) print(i,cur);
tmpres[i] = cur;
// assert(cur>=0);
if (!ok)
continue;
int flag = 1, tmp;
for (; flag <= i || flag <= cur; flag *= 3)
;
if (inst.size() % 2 == 0) {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = tmp + cur;
}
} else {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = revmap[tmp] + cur;
}
}
}
// print(1);
// print(*max_element(all(res)),*min_element(all(res)));
// return res;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// solve_testcase;
int n;
string s;
cin >> n;
cin >> s;
// n=12;
// rep(i,0,1e5) s+="RS";
power[0] = 1;
rep(i, 1, 13) power[i] = power[i - 1] * 3;
int tot = 1;
rep(i, 0, n) tot *= 3;
rep(i, 0, tot) {
if (i >= 3) {
if (i % 3 == 0)
revmap[i] = revmap[i / 3] * 3;
else
revmap[i] = revmap[i - i % 3] + rev(i % 3);
} else
revmap[i] = rev(i);
}
// printn(revmap,9);
vi inst = cal_inst(s);
for (auto &x : inst)
x %= tot;
// print(inst);
int i = 0;
int bound = 500;
vi res(tot);
iota(all(res), 0);
while (i < inst.size()) {
int cur = inst[i];
vi cur_inst({cur});
for (++i; i < inst.size() && cur + inst[i] < bound; i++) {
cur += inst[i];
cur_inst.pb(inst[i]);
}
cal(cur_inst, n, tot);
// print(tmp);
rep(j, 0, tot) res[j] = tmpres[res[j]];
// print(cur_inst,tmp);
// print(res);
// sort(all(tmp)); print(tmp);
}
if (s.back() == 'R') {
rep(i, 0, tot) { res[i] = revmap[res[i]]; }
}
for (auto x : res)
cout << x << ' ';
cout << endl;
return 0;
}
| replace | 225 | 226 | 225 | 226 | TLE | |
p02671 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase \
int T; \
cin >> T; \
for (int t = 1; t <= T; t++) { \
solve(t); \
}
// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type, op, val) bind(op<type>(), std::placeholders::_1, val)
const int MAXN = 1e6 + 10;
void solve(int tt) {
// cout<<"Case #"<<tt<<": ";
}
string to_ter(int x, int k = -1) {
string res;
while (x) {
res += '0' + x % 3;
x /= 3;
}
if (k >= 0) {
while (res.size() < k)
res += '0';
}
return res;
}
int to_int(const string &s) {
int res = 0;
// rrep(i,s.size()-1,-1)
// res=res*3+(s[i]-'0');
for (int i = s.size() - 1; i >= 0; i--)
res = res * 3 + (s[i] - '0');
// print(s,res);
return res;
}
bool add(string &x, const string &y) {
int n1 = x.size(), n2 = y.size(), carry = 0;
rep(i, 0, n1) {
if (i < n1)
carry += x[i] - '0';
if (i < n2)
carry += y[i] - '0';
x[i] = carry % 3 + '0';
carry /= 3;
}
return carry == 0;
}
vi cal_inst(string &s) {
int n = s.size();
vi res(1);
int i = 0;
while (i < n) {
if (s[i] == 'R') {
res.back()++;
i++;
} else {
int j = i;
for (; j < n && s[j] == 'S'; j++)
;
if ((j - i) % 2)
res.pb(0);
i = j;
}
}
if (s.back() == 'S')
res.pop_back();
return res;
}
char rev(char c) {
if (c > '0')
return '0' + (3 - (c - '0'));
return c;
}
string rev(string s) {
for (auto &c : s)
c = rev(c);
return s;
}
int len(string &s) {
int res = s.size() - 1;
while (res >= 0 && s[res] == '0')
res--;
return res + 1;
}
int power[13] = {};
int revmap[MAXN] = {};
int tmpres[MAXN];
int rev(int x) {
for (int flag = 1; flag < power[12]; flag *= 3) {
int tmp = x / flag % 3;
if (tmp == 1)
x += flag;
else if (tmp == 2)
x -= flag;
}
return x;
}
void cal(vi inst, int n, int tot) {
// vi tmpres(tot,-1);
fill(tmpres, tmpres + tot, -1);
rep(i, 0, tot) {
if (tmpres[i] >= 0)
continue;
int cur = i, ok = 1;
for (auto x : inst) {
cur += x;
if (cur >= power[n]) {
ok = 0;
cur %= power[n];
}
cur = revmap[cur];
}
// if(i<=9) print(i,cur);
tmpres[i] = cur;
// assert(cur>=0);
if (!ok)
continue;
int flag = 1, tmp;
for (; flag <= i || flag <= cur; flag *= 3)
;
if (inst.size() % 2 == 0) {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = tmp + cur;
}
} else {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = revmap[tmp] + cur;
}
}
}
// print(1);
// print(*max_element(all(res)),*min_element(all(res)));
// return res;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// solve_testcase;
int n;
string s;
cin >> n;
cin >> s;
// n=12;
// rep(i,0,1e5) s+="RS";
power[0] = 1;
rep(i, 1, 13) power[i] = power[i - 1] * 3;
int tot = 1;
rep(i, 0, n) tot *= 3;
rep(i, 0, tot) revmap[i] = rev(i);
// printn(revmap,9);
vi inst = cal_inst(s);
for (auto &x : inst)
x %= tot;
// print(inst);
int i = 0;
int bound = 81;
vi res(tot);
iota(all(res), 0);
while (i < inst.size()) {
int cur = inst[i];
vi cur_inst({cur});
for (++i; i < inst.size() && cur + inst[i] < bound; i++) {
cur += inst[i];
cur_inst.pb(inst[i]);
}
cal(cur_inst, n, tot);
// print(tmp);
rep(j, 0, tot) res[j] = tmpres[res[j]];
// print(cur_inst,tmp);
// print(res);
// sort(all(tmp)); print(tmp);
}
if (s.back() == 'R') {
rep(i, 0, tot) { res[i] = to_int(rev(to_ter(res[i], n))); }
}
for (auto x : res)
cout << x << ' ';
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase \
int T; \
cin >> T; \
for (int t = 1; t <= T; t++) { \
solve(t); \
}
// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type, op, val) bind(op<type>(), std::placeholders::_1, val)
const int MAXN = 1e6 + 10;
void solve(int tt) {
// cout<<"Case #"<<tt<<": ";
}
string to_ter(int x, int k = -1) {
string res;
while (x) {
res += '0' + x % 3;
x /= 3;
}
if (k >= 0) {
while (res.size() < k)
res += '0';
}
return res;
}
int to_int(const string &s) {
int res = 0;
// rrep(i,s.size()-1,-1)
// res=res*3+(s[i]-'0');
for (int i = s.size() - 1; i >= 0; i--)
res = res * 3 + (s[i] - '0');
// print(s,res);
return res;
}
bool add(string &x, const string &y) {
int n1 = x.size(), n2 = y.size(), carry = 0;
rep(i, 0, n1) {
if (i < n1)
carry += x[i] - '0';
if (i < n2)
carry += y[i] - '0';
x[i] = carry % 3 + '0';
carry /= 3;
}
return carry == 0;
}
vi cal_inst(string &s) {
int n = s.size();
vi res(1);
int i = 0;
while (i < n) {
if (s[i] == 'R') {
res.back()++;
i++;
} else {
int j = i;
for (; j < n && s[j] == 'S'; j++)
;
if ((j - i) % 2)
res.pb(0);
i = j;
}
}
if (s.back() == 'S')
res.pop_back();
return res;
}
char rev(char c) {
if (c > '0')
return '0' + (3 - (c - '0'));
return c;
}
string rev(string s) {
for (auto &c : s)
c = rev(c);
return s;
}
int len(string &s) {
int res = s.size() - 1;
while (res >= 0 && s[res] == '0')
res--;
return res + 1;
}
int power[13] = {};
int revmap[MAXN] = {};
int tmpres[MAXN];
int rev(int x) {
for (int flag = 1; flag < power[12]; flag *= 3) {
int tmp = x / flag % 3;
if (tmp == 1)
x += flag;
else if (tmp == 2)
x -= flag;
}
return x;
}
void cal(vi inst, int n, int tot) {
// vi tmpres(tot,-1);
fill(tmpres, tmpres + tot, -1);
rep(i, 0, tot) {
if (tmpres[i] >= 0)
continue;
int cur = i, ok = 1;
for (auto x : inst) {
cur += x;
if (cur >= power[n]) {
ok = 0;
cur %= power[n];
}
cur = revmap[cur];
}
// if(i<=9) print(i,cur);
tmpres[i] = cur;
// assert(cur>=0);
if (!ok)
continue;
int flag = 1, tmp;
for (; flag <= i || flag <= cur; flag *= 3)
;
if (inst.size() % 2 == 0) {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = tmp + cur;
}
} else {
for (tmp = flag; tmp < power[n]; tmp += flag) {
tmpres[tmp + i] = revmap[tmp] + cur;
}
}
}
// print(1);
// print(*max_element(all(res)),*min_element(all(res)));
// return res;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// solve_testcase;
int n;
string s;
cin >> n;
cin >> s;
// n=12;
// rep(i,0,1e5) s+="RS";
power[0] = 1;
rep(i, 1, 13) power[i] = power[i - 1] * 3;
int tot = 1;
rep(i, 0, n) tot *= 3;
rep(i, 0, tot) revmap[i] = rev(i);
// printn(revmap,9);
vi inst = cal_inst(s);
for (auto &x : inst)
x %= tot;
// print(inst);
int i = 0;
int bound = 241;
vi res(tot);
iota(all(res), 0);
while (i < inst.size()) {
int cur = inst[i];
vi cur_inst({cur});
for (++i; i < inst.size() && cur + inst[i] < bound; i++) {
cur += inst[i];
cur_inst.pb(inst[i]);
}
cal(cur_inst, n, tot);
// print(tmp);
rep(j, 0, tot) res[j] = tmpres[res[j]];
// print(cur_inst,tmp);
// print(res);
// sort(all(tmp)); print(tmp);
}
if (s.back() == 'R') {
rep(i, 0, tot) { res[i] = to_int(rev(to_ter(res[i], n))); }
}
for (auto x : res)
cout << x << ' ';
cout << endl;
return 0;
}
| replace | 217 | 218 | 217 | 218 | TLE | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG \
fprintf(stderr, "Running on Line %d in Function %s\n", __LINE__, __FUNCTION__)
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read() {
char ch = getchar();
int nega = 1;
while (!isdigit(ch)) {
if (ch == '-')
nega = -1;
ch = getchar();
}
int ans = 0;
while (isdigit(ch)) {
ans = ans * 10 + ch - 48;
ch = getchar();
}
if (nega == -1)
return -ans;
return ans;
}
typedef pair<int, int> pii;
inline int min(int x, int y, int z) { return min(x, min(y, z)); }
inline int max(int x, int y, int z) { return max(x, max(y, z)); }
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int add(int x, int y, int z) { return add(add(x, y), z); }
inline int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline int mul(int x, int y, int z) { return mul(mul(x, y), z); }
#define N 200005
int a[N], t[15][N];
char s[N];
int id[N], n;
void upd(int &x) {
if (x == 1)
x = 2;
else if (x == 2)
x = 1;
}
signed main() {
cin >> n;
scanf("%s", s + 1);
int m = strlen(s + 1);
int cur = 1;
for (int i = 0; i < n; i++) {
cur *= 3;
for (int j = 0; j < cur; j++) {
int x = j;
for (int k = 0; k < i; k++)
x /= 3;
a[j] = x;
}
bool op = 0;
for (int j = 1; j <= m; j++) {
if (s[j] == 'S')
op ^= 1;
else {
int u = id[j], tmp = 0;
for (int k = 0; k < 3; k++) {
int v = k * (cur / 3) + u;
if (op)
upd(a[v]);
if (a[v] == 2)
tmp = k, a[v] = 0;
else
a[v]++;
if (op)
upd(a[v]);
}
id[j] += tmp * (cur / 3);
}
}
if (op)
for (int j = 0; j < cur; j++)
upd(a[j]);
for (int j = 0; j < cur; j++)
t[i][j] = a[j];
// for(int j=1;j<=cur;j++) printf("%d ",t[i][j]);
// cout<<"\n";
}
for (int i = 0; i < cur; i++) {
int ans = 0, tmp = 1;
for (int j = 0; j < n; j++) {
tmp *= 3;
ans += t[j][i % tmp] * (tmp / 3);
}
printf("%d ", ans);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG \
fprintf(stderr, "Running on Line %d in Function %s\n", __LINE__, __FUNCTION__)
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read() {
char ch = getchar();
int nega = 1;
while (!isdigit(ch)) {
if (ch == '-')
nega = -1;
ch = getchar();
}
int ans = 0;
while (isdigit(ch)) {
ans = ans * 10 + ch - 48;
ch = getchar();
}
if (nega == -1)
return -ans;
return ans;
}
typedef pair<int, int> pii;
inline int min(int x, int y, int z) { return min(x, min(y, z)); }
inline int max(int x, int y, int z) { return max(x, max(y, z)); }
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int add(int x, int y, int z) { return add(add(x, y), z); }
inline int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline int mul(int x, int y, int z) { return mul(mul(x, y), z); }
#define N 600005
int a[N], t[15][N];
char s[N];
int id[N], n;
void upd(int &x) {
if (x == 1)
x = 2;
else if (x == 2)
x = 1;
}
signed main() {
cin >> n;
scanf("%s", s + 1);
int m = strlen(s + 1);
int cur = 1;
for (int i = 0; i < n; i++) {
cur *= 3;
for (int j = 0; j < cur; j++) {
int x = j;
for (int k = 0; k < i; k++)
x /= 3;
a[j] = x;
}
bool op = 0;
for (int j = 1; j <= m; j++) {
if (s[j] == 'S')
op ^= 1;
else {
int u = id[j], tmp = 0;
for (int k = 0; k < 3; k++) {
int v = k * (cur / 3) + u;
if (op)
upd(a[v]);
if (a[v] == 2)
tmp = k, a[v] = 0;
else
a[v]++;
if (op)
upd(a[v]);
}
id[j] += tmp * (cur / 3);
}
}
if (op)
for (int j = 0; j < cur; j++)
upd(a[j]);
for (int j = 0; j < cur; j++)
t[i][j] = a[j];
// for(int j=1;j<=cur;j++) printf("%d ",t[i][j]);
// cout<<"\n";
}
for (int i = 0; i < cur; i++) {
int ans = 0, tmp = 1;
for (int j = 0; j < n; j++) {
tmp *= 3;
ans += t[j][i % tmp] * (tmp / 3);
}
printf("%d ", ans);
}
return 0;
}
| replace | 39 | 40 | 39 | 40 | 0 | |
p02671 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define LL long long
#define mp(x, y) make_pair(x, y)
#define pll pair<long long, long long>
#define pii pair<int, int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read() {
LL f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int stack[20];
template <typename T> inline void write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (!x) {
putchar('0');
return;
}
int top = 0;
while (x)
stack[++top] = x % 10, x /= 10;
while (top)
putchar(stack[top--] + '0');
}
template <typename T> inline void pr1(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void pr2(T x) {
write(x);
putchar('\n');
}
template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
const int MAXN = 550005;
const int MAXV = 11;
int bin[15];
int n, m, ans[MAXN];
struct Trie {
int son[MAXN][3], tot, root;
int val[MAXN];
bool rev[MAXN];
void insert(int v) {
int p = root;
for (int i = 0; i <= n - 1; i++) {
int c = v / bin[i];
c %= 3;
if (!son[p][c])
son[p][c] = ++tot;
p = son[p][c];
}
val[p] = v;
}
void down(int p) {
if (!rev[p])
return;
swap(son[p][1], son[p][2]);
rev[son[p][0]] ^= 1;
rev[son[p][1]] ^= 1;
rev[son[p][2]] ^= 1;
rev[p] = 0;
}
void addone(int p, int dep) {
if (dep == 0)
return;
down(p);
int a = son[p][0], b = son[p][1], c = son[p][2];
son[p][0] = c;
son[p][1] = a;
son[p][2] = b;
addone(son[p][0], dep - 1);
}
void getans(int p, int dep, int nowp) {
if (dep == n) {
ans[val[p]] = nowp;
return;
}
down(p);
getans(son[p][0], dep + 1, nowp);
getans(son[p][1], dep + 1, nowp + bin[dep]);
getans(son[p][2], dep + 1, nowp + 2 * bin[dep]);
}
} tr;
char ch[MAXN];
int main() {
#ifdef Rose
double BeginJudgeTime = clock();
#endif
bin[0] = 1;
for (int i = 1; i < 15; i++)
bin[i] = bin[i - 1] * 3;
n = read();
scanf("%s", ch + 1);
m = strlen(ch + 1);
tr.tot = tr.root = 1;
for (int i = 0; i < bin[n]; i++)
tr.insert(i);
for (int i = 1; i <= m; i++) {
if (ch[i] == 'S')
tr.rev[1] ^= 1;
else
tr.addone(1, n);
}
tr.getans(1, 0, 0);
for (int i = 0; i < bin[n]; i++)
pr1(ans[i]);
puts("");
#ifdef Rose
double EndJudgeTime = clock();
cerr << "JudgeTime is"
<< " ";
cerr << (EndJudgeTime - BeginJudgeTime) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define LL long long
#define mp(x, y) make_pair(x, y)
#define pll pair<long long, long long>
#define pii pair<int, int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read() {
LL f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int stack[20];
template <typename T> inline void write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (!x) {
putchar('0');
return;
}
int top = 0;
while (x)
stack[++top] = x % 10, x /= 10;
while (top)
putchar(stack[top--] + '0');
}
template <typename T> inline void pr1(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void pr2(T x) {
write(x);
putchar('\n');
}
template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
const int MAXN = 2e6;
const int MAXV = 13;
int bin[15];
int n, m, ans[MAXN];
struct Trie {
int son[MAXN][3], tot, root;
int val[MAXN];
bool rev[MAXN];
void insert(int v) {
int p = root;
for (int i = 0; i <= n - 1; i++) {
int c = v / bin[i];
c %= 3;
if (!son[p][c])
son[p][c] = ++tot;
p = son[p][c];
}
val[p] = v;
}
void down(int p) {
if (!rev[p])
return;
swap(son[p][1], son[p][2]);
rev[son[p][0]] ^= 1;
rev[son[p][1]] ^= 1;
rev[son[p][2]] ^= 1;
rev[p] = 0;
}
void addone(int p, int dep) {
if (dep == 0)
return;
down(p);
int a = son[p][0], b = son[p][1], c = son[p][2];
son[p][0] = c;
son[p][1] = a;
son[p][2] = b;
addone(son[p][0], dep - 1);
}
void getans(int p, int dep, int nowp) {
if (dep == n) {
ans[val[p]] = nowp;
return;
}
down(p);
getans(son[p][0], dep + 1, nowp);
getans(son[p][1], dep + 1, nowp + bin[dep]);
getans(son[p][2], dep + 1, nowp + 2 * bin[dep]);
}
} tr;
char ch[MAXN];
int main() {
#ifdef Rose
double BeginJudgeTime = clock();
#endif
bin[0] = 1;
for (int i = 1; i < 15; i++)
bin[i] = bin[i - 1] * 3;
n = read();
scanf("%s", ch + 1);
m = strlen(ch + 1);
tr.tot = tr.root = 1;
for (int i = 0; i < bin[n]; i++)
tr.insert(i);
for (int i = 1; i <= m; i++) {
if (ch[i] == 'S')
tr.rev[1] ^= 1;
else
tr.addone(1, n);
}
tr.getans(1, 0, 0);
for (int i = 0; i < bin[n]; i++)
pr1(ans[i]);
puts("");
#ifdef Rose
double EndJudgeTime = clock();
cerr << "JudgeTime is"
<< " ";
cerr << (EndJudgeTime - BeginJudgeTime) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
| replace | 63 | 65 | 63 | 65 | 0 | |
p02671 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #define int long long
#define pii pair<int, int>
#define x1 x1228
#define y1 y1228
#define left left228
#define right right228
#define next next228
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl;
#define TIME (ld) clock() / CLOCKS_PER_SEC
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 2e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int n;
string s;
int next[MAXN];
const int N = 2187;
int dp1[N];
int dp2[N];
int xyz[N];
int get1(int mask, char q) {
if (q == 'R') {
++mask;
return mask;
}
int ptr = 1;
int ans = 0;
while (mask) {
int t = mask % 3;
mask /= 3;
if (t == 2)
ans += ptr;
if (t == 1)
ans += 2 * ptr;
ptr *= 3;
}
return ans;
}
const int L = 12;
int pref[maxn];
int to[maxn];
int kek1[N], kek2[N];
int res[N], res1[N];
int add = 1;
void print(int x) {
while (x) {
cout << x % 3 << " ";
x /= 3;
}
cout << '\n';
}
int get(int x) {
vector<int> bts;
for (int i = 0; i < L; ++i) {
bts.pb(x % 3);
x /= 3;
}
int left = 0;
int right = 0;
for (int i = 6; i >= 0; --i) {
left *= 3;
left += bts[i];
}
for (int i = L - 1; i >= 7; --i) {
right *= 3;
right += bts[i];
}
int id = 0;
if (left && dp1[left] == -1) {
if ((pref[(int)s.size()] - pref[id]) & 1) {
right = xyz[right];
}
return res[left] + add * right;
}
if (left) {
id = dp1[left];
// print(right);
if (pref[id] & 1) {
right = xyz[right];
}
++right;
// print(right);
left = 0;
}
while (next[id] != -1) {
if ((pref[next[id]] - pref[id]) & 1) {
right = xyz[right];
}
right++;
id = next[id];
}
if ((pref[(int)s.size()] - pref[id]) & 1) {
right = xyz[right];
}
left = to[id];
return left + right * add;
}
void solve() {
for (int i = 0; i < N; ++i) {
xyz[i] = get1(i, 'S') % N;
}
cin >> n >> s;
int t = s.size();
for (int i = 0; i < t; ++i) {
pref[i + 1] = pref[i] + (s[i] == 'S');
}
for (int i = 0; i < N; ++i)
dp1[i] = dp2[i] = -1;
next[t] = -1;
for (int i = 0; i < N; ++i)
kek1[i] = i;
for (int i = 0; i < N; ++i)
res[i] = i;
for (int i = t - 1; i >= 0; --i) {
for (int mask = 0; mask < N; ++mask) {
int mask1;
if (s[i] == 'S')
mask1 = xyz[mask];
else
mask1 = mask + 1;
if (mask1 >= N)
mask1 -= N;
res1[mask] = res[mask1];
kek2[mask] = kek1[mask1];
if (mask && mask1 == 0) {
dp2[mask] = i + 1;
} else {
dp2[mask] = dp1[mask1];
}
}
to[i] = kek2[0];
next[i] = dp2[0];
for (int mask = 0; mask < N; ++mask) {
res[mask] = res1[mask];
kek1[mask] = kek2[mask];
dp1[mask] = dp2[mask];
dp2[mask] = -1;
}
}
for (int i = 0; i < 7; ++i)
add *= 3;
int tet = 1;
for (int i = 0; i < n; ++i)
tet *= 3;
for (int ptr = 0; ptr < tet; ++ptr) {
cout << get(ptr) % tet << " ";
}
// cout << TIME;
return;
}
signed main() {
#ifdef LOCAL
freopen("TASK.in", "r", stdin);
freopen("TASK.out", "w", stdout);
#else
#endif // LOCAL
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
cout << fixed;
int t = 1;
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
} | #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
// #define int long long
#define pii pair<int, int>
#define x1 x1228
#define y1 y1228
#define left left228
#define right right228
#define next next228
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl;
#define TIME (ld) clock() / CLOCKS_PER_SEC
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 2e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int n;
string s;
int next[MAXN];
const int N = 2187;
int dp1[N];
int dp2[N];
int xyz[N];
int get1(int mask, char q) {
if (q == 'R') {
++mask;
return mask;
}
int ptr = 1;
int ans = 0;
while (mask) {
int t = mask % 3;
mask /= 3;
if (t == 2)
ans += ptr;
if (t == 1)
ans += 2 * ptr;
ptr *= 3;
}
return ans;
}
const int L = 12;
int pref[maxn];
int to[maxn];
int kek1[N], kek2[N];
int res[N], res1[N];
int add = 1;
void print(int x) {
while (x) {
cout << x % 3 << " ";
x /= 3;
}
cout << '\n';
}
int get(int x) {
vector<int> bts;
for (int i = 0; i < L; ++i) {
bts.pb(x % 3);
x /= 3;
}
int left = 0;
int right = 0;
for (int i = 6; i >= 0; --i) {
left *= 3;
left += bts[i];
}
for (int i = L - 1; i >= 7; --i) {
right *= 3;
right += bts[i];
}
int id = 0;
if (left && dp1[left] == -1) {
if ((pref[(int)s.size()] - pref[id]) & 1) {
right = xyz[right];
}
return res[left] + add * right;
}
if (left) {
id = dp1[left];
// print(right);
if (pref[id] & 1) {
right = xyz[right];
}
++right;
// print(right);
left = 0;
}
while (next[id] != -1) {
if ((pref[next[id]] - pref[id]) & 1) {
right = xyz[right];
}
right++;
id = next[id];
}
if ((pref[(int)s.size()] - pref[id]) & 1) {
right = xyz[right];
}
left = to[id];
return left + right * add;
}
void solve() {
for (int i = 0; i < N; ++i) {
xyz[i] = get1(i, 'S') % N;
}
cin >> n >> s;
int t = s.size();
for (int i = 0; i < t; ++i) {
pref[i + 1] = pref[i] + (s[i] == 'S');
}
for (int i = 0; i < N; ++i)
dp1[i] = dp2[i] = -1;
next[t] = -1;
for (int i = 0; i < N; ++i)
kek1[i] = i;
for (int i = 0; i < N; ++i)
res[i] = i;
for (int i = t - 1; i >= 0; --i) {
for (int mask = 0; mask < N; ++mask) {
int mask1;
if (s[i] == 'S')
mask1 = xyz[mask];
else
mask1 = mask + 1;
if (mask1 >= N)
mask1 -= N;
res1[mask] = res[mask1];
kek2[mask] = kek1[mask1];
if (mask && mask1 == 0) {
dp2[mask] = i + 1;
} else {
dp2[mask] = dp1[mask1];
}
}
to[i] = kek2[0];
next[i] = dp2[0];
for (int mask = 0; mask < N; ++mask) {
res[mask] = res1[mask];
kek1[mask] = kek2[mask];
dp1[mask] = dp2[mask];
dp2[mask] = -1;
}
}
for (int i = 0; i < 7; ++i)
add *= 3;
int tet = 1;
for (int i = 0; i < n; ++i)
tet *= 3;
for (int ptr = 0; ptr < tet; ++ptr) {
cout << get(ptr) % tet << " ";
}
// cout << TIME;
return;
}
signed main() {
#ifdef LOCAL
freopen("TASK.in", "r", stdin);
freopen("TASK.out", "w", stdout);
#else
#endif // LOCAL
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
cout << fixed;
int t = 1;
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
} | insert | 0 | 0 | 0 | 3 | TLE | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef vector<bool> vi;
const int maxn = 2e5 + 10;
char s[maxn];
int n, ans[maxn], len, p3[13];
void solve(int x, int v, vi &a) {
int res[3];
vi tmp[3];
for (int i = 0; i < 3; i++) {
tmp[i].clear();
int now = i;
for (int j = 0; j < a.size(); j++) {
if (a[j]) {
if (now > 0)
now = 3 - now;
tmp[i].pb(1);
int m = tmp[i].size();
if (m >= 2 && tmp[i][m - 1] && tmp[i][m - 2])
tmp[i].resize(m - 2);
} else {
now++;
if (now == 3) {
now = 0;
tmp[i].pb(0);
}
}
}
res[i] = now;
}
for (int i = 0; i < p3[n] / p3[x]; i++) {
ans[i * p3[x] + v] += p3[x] * res[i % 3];
}
if (x < n - 1) {
for (int i = 0; i < 3; i++)
solve(x + 1, v + i * p3[x], tmp[i]);
}
}
int main() {
cin >> n >> s;
len = strlen(s);
vector<vi> dp;
p3[0] = 1;
for (int i = 1; i <= n; i++)
p3[i] = p3[i - 1] * 3;
vi res;
res.clear();
for (int i = 0; i < len; i++) {
res.pb(s[i] == 'S');
int m = res.size();
if (m >= 2 && res[m - 1] && res[m - 2])
res.resize(m - 2);
}
solve(0, 0, res);
for (int i = 0; i < p3[n]; i++)
cout << ans[i] << ' ';
cout << endl;
}
| #include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef vector<bool> vi;
const int maxn = 1e6 + 10;
char s[maxn];
int n, ans[maxn], len, p3[13];
void solve(int x, int v, vi &a) {
int res[3];
vi tmp[3];
for (int i = 0; i < 3; i++) {
tmp[i].clear();
int now = i;
for (int j = 0; j < a.size(); j++) {
if (a[j]) {
if (now > 0)
now = 3 - now;
tmp[i].pb(1);
int m = tmp[i].size();
if (m >= 2 && tmp[i][m - 1] && tmp[i][m - 2])
tmp[i].resize(m - 2);
} else {
now++;
if (now == 3) {
now = 0;
tmp[i].pb(0);
}
}
}
res[i] = now;
}
for (int i = 0; i < p3[n] / p3[x]; i++) {
ans[i * p3[x] + v] += p3[x] * res[i % 3];
}
if (x < n - 1) {
for (int i = 0; i < 3; i++)
solve(x + 1, v + i * p3[x], tmp[i]);
}
}
int main() {
cin >> n >> s;
len = strlen(s);
vector<vi> dp;
p3[0] = 1;
for (int i = 1; i <= n; i++)
p3[i] = p3[i - 1] * 3;
vi res;
res.clear();
for (int i = 0; i < len; i++) {
res.pb(s[i] == 'S');
int m = res.size();
if (m >= 2 && res[m - 1] && res[m - 2])
res.resize(m - 2);
}
solve(0, 0, res);
for (int i = 0; i < p3[n]; i++)
cout << ans[i] << ' ';
cout << endl;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02671 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 12;
const int maxN = 600000;
const int maxt = 200002;
struct node {
node *ch[3];
int lazy, id;
};
node *build(int d, int cur);
void pd(node *p);
void change(node *p, int d);
void cal(node *p, int d, int cur);
int n, t;
char str[maxt];
int powd[maxn];
int ans[maxN];
int main() {
scanf("%d", &n);
scanf("%s", str + 1);
t = strlen(str + 1);
powd[0] = 1;
for (int i = 1; i < n; i++) {
powd[i] = 3 * powd[i - 1];
}
node *rt = build(0, 0);
for (int i = 1; i <= t; i++) {
if (str[i] == 'S')
rt->lazy ^= 1;
else
change(rt, 0);
}
cal(rt, 0, 0);
int N = 1;
for (int i = 1; i <= n; i++)
N *= 3;
for (int i = 0; i < N; i++) {
printf("%d ", ans[i]);
}
return 0;
}
node *create() {
static node pool[maxN];
static node *p = pool;
p->ch[0] = p->ch[1] = p->ch[2] = NULL;
p->lazy = p->id = 0;
return p++;
}
node *build(int d, int cur) {
node *p = create();
if (d == n) {
p->id = cur;
return p;
}
p->ch[0] = build(d + 1, cur);
p->ch[1] = build(d + 1, cur + powd[d]);
p->ch[2] = build(d + 1, cur + powd[d] + powd[d]);
return p;
}
void pd(node *p) {
if (!p->lazy)
return;
swap(p->ch[1], p->ch[2]);
p->ch[0]->lazy ^= 1;
p->ch[1]->lazy ^= 1;
p->ch[2]->lazy ^= 1;
p->lazy = 0;
}
void change(node *p, int d) {
if (d == n)
return;
pd(p);
swap(p->ch[0], p->ch[1]);
swap(p->ch[0], p->ch[2]);
change(p->ch[0], d + 1);
}
void cal(node *p, int d, int cur) {
if (d == n) {
ans[p->id] = cur;
return;
}
pd(p);
cal(p->ch[0], d + 1, cur);
cal(p->ch[1], d + 1, cur + powd[d]);
cal(p->ch[2], d + 1, cur + powd[d] + powd[d]);
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 20;
const int maxN = 1000000;
const int maxt = 2000002;
struct node {
node *ch[3];
int lazy, id;
};
node *build(int d, int cur);
void pd(node *p);
void change(node *p, int d);
void cal(node *p, int d, int cur);
int n, t;
char str[maxt];
int powd[maxn];
int ans[maxN];
int main() {
scanf("%d", &n);
scanf("%s", str + 1);
t = strlen(str + 1);
powd[0] = 1;
for (int i = 1; i < n; i++) {
powd[i] = 3 * powd[i - 1];
}
node *rt = build(0, 0);
for (int i = 1; i <= t; i++) {
if (str[i] == 'S')
rt->lazy ^= 1;
else
change(rt, 0);
}
cal(rt, 0, 0);
int N = 1;
for (int i = 1; i <= n; i++)
N *= 3;
for (int i = 0; i < N; i++) {
printf("%d ", ans[i]);
}
return 0;
}
node *create() {
static node pool[maxN];
static node *p = pool;
p->ch[0] = p->ch[1] = p->ch[2] = NULL;
p->lazy = p->id = 0;
return p++;
}
node *build(int d, int cur) {
node *p = create();
if (d == n) {
p->id = cur;
return p;
}
p->ch[0] = build(d + 1, cur);
p->ch[1] = build(d + 1, cur + powd[d]);
p->ch[2] = build(d + 1, cur + powd[d] + powd[d]);
return p;
}
void pd(node *p) {
if (!p->lazy)
return;
swap(p->ch[1], p->ch[2]);
p->ch[0]->lazy ^= 1;
p->ch[1]->lazy ^= 1;
p->ch[2]->lazy ^= 1;
p->lazy = 0;
}
void change(node *p, int d) {
if (d == n)
return;
pd(p);
swap(p->ch[0], p->ch[1]);
swap(p->ch[0], p->ch[2]);
change(p->ch[0], d + 1);
}
void cal(node *p, int d, int cur) {
if (d == n) {
ans[p->id] = cur;
return;
}
pd(p);
cal(p->ch[0], d + 1, cur);
cal(p->ch[1], d + 1, cur + powd[d]);
cal(p->ch[2], d + 1, cur + powd[d] + powd[d]);
} | replace | 5 | 8 | 5 | 8 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int ch[600005][3], ed[600005], cnt = 1, ans[600005];
bool rev[600005];
char s[200005];
void pushr(int x) {
swap(ch[x][1], ch[x][2]);
rev[x] ^= 1;
}
void pushdown(int x) {
if (!rev[x])
return;
for (int i = 0; i <= 2; i++)
if (ch[x][i])
pushr(ch[x][i]);
rev[x] = 0;
}
void dfs(int x) {
pushdown(x);
swap(ch[x][0], ch[x][2]), swap(ch[x][1], ch[x][2]);
if (ch[x][0])
dfs(ch[x][0]);
}
void get(int x, int now, int pw) {
pushdown(x);
if (ed[x] != 0xffffffff)
ans[ed[x]] = now;
if (ch[x][0])
get(ch[x][0], now, pw * 3);
if (ch[x][1])
get(ch[x][1], now + pw, pw * 3);
if (ch[x][2])
get(ch[x][2], now + 2 * pw, pw * 3);
}
int main() {
int n, m = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
m *= 3;
memset(ed, 0xff, sizeof(ed));
for (int i = 0; i < m; i++) {
int now = 1, tmp = i;
for (int k = 0; k < n; k++) {
int t = tmp % 3;
tmp /= 3;
if (!ch[now][t])
ch[now][t] = ++cnt;
now = ch[now][t];
}
ed[now] = i;
}
scanf("%s", s + 1);
int q = strlen(s + 1);
for (int i = 1; i <= q; i++) {
if (s[i] == 'S')
pushr(1);
else
dfs(1);
}
get(1, 0, 1);
for (int i = 0; i < m; i++)
printf("%d ", ans[i]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int ch[10000005][3], ed[10000005], cnt = 1, ans[10000005];
bool rev[10000005];
char s[200005];
void pushr(int x) {
swap(ch[x][1], ch[x][2]);
rev[x] ^= 1;
}
void pushdown(int x) {
if (!rev[x])
return;
for (int i = 0; i <= 2; i++)
if (ch[x][i])
pushr(ch[x][i]);
rev[x] = 0;
}
void dfs(int x) {
pushdown(x);
swap(ch[x][0], ch[x][2]), swap(ch[x][1], ch[x][2]);
if (ch[x][0])
dfs(ch[x][0]);
}
void get(int x, int now, int pw) {
pushdown(x);
if (ed[x] != 0xffffffff)
ans[ed[x]] = now;
if (ch[x][0])
get(ch[x][0], now, pw * 3);
if (ch[x][1])
get(ch[x][1], now + pw, pw * 3);
if (ch[x][2])
get(ch[x][2], now + 2 * pw, pw * 3);
}
int main() {
int n, m = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
m *= 3;
memset(ed, 0xff, sizeof(ed));
for (int i = 0; i < m; i++) {
int now = 1, tmp = i;
for (int k = 0; k < n; k++) {
int t = tmp % 3;
tmp /= 3;
if (!ch[now][t])
ch[now][t] = ++cnt;
now = ch[now][t];
}
ed[now] = i;
}
scanf("%s", s + 1);
int q = strlen(s + 1);
for (int i = 1; i <= q; i++) {
if (s[i] == 'S')
pushr(1);
else
dfs(1);
}
get(1, 0, 1);
for (int i = 0; i < m; i++)
printf("%d ", ans[i]);
return 0;
} | replace | 2 | 4 | 2 | 4 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void read(int &x) {
register char ch = getchar();
x = 0;
for (; ch == ' ' || ch == '\n'; ch = getchar())
;
for (; ch != ' ' && ch != '\n'; x = x * 10 + ch - '0', ch = getchar())
;
}
void reads(string &s) {
register char ch = getchar();
s = "";
for (; ch == ' ' || ch == '\n'; ch = getchar())
;
for (; ch != ' ' && ch != '\n'; s += ch, ch = getchar())
;
}
void write(int x) {
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int K, pw[13], ans[532000], dat[532000], go[532000][3];
bool lz[532000];
string typ;
void built_trie(int id, int lv, int now) {
if (lv == K) {
dat[id] = now;
return;
}
for (int i = 0; i < 3; i++) {
go[id][i] = id * 3 + i + 1;
built_trie(go[id][i], lv + 1, now + i * pw[lv]);
}
}
void push_down(int id) {
swap(go[id][1], go[id][2]);
for (int i = 0; i < 3; i++)
lz[go[id][i]] ^= 1;
lz[id] = 0;
}
void update_trie(int id, int lv) {
if (lv == K)
return;
if (lz[id])
push_down(id);
update_trie(go[id][2], lv + 1);
swap(go[id][1], go[id][2]), swap(go[id][0], go[id][1]);
}
void make_ans(int id, int lv, int now) {
if (lv == K) {
ans[dat[id]] = now;
return;
}
if (lz[id])
push_down(id);
for (int i = 0; i < 3; i++)
make_ans(go[id][i], lv + 1, now + i * pw[lv]);
}
int main() {
pw[0] = 1, read(K), reads(typ);
for (int i = 1; i <= K; i++)
pw[i] = pw[i - 1] * 3;
built_trie(0, 0, 0);
for (int i = 0; i < typ.size(); i++) {
if (typ[i] == 'S')
lz[0] ^= 1;
else
update_trie(0, 0);
}
make_ans(0, 0, 0);
for (int i = 0; i < pw[K]; i++)
write(ans[i]), putchar(' ');
} | #include <bits/stdc++.h>
using namespace std;
void read(int &x) {
register char ch = getchar();
x = 0;
for (; ch == ' ' || ch == '\n'; ch = getchar())
;
for (; ch != ' ' && ch != '\n'; x = x * 10 + ch - '0', ch = getchar())
;
}
void reads(string &s) {
register char ch = getchar();
s = "";
for (; ch == ' ' || ch == '\n'; ch = getchar())
;
for (; ch != ' ' && ch != '\n'; s += ch, ch = getchar())
;
}
void write(int x) {
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int K, pw[13], ans[800000], dat[800000], go[800000][3];
bool lz[800000];
string typ;
void built_trie(int id, int lv, int now) {
if (lv == K) {
dat[id] = now;
return;
}
for (int i = 0; i < 3; i++) {
go[id][i] = id * 3 + i + 1;
built_trie(go[id][i], lv + 1, now + i * pw[lv]);
}
}
void push_down(int id) {
swap(go[id][1], go[id][2]);
for (int i = 0; i < 3; i++)
lz[go[id][i]] ^= 1;
lz[id] = 0;
}
void update_trie(int id, int lv) {
if (lv == K)
return;
if (lz[id])
push_down(id);
update_trie(go[id][2], lv + 1);
swap(go[id][1], go[id][2]), swap(go[id][0], go[id][1]);
}
void make_ans(int id, int lv, int now) {
if (lv == K) {
ans[dat[id]] = now;
return;
}
if (lz[id])
push_down(id);
for (int i = 0; i < 3; i++)
make_ans(go[id][i], lv + 1, now + i * pw[lv]);
}
int main() {
pw[0] = 1, read(K), reads(typ);
for (int i = 1; i <= K; i++)
pw[i] = pw[i - 1] * 3;
built_trie(0, 0, 0);
for (int i = 0; i < typ.size(); i++) {
if (typ[i] == 'S')
lz[0] ^= 1;
else
update_trie(0, 0);
}
make_ans(0, 0, 0);
for (int i = 0; i < pw[K]; i++)
write(ans[i]), putchar(' ');
} | replace | 23 | 25 | 23 | 25 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size() - 1
#define F(i, a, b) for (int i = a; i <= b; ++i)
#define DF(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
int read() {
char ch = getchar();
int w = 1, c = 0;
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
w = -1;
for (; isdigit(ch); ch = getchar())
c = (c << 3) + (c << 1) + (ch ^ 48);
return w * c;
}
const int M = 6e5 + 10;
int t[M][3], n, pw[M];
int val[M], rt, tot, ans[M];
bool tg[M];
char ch[M];
void rev(int x) {
tg[x] ^= 1;
swap(t[x][1], t[x][2]);
}
void pd(int x) {
if (tg[x]) {
F(i, 0, 2)
rev(t[x][i]);
tg[x] = 0;
}
}
void build(int &x, int dep, int o) {
x = ++tot;
val[x] = o;
if (dep == n)
return;
F(i, 0, 2) build(t[x][i], dep + 1, o + pw[dep] * i);
}
void add(int x, int dep) {
if (dep == n)
return;
pd(x);
int t0 = t[x][0], t1 = t[x][1], t2 = t[x][2];
t[x][0] = t2;
t[x][1] = t0;
t[x][2] = t1;
add(t[x][0], dep + 1);
}
void calc(int x, int dep, int o) {
if (dep == n) {
ans[val[x]] = o;
return;
}
pd(x);
F(i, 0, 2) calc(t[x][i], dep + 1, o + pw[dep] * i);
}
int main() {
n = read();
scanf("%s", ch + 1);
int m = strlen(ch + 1);
pw[0] = 1;
F(i, 1, 20) pw[i] = pw[i - 1] * 3;
build(rt, 0, 0);
F(i, 1, m) {
if (ch[i] == 'S')
rev(rt);
else
add(rt, 0);
}
calc(1, 0, 0);
F(i, 0, pw[n] - 1) { cout << ans[i] << " "; }
cout << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size() - 1
#define F(i, a, b) for (int i = a; i <= b; ++i)
#define DF(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
int read() {
char ch = getchar();
int w = 1, c = 0;
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
w = -1;
for (; isdigit(ch); ch = getchar())
c = (c << 3) + (c << 1) + (ch ^ 48);
return w * c;
}
const int M = 5e6 + 10;
int t[M][3], n, pw[M];
int val[M], rt, tot, ans[M];
bool tg[M];
char ch[M];
void rev(int x) {
tg[x] ^= 1;
swap(t[x][1], t[x][2]);
}
void pd(int x) {
if (tg[x]) {
F(i, 0, 2)
rev(t[x][i]);
tg[x] = 0;
}
}
void build(int &x, int dep, int o) {
x = ++tot;
val[x] = o;
if (dep == n)
return;
F(i, 0, 2) build(t[x][i], dep + 1, o + pw[dep] * i);
}
void add(int x, int dep) {
if (dep == n)
return;
pd(x);
int t0 = t[x][0], t1 = t[x][1], t2 = t[x][2];
t[x][0] = t2;
t[x][1] = t0;
t[x][2] = t1;
add(t[x][0], dep + 1);
}
void calc(int x, int dep, int o) {
if (dep == n) {
ans[val[x]] = o;
return;
}
pd(x);
F(i, 0, 2) calc(t[x][i], dep + 1, o + pw[dep] * i);
}
int main() {
n = read();
scanf("%s", ch + 1);
int m = strlen(ch + 1);
pw[0] = 1;
F(i, 1, 20) pw[i] = pw[i - 1] * 3;
build(rt, 0, 0);
F(i, 1, m) {
if (ch[i] == 'S')
rev(rt);
else
add(rt, 0);
}
calc(1, 0, 0);
F(i, 0, pw[n] - 1) { cout << ans[i] << " "; }
cout << "\n";
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 13;
const int maxp = 2e6 + 5;
const int maxm = 2e5 + 5;
int n, m;
int pw[maxn], ans[maxn];
char t[maxm];
class Trie {
public:
int tot;
int p[maxp], ch[maxp][3], tag[maxp];
Trie() {
tot = 1;
memset(ch, -1, sizeof(ch));
memset(p, -1, sizeof(p));
return;
}
inline void insert(int x) {
int u = 0, y = x;
for (int i = 0; i < n; ++i, x /= 3) {
if (!~ch[u][x % 3])
ch[u][x % 3] = tot++;
u = ch[u][x % 3];
}
// printf("u = %d y = %d\n", u, y);
p[u] = y;
return;
}
inline void inv(int u) {
tag[u] ^= 1;
swap(ch[u][1], ch[u][2]);
return;
}
inline void pushDown(int u) {
if (tag[u]) {
FOR(i, 0, 3)
inv(ch[u][i]);
tag[u] = false;
}
return;
}
inline void update(int dep, int u) {
// printf("dep = %d u = %d\n", dep, u);
if (dep > n || !~u)
return;
pushDown(u);
int tmp = ch[u][2];
ch[u][2] = ch[u][1];
ch[u][1] = ch[u][0];
ch[u][0] = tmp;
update(dep + 1, ch[u][0]);
return;
}
inline void dfs(int dep, int u, int x) {
if (dep > n || !~u)
return;
// printf("dep = %d u = %d x = %d\n", dep, u, x);
pushDown(u);
FOR(i, 0, 3)
dfs(dep + 1, ch[u][i], x + i * pw[dep]);
if (~p[u])
ans[p[u]] = x;
return;
}
} trie;
inline void precalc() {
pw[0] = 1;
FOR(i, 1, maxn)
pw[i] = pw[i - 1] * 3;
return;
}
int main() {
scanf("%d", &n);
precalc();
scanf("%s", t);
m = strlen(t);
FOR(i, 0, pw[n])
trie.insert(i);
FOR(i, 0, m) {
if (t[i] == 'S')
trie.inv(0);
else
trie.update(0, 0);
}
trie.dfs(0, 0, 0);
FOR(i, 0, pw[n])
printf("%d ", ans[i]);
puts("");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 13;
const int maxp = 2e6 + 5;
const int maxm = 2e5 + 5;
int n, m;
int pw[maxn], ans[maxp];
char t[maxm];
class Trie {
public:
int tot;
int p[maxp], ch[maxp][3], tag[maxp];
Trie() {
tot = 1;
memset(ch, -1, sizeof(ch));
memset(p, -1, sizeof(p));
return;
}
inline void insert(int x) {
int u = 0, y = x;
for (int i = 0; i < n; ++i, x /= 3) {
if (!~ch[u][x % 3])
ch[u][x % 3] = tot++;
u = ch[u][x % 3];
}
// printf("u = %d y = %d\n", u, y);
p[u] = y;
return;
}
inline void inv(int u) {
tag[u] ^= 1;
swap(ch[u][1], ch[u][2]);
return;
}
inline void pushDown(int u) {
if (tag[u]) {
FOR(i, 0, 3)
inv(ch[u][i]);
tag[u] = false;
}
return;
}
inline void update(int dep, int u) {
// printf("dep = %d u = %d\n", dep, u);
if (dep > n || !~u)
return;
pushDown(u);
int tmp = ch[u][2];
ch[u][2] = ch[u][1];
ch[u][1] = ch[u][0];
ch[u][0] = tmp;
update(dep + 1, ch[u][0]);
return;
}
inline void dfs(int dep, int u, int x) {
if (dep > n || !~u)
return;
// printf("dep = %d u = %d x = %d\n", dep, u, x);
pushDown(u);
FOR(i, 0, 3)
dfs(dep + 1, ch[u][i], x + i * pw[dep]);
if (~p[u])
ans[p[u]] = x;
return;
}
} trie;
inline void precalc() {
pw[0] = 1;
FOR(i, 1, maxn)
pw[i] = pw[i - 1] * 3;
return;
}
int main() {
scanf("%d", &n);
precalc();
scanf("%s", t);
m = strlen(t);
FOR(i, 0, pw[n])
trie.insert(i);
FOR(i, 0, m) {
if (t[i] == 'S')
trie.inv(0);
else
trie.update(0, 0);
}
trie.dfs(0, 0, 0);
FOR(i, 0, pw[n])
printf("%d ", ans[i]);
puts("");
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02671 | C++ | Time Limit Exceeded | #define ENABLE_DEBUG 0
// Kana's kitchen {{{
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define LOOP(k) \
for (i64 ngtkana_is_a_genius = 0; ngtkana_is_a_genius < (i64)k; \
ngtkana_is_a_genius++)
using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;
#ifdef NGTKANA
#include <debug.hpp>
#else
#define DEBUG(...) (void)0
#endif
/*}}}*/
// mint{{{
template <class ModType> struct modint {
using value_type = typename ModType::value_type;
using mint = modint<ModType>;
using mod_type = ModType;
static value_type mod() { return ModType::value; }
private:
static value_type inverse(value_type x) {
value_type y = 1, u = mod(), v = 0;
while (x) {
value_type q = u / x;
u -= q * x;
std::swap(x, u);
v -= q * y;
std::swap(y, v);
}
assert(x == 0 && std::abs(y) == mod() && std::abs(u) == 1 &&
std::abs(v) < mod());
return v < 0 ? v + mod() : v;
}
public:
// the member variable
value_type value;
// constructors
modint() = default;
modint(modint const &) = default;
modint(modint &&) = default;
modint &operator=(modint const &) = default;
modint &operator=(modint &&) = default;
~modint() = default;
template <class T>
modint(T t)
: value([t]() mutable {
if (t <= -static_cast<T>(mod()) || static_cast<T>(mod()) <= t)
t %= mod();
return t < 0 ? t + mod() : t;
}()) {}
// operators
mint &operator+=(mint y) {
value += y.value;
if (mod() <= value)
value -= mod();
return *this;
}
mint &operator-=(mint y) {
value -= y.value;
if (value < 0)
value += mod();
return *this;
}
mint &operator*=(mint y) {
value = (long long)value * y.value % mod();
return *this;
}
mint &operator/=(mint y) {
value = (long long)value * inverse(y.value) % mod();
return *this;
}
mint &operator++() { return *this += 1; }
mint &operator--() { return *this -= 1; }
mint operator++(int) {
mint this_ = *this;
++*this;
return this_;
}
mint operator--(int) {
mint this_ = *this;
--*this;
return this_;
}
// static member functions
static mint inv(mint x) { return inverse(x.value); }
static mint m1pow(long long y) { return y % 2 ? -1 : 1; }
static mint pow(mint x, unsigned long long y) {
mint ans = 1;
for (; y; y >>= 1) {
if (y & 1ull)
ans *= x;
x *= x;
}
return ans;
}
// non-member functions
mint &add_assign(mint y) { return *this += y; }
mint &sub_assign(mint y) { return *this -= y; }
mint &mul_assign(mint y) { return *this *= y; }
mint &div_assign(mint y) { return *this /= y; }
mint &inv_assign() { return *this = inv(*this); }
mint &pow_assign(unsigned long long y) { return *this = pow(*this, y); }
mint add(mint y) {
mint ans = *this;
return ans.add_assign(y);
}
mint sub(mint y) {
mint ans = *this;
return ans.sub_assign(y);
}
mint mul(mint y) {
mint ans = *this;
return ans.mul_assign(y);
}
mint div(mint y) {
mint ans = *this;
return ans.div_assign(y);
}
mint inv() {
mint ans = *this;
return ans.inv_assign();
}
mint pow(unsigned long long y) { return pow(*this, y); }
template <class F> mint map(F const &f) {
value = f(value);
return *this;
}
};
template <class T> std::istream &operator>>(std::istream &is, modint<T> &x) {
typename modint<T>::value_type y;
is >> y;
x = modint<T>{y};
return is;
}
template <class T> std::ostream &operator<<(std::ostream &os, modint<T> x) {
return os << x.value;
}
template <class T> modint<T> operator+(modint<T> x, modint<T> y) {
return x += y;
}
template <class T> modint<T> operator-(modint<T> x, modint<T> y) {
return x -= y;
}
template <class T> modint<T> operator*(modint<T> x, modint<T> y) {
return x *= y;
}
template <class T> modint<T> operator/(modint<T> x, modint<T> y) {
return x /= y;
}
template <class T> bool operator==(modint<T> x, modint<T> y) {
return x.value == y.value;
}
template <class T> bool operator!=(modint<T> x, modint<T> y) {
return x.value != y.value;
}
template <class T, class U> modint<T> operator+(modint<T> x, U y) {
return x + modint<T>(y);
}
template <class T, class U> modint<T> operator-(modint<T> x, U y) {
return x - modint<T>(y);
}
template <class T, class U> modint<T> operator*(modint<T> x, U y) {
return x * modint<T>(y);
}
template <class T, class U> modint<T> operator/(modint<T> x, U y) {
return x / modint<T>(y);
}
template <class T, class U> bool operator==(modint<T> x, U y) {
return x == modint<T>(y);
}
template <class T, class U> bool operator!=(modint<T> x, U y) {
return x != modint<T>(y);
}
template <class T, class U> modint<T> operator+(U x, modint<T> y) {
return modint<T>(x) + y;
}
template <class T, class U> modint<T> operator-(U x, modint<T> y) {
return modint<T>(x) - y;
}
template <class T, class U> modint<T> operator*(U x, modint<T> y) {
return modint<T>(x) * y;
}
template <class T, class U> modint<T> operator/(U x, modint<T> y) {
return modint<T>(x) / y;
}
template <class T, class U> bool operator==(U x, modint<T> y) {
return modint<T>(x) == y;
}
template <class T, class U> bool operator!=(U x, modint<T> y) {
return modint<T>(x) != y;
}
/*}}}*/
using mint = modint<std::integral_constant<i32, 3>>;
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cout << std::setprecision(15) << std::fixed;
usize n;
std::cin >> n;
vec<usize> tpow(n + 1, 1);
for (usize i = 0; i < n; i++) {
tpow.at(i + 1) = tpow.at(i) * 3;
}
usize N = tpow.back();
DEBUG(n, N, tpow);
bool has_s = false;
vec<vec<mint>> sigma(n);
for (usize i = 0; i < n; i++) {
sigma.at(i).resize(tpow.at(i));
}
DEBUG(matrix_style(sigma));
// apply-s{{{
auto apply_s = [&](usize a) {
for (usize k = 0; k < n; k++) {
usize K = tpow.at(k);
usize r = a % (3 * K);
if (K <= r && r < 2 * K) {
a += K;
} else if (2 * K <= r) {
a -= K;
}
}
return a;
};
/*}}}*/
// mul_r_from_the_left{{{
auto mul_r_from_the_left = [&] {
for (usize i = n - 1; i != -1; i--) {
usize I = tpow.at(i);
usize j = I - 1;
if (has_s) {
j = apply_s(j);
}
DEBUG(i, j);
for (usize k = 0; k < i; k++) {
usize K = tpow.at(k);
usize r = j % (3 * K);
usize val = sigma.at(k).at(r % K).value;
DEBUG(j, val);
j -= val * K;
if (r < val * K)
j += 3 * K;
DEBUG(j, val);
}
if (has_s) {
sigma.at(i).at(j)--;
} else {
sigma.at(i).at(j)++;
}
}
};
/*}}}*/
// get-ans{{{
auto get_ans = [&] {
vec<usize> ans(N);
std::iota(ALL(ans), 0u);
for (usize j = 0; j < N; j++) {
usize &a = ans.at(j);
for (usize k = n - 1; k != -1; k--) {
usize K = tpow.at(k);
usize r = a % (3 * K);
usize val = sigma.at(k).at(r % K).value;
a += val * K;
if ((3 - val) * K <= r)
a -= 3 * K;
}
if (has_s) {
a = apply_s(a);
}
}
return ans;
};
/*}}}*/
DEBUG(get_ans());
std::string s;
std::cin >> s;
for (char c : s) {
DEBUG(c);
if (c == 'S') {
has_s ^= 1;
}
if (c == 'R') {
mul_r_from_the_left();
}
DEBUG(has_s);
DEBUG(matrix_style(sigma));
auto ans = get_ans();
DEBUG(ans);
DEBUG();
}
auto ans = get_ans();
for (usize i = 0; i < N; i++) {
std::cout << (i ? " " : "") << ans.at(i);
}
std::cout << '\n';
}
| #define ENABLE_DEBUG 0
// Kana's kitchen {{{
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define LOOP(k) \
for (i64 ngtkana_is_a_genius = 0; ngtkana_is_a_genius < (i64)k; \
ngtkana_is_a_genius++)
using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;
#ifdef NGTKANA
#include <debug.hpp>
#else
#define DEBUG(...) (void)0
#endif
/*}}}*/
// mint{{{
template <class ModType> struct modint {
using value_type = typename ModType::value_type;
using mint = modint<ModType>;
using mod_type = ModType;
static value_type mod() { return ModType::value; }
private:
static value_type inverse(value_type x) {
value_type y = 1, u = mod(), v = 0;
while (x) {
value_type q = u / x;
u -= q * x;
std::swap(x, u);
v -= q * y;
std::swap(y, v);
}
assert(x == 0 && std::abs(y) == mod() && std::abs(u) == 1 &&
std::abs(v) < mod());
return v < 0 ? v + mod() : v;
}
public:
// the member variable
value_type value;
// constructors
modint() = default;
modint(modint const &) = default;
modint(modint &&) = default;
modint &operator=(modint const &) = default;
modint &operator=(modint &&) = default;
~modint() = default;
template <class T>
modint(T t)
: value([t]() mutable {
if (t <= -static_cast<T>(mod()) || static_cast<T>(mod()) <= t)
t %= mod();
return t < 0 ? t + mod() : t;
}()) {}
// operators
mint &operator+=(mint y) {
value += y.value;
if (mod() <= value)
value -= mod();
return *this;
}
mint &operator-=(mint y) {
value -= y.value;
if (value < 0)
value += mod();
return *this;
}
mint &operator*=(mint y) {
value = (long long)value * y.value % mod();
return *this;
}
mint &operator/=(mint y) {
value = (long long)value * inverse(y.value) % mod();
return *this;
}
mint &operator++() { return *this += 1; }
mint &operator--() { return *this -= 1; }
mint operator++(int) {
mint this_ = *this;
++*this;
return this_;
}
mint operator--(int) {
mint this_ = *this;
--*this;
return this_;
}
// static member functions
static mint inv(mint x) { return inverse(x.value); }
static mint m1pow(long long y) { return y % 2 ? -1 : 1; }
static mint pow(mint x, unsigned long long y) {
mint ans = 1;
for (; y; y >>= 1) {
if (y & 1ull)
ans *= x;
x *= x;
}
return ans;
}
// non-member functions
mint &add_assign(mint y) { return *this += y; }
mint &sub_assign(mint y) { return *this -= y; }
mint &mul_assign(mint y) { return *this *= y; }
mint &div_assign(mint y) { return *this /= y; }
mint &inv_assign() { return *this = inv(*this); }
mint &pow_assign(unsigned long long y) { return *this = pow(*this, y); }
mint add(mint y) {
mint ans = *this;
return ans.add_assign(y);
}
mint sub(mint y) {
mint ans = *this;
return ans.sub_assign(y);
}
mint mul(mint y) {
mint ans = *this;
return ans.mul_assign(y);
}
mint div(mint y) {
mint ans = *this;
return ans.div_assign(y);
}
mint inv() {
mint ans = *this;
return ans.inv_assign();
}
mint pow(unsigned long long y) { return pow(*this, y); }
template <class F> mint map(F const &f) {
value = f(value);
return *this;
}
};
template <class T> std::istream &operator>>(std::istream &is, modint<T> &x) {
typename modint<T>::value_type y;
is >> y;
x = modint<T>{y};
return is;
}
template <class T> std::ostream &operator<<(std::ostream &os, modint<T> x) {
return os << x.value;
}
template <class T> modint<T> operator+(modint<T> x, modint<T> y) {
return x += y;
}
template <class T> modint<T> operator-(modint<T> x, modint<T> y) {
return x -= y;
}
template <class T> modint<T> operator*(modint<T> x, modint<T> y) {
return x *= y;
}
template <class T> modint<T> operator/(modint<T> x, modint<T> y) {
return x /= y;
}
template <class T> bool operator==(modint<T> x, modint<T> y) {
return x.value == y.value;
}
template <class T> bool operator!=(modint<T> x, modint<T> y) {
return x.value != y.value;
}
template <class T, class U> modint<T> operator+(modint<T> x, U y) {
return x + modint<T>(y);
}
template <class T, class U> modint<T> operator-(modint<T> x, U y) {
return x - modint<T>(y);
}
template <class T, class U> modint<T> operator*(modint<T> x, U y) {
return x * modint<T>(y);
}
template <class T, class U> modint<T> operator/(modint<T> x, U y) {
return x / modint<T>(y);
}
template <class T, class U> bool operator==(modint<T> x, U y) {
return x == modint<T>(y);
}
template <class T, class U> bool operator!=(modint<T> x, U y) {
return x != modint<T>(y);
}
template <class T, class U> modint<T> operator+(U x, modint<T> y) {
return modint<T>(x) + y;
}
template <class T, class U> modint<T> operator-(U x, modint<T> y) {
return modint<T>(x) - y;
}
template <class T, class U> modint<T> operator*(U x, modint<T> y) {
return modint<T>(x) * y;
}
template <class T, class U> modint<T> operator/(U x, modint<T> y) {
return modint<T>(x) / y;
}
template <class T, class U> bool operator==(U x, modint<T> y) {
return modint<T>(x) == y;
}
template <class T, class U> bool operator!=(U x, modint<T> y) {
return modint<T>(x) != y;
}
/*}}}*/
using mint = modint<std::integral_constant<i32, 3>>;
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cout << std::setprecision(15) << std::fixed;
usize n;
std::cin >> n;
vec<usize> tpow(n + 1, 1);
for (usize i = 0; i < n; i++) {
tpow.at(i + 1) = tpow.at(i) * 3;
}
usize N = tpow.back();
DEBUG(n, N, tpow);
bool has_s = false;
vec<vec<mint>> sigma(n);
for (usize i = 0; i < n; i++) {
sigma.at(i).resize(tpow.at(i));
}
DEBUG(matrix_style(sigma));
// apply-s{{{
auto apply_s = [&](usize a) {
for (usize k = 0; k < n; k++) {
usize K = tpow.at(k);
usize r = a % (3 * K);
if (K <= r && r < 2 * K) {
a += K;
} else if (2 * K <= r) {
a -= K;
}
}
return a;
};
/*}}}*/
// mul_r_from_the_left{{{
auto mul_r_from_the_left = [&] {
for (usize i = n - 1; i != -1; i--) {
usize I = tpow.at(i);
usize j = I - 1;
if (has_s) {
j = apply_s(j);
}
DEBUG(i, j);
for (usize k = 0; k < i; k++) {
usize K = tpow.at(k);
usize r = j % (3 * K);
usize val = sigma.at(k).at(r % K).value;
DEBUG(j, val);
j -= val * K;
if (r < val * K)
j += 3 * K;
DEBUG(j, val);
}
if (has_s) {
sigma.at(i).at(j)--;
} else {
sigma.at(i).at(j)++;
}
}
};
/*}}}*/
// get-ans{{{
auto get_ans = [&] {
vec<usize> ans(N);
std::iota(ALL(ans), 0u);
for (usize j = 0; j < N; j++) {
usize &a = ans.at(j);
for (usize k = n - 1; k != -1; k--) {
usize K = tpow.at(k);
usize r = a % (3 * K);
usize val = sigma.at(k).at(r % K).value;
a += val * K;
if ((3 - val) * K <= r)
a -= 3 * K;
}
if (has_s) {
a = apply_s(a);
}
}
return ans;
};
/*}}}*/
DEBUG(get_ans());
std::string s;
std::cin >> s;
for (char c : s) {
DEBUG(c);
if (c == 'S') {
has_s ^= 1;
}
if (c == 'R') {
mul_r_from_the_left();
}
DEBUG(has_s);
DEBUG(matrix_style(sigma));
DEBUG();
}
auto ans = get_ans();
for (usize i = 0; i < N; i++) {
std::cout << (i ? " " : "") << ans.at(i);
}
std::cout << '\n';
}
| delete | 321 | 323 | 321 | 321 | TLE | |
p02671 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline int Pow(int a, int b) {
return b ? Pow(a * a, b >> 1) * (b & 1 ? a : 1) : 1;
}
int main() {
int N, now, len = 0, A[200001], B[531441];
char T[200001], S[200001];
now = scanf("%d %s", &N, T);
len = strlen(T);
fflush(stdin);
int pw3 = Pow(3, N), x = Pow(3, N >> 1), y = Pow(3, N - (N >> 1));
rep(i, pw3) B[i] = B[i / 3] * 3 + (3 - i % 3) % 3;
rep(i, x) {
int temp = i;
now = 0;
rep(j, len) {
if (T[j] == 'S') {
temp = B[temp];
if (S[now] == 'S')
--now;
else
S[++now] = 'S';
} else {
++temp;
if (temp == x)
S[++now] = 'R', temp = 0;
}
}
rep(j, y) {
int keep = j;
rep(k, now) {
if (S[k + 1] == 'S')
keep = B[keep];
else if (S[k + 1] == 'R')
if ((++keep) == y)
keep = 0;
}
A[i + j * x] = temp + keep * x;
}
}
rep(i, pw3) printf("%d%c", A[i], i + 1 == pw3 ? '\n' : ' ');
return fflush(stdout), 0;
} | #include <stdio.h>
#include <string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline int Pow(int a, int b) {
return b ? Pow(a * a, b >> 1) * (b & 1 ? a : 1) : 1;
}
int main() {
int N, now, len = 0, A[531441], B[531441];
char T[200001], S[200001];
now = scanf("%d %s", &N, T);
len = strlen(T);
fflush(stdin);
int pw3 = Pow(3, N), x = Pow(3, N >> 1), y = Pow(3, N - (N >> 1));
rep(i, pw3) B[i] = B[i / 3] * 3 + (3 - i % 3) % 3;
rep(i, x) {
int temp = i;
now = 0;
rep(j, len) {
if (T[j] == 'S') {
temp = B[temp];
if (S[now] == 'S')
--now;
else
S[++now] = 'S';
} else {
++temp;
if (temp == x)
S[++now] = 'R', temp = 0;
}
}
rep(j, y) {
int keep = j;
rep(k, now) {
if (S[k + 1] == 'S')
keep = B[keep];
else if (S[k + 1] == 'R')
if ((++keep) == y)
keep = 0;
}
A[i + j * x] = temp + keep * x;
}
}
rep(i, pw3) printf("%d%c", A[i], i + 1 == pw3 ? '\n' : ' ');
return fflush(stdout), 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 6e5 + 50;
int n, p[N];
char S[N];
int ch[N][3], tag[N], vl[N], nd, pw[20];
int build(int d, int v) {
if (!d)
return vl[++nd] = v, nd;
int x = ++nd;
ch[x][0] = build(d - 1, v);
ch[x][1] = build(d - 1, v + pw[n - d]);
ch[x][2] = build(d - 1, v + 2 * pw[n - d]);
return x;
}
void put(int x) {
if (!x)
return;
tag[x] ^= 1;
swap(ch[x][1], ch[x][2]);
}
void down(int x) {
if (tag[x])
put(ch[x][0]), put(ch[x][1]), put(ch[x][2]), tag[x] = 0;
}
void work(int x, int d) {
if (!d)
return;
down(x);
int v = ch[x][2];
ch[x][2] = ch[x][1];
ch[x][1] = ch[x][0];
ch[x][0] = v;
work(v, d - 1);
}
void dfs(int x, int d, int v = 0) {
if (!d)
return p[vl[x]] = v, void();
down(x);
dfs(ch[x][0], d - 1, v);
dfs(ch[x][1], d - 1, v + pw[n - d]);
dfs(ch[x][2], d - 1, v + 2 * pw[n - d]);
}
int main() {
#ifdef FSYolanda
freopen("1.in", "r", stdin);
#endif
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 3;
scanf("%s", S);
int m = strlen(S);
build(n, 0);
for (int i = 0; i < m; i++) {
if (S[i] == 'R')
work(1, n);
if (S[i] == 'S')
put(1);
}
dfs(1, n);
for (int i = 0; i < pw[n]; i++)
cout << p[i] << " ";
return 0;
} | #include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 2e6 + 50;
int n, p[N];
char S[N];
int ch[N][3], tag[N], vl[N], nd, pw[20];
int build(int d, int v) {
if (!d)
return vl[++nd] = v, nd;
int x = ++nd;
ch[x][0] = build(d - 1, v);
ch[x][1] = build(d - 1, v + pw[n - d]);
ch[x][2] = build(d - 1, v + 2 * pw[n - d]);
return x;
}
void put(int x) {
if (!x)
return;
tag[x] ^= 1;
swap(ch[x][1], ch[x][2]);
}
void down(int x) {
if (tag[x])
put(ch[x][0]), put(ch[x][1]), put(ch[x][2]), tag[x] = 0;
}
void work(int x, int d) {
if (!d)
return;
down(x);
int v = ch[x][2];
ch[x][2] = ch[x][1];
ch[x][1] = ch[x][0];
ch[x][0] = v;
work(v, d - 1);
}
void dfs(int x, int d, int v = 0) {
if (!d)
return p[vl[x]] = v, void();
down(x);
dfs(ch[x][0], d - 1, v);
dfs(ch[x][1], d - 1, v + pw[n - d]);
dfs(ch[x][2], d - 1, v + 2 * pw[n - d]);
}
int main() {
#ifdef FSYolanda
freopen("1.in", "r", stdin);
#endif
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 3;
scanf("%s", S);
int m = strlen(S);
build(n, 0);
for (int i = 0; i < m; i++) {
if (S[i] == 'R')
work(1, n);
if (S[i] == 'S')
put(1);
}
dfs(1, n);
for (int i = 0; i < pw[n]; i++)
cout << p[i] << " ";
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02671 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define RI register int
#define CI const int &
using namespace std;
const int N = 531442;
int n, m, rt, tot, ch[N][3], ans[N], id[N];
char s[N];
bool rev[N];
inline void build(int &now, CI dep = 0, CI st = 0) {
now = ++tot;
if (dep == n)
return (void)(id[now] = st);
int len = pow(3, dep);
build(ch[now][0], dep + 1, st);
build(ch[now][1], dep + 1, st + len);
build(ch[now][2], dep + 1, st + (len << 1));
}
inline void rever(CI now) {
swap(ch[now][1], ch[now][2]);
rev[now] ^= 1;
}
inline void pushdown(CI now) {
if (!rev[now])
return;
rev[now] = 0;
for (RI i = 0; i < 3; ++i)
rever(ch[now][i]);
}
inline void swaping(CI now, CI dep = 0) {
pushdown(now);
if (dep == n)
return;
swap(ch[now][1], ch[now][2]);
swap(ch[now][0], ch[now][1]);
swaping(ch[now][0], dep + 1);
}
inline void DFS(CI now, CI dep = 0, CI st = 0) {
pushdown(now);
if (dep == n)
return (void)(ans[id[now]] = st);
int len = pow(3, dep);
DFS(ch[now][0], dep + 1, st);
DFS(ch[now][1], dep + 1, st + len);
DFS(ch[now][2], dep + 1, st + (len << 1));
}
int main() {
RI i;
scanf("%d%s", &n, s + 1);
m = strlen(s + 1);
for (build(rt), i = 1; i <= m; ++i)
if (s[i] == 'S')
rever(rt);
else
swaping(rt);
for (DFS(rt), n = pow(3, n), i = 0; i < n; ++i)
printf("%d ", ans[i]);
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define RI register int
#define CI const int &
using namespace std;
const int N = 1594324;
int n, m, rt, tot, ch[N][3], ans[N], id[N];
char s[N];
bool rev[N];
inline void build(int &now, CI dep = 0, CI st = 0) {
now = ++tot;
if (dep == n)
return (void)(id[now] = st);
int len = pow(3, dep);
build(ch[now][0], dep + 1, st);
build(ch[now][1], dep + 1, st + len);
build(ch[now][2], dep + 1, st + (len << 1));
}
inline void rever(CI now) {
swap(ch[now][1], ch[now][2]);
rev[now] ^= 1;
}
inline void pushdown(CI now) {
if (!rev[now])
return;
rev[now] = 0;
for (RI i = 0; i < 3; ++i)
rever(ch[now][i]);
}
inline void swaping(CI now, CI dep = 0) {
pushdown(now);
if (dep == n)
return;
swap(ch[now][1], ch[now][2]);
swap(ch[now][0], ch[now][1]);
swaping(ch[now][0], dep + 1);
}
inline void DFS(CI now, CI dep = 0, CI st = 0) {
pushdown(now);
if (dep == n)
return (void)(ans[id[now]] = st);
int len = pow(3, dep);
DFS(ch[now][0], dep + 1, st);
DFS(ch[now][1], dep + 1, st + len);
DFS(ch[now][2], dep + 1, st + (len << 1));
}
int main() {
RI i;
scanf("%d%s", &n, s + 1);
m = strlen(s + 1);
for (build(rt), i = 1; i <= m; ++i)
if (s[i] == 'S')
rever(rt);
else
swaping(rt);
for (DFS(rt), n = pow(3, n), i = 0; i < n; ++i)
printf("%d ", ans[i]);
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, rt, tot, sum[N], ans[N], t[N][3], lz[N];
char s[N];
void build(int &now, int n, int b, int c) {
now = ++tot;
if (n == 0) {
sum[now] = c;
return;
}
build(t[now][0], n - 1, b * 3, c);
build(t[now][1], n - 1, b * 3, c + b);
build(t[now][2], n - 1, b * 3, c + b + b);
}
void updata(int now, int n) {
swap(t[now][1], t[now][2]);
lz[t[now][0]] ^= 1;
lz[t[now][1]] ^= 1;
lz[t[now][2]] ^= 1;
lz[now] = 0;
}
void solve(int now, int n) {
if (n == 0)
return;
if (lz[now])
updata(now, n);
int a = t[now][0], b = t[now][1], c = t[now][2];
t[now][1] = a;
t[now][2] = b;
t[now][0] = c;
solve(t[now][0], n - 1);
}
void getans(int now, int n, int b, int c) {
if (n == 0) {
ans[sum[now]] = c;
return;
}
if (lz[now])
updata(now, n);
getans(t[now][0], n - 1, b * 3, c);
getans(t[now][1], n - 1, b * 3, c + b);
getans(t[now][2], n - 1, b * 3, c + b + b);
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
build(rt, n, 1, 0);
for (int i = 1; s[i]; i++) {
if (s[i] == 'S')
lz[rt] ^= 1;
else
solve(rt, n);
}
getans(rt, n, 1, 0);
int sum = 1;
for (int i = 1; i <= n; i++)
sum *= 3;
for (int i = 0; i < sum; i++)
printf(i == sum - 1 ? "%d\n" : "%d ", ans[i]);
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, rt, tot, sum[N], ans[N], t[N][3], lz[N];
char s[N];
void build(int &now, int n, int b, int c) {
now = ++tot;
if (n == 0) {
sum[now] = c;
return;
}
build(t[now][0], n - 1, b * 3, c);
build(t[now][1], n - 1, b * 3, c + b);
build(t[now][2], n - 1, b * 3, c + b + b);
}
void updata(int now, int n) {
swap(t[now][1], t[now][2]);
lz[t[now][0]] ^= 1;
lz[t[now][1]] ^= 1;
lz[t[now][2]] ^= 1;
lz[now] = 0;
}
void solve(int now, int n) {
if (n == 0)
return;
if (lz[now])
updata(now, n);
int a = t[now][0], b = t[now][1], c = t[now][2];
t[now][1] = a;
t[now][2] = b;
t[now][0] = c;
solve(t[now][0], n - 1);
}
void getans(int now, int n, int b, int c) {
if (n == 0) {
ans[sum[now]] = c;
return;
}
if (lz[now])
updata(now, n);
getans(t[now][0], n - 1, b * 3, c);
getans(t[now][1], n - 1, b * 3, c + b);
getans(t[now][2], n - 1, b * 3, c + b + b);
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
build(rt, n, 1, 0);
for (int i = 1; s[i]; i++) {
if (s[i] == 'S')
lz[rt] ^= 1;
else
solve(rt, n);
}
getans(rt, n, 1, 0);
int sum = 1;
for (int i = 1; i <= n; i++)
sum *= 3;
for (int i = 0; i < sum; i++)
printf(i == sum - 1 ? "%d\n" : "%d ", ans[i]);
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02671 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 531500
void Read(int &p) {
p = 0;
char c = getchar();
for (; c < '0' || c > '9'; c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar())
p = p * 10 + c - '0';
}
int n, m, rot, cnt, val[N], ans[N];
char T[N];
struct Node {
int ch[3], rv, tg;
} S[N];
void Build(int &q, int d, int s) {
q = ++cnt;
if (d == n) {
S[q].tg = s;
return;
}
Build(S[q].ch[0], d + 1, s);
Build(S[q].ch[1], d + 1, s + val[d]);
Build(S[q].ch[2], d + 1, s + val[d] * 2);
}
void Pushdown(int q) {
if (S[q].rv) {
swap(S[q].ch[1], S[q].ch[2]);
S[S[q].ch[0]].rv ^= 1;
S[S[q].ch[1]].rv ^= 1;
S[S[q].ch[2]].rv ^= 1;
S[q].rv = 0;
}
}
void Insert(int q, int d) {
if (d == n)
return;
Pushdown(q);
int a = S[q].ch[0];
int b = S[q].ch[1];
int c = S[q].ch[2];
S[q].ch[1] = a;
S[q].ch[2] = b;
S[q].ch[0] = c;
Insert(S[q].ch[0], d + 1);
}
void Getans(int q, int d, int s) {
if (d == n) {
ans[S[q].tg] = s;
return;
}
Pushdown(q);
Getans(S[q].ch[0], d + 1, s);
Getans(S[q].ch[1], d + 1, s + val[d]);
Getans(S[q].ch[2], d + 1, s + val[d] * 2);
}
int main() {
Read(n);
val[0] = 1;
for (int i = 1; i <= n; i++)
val[i] = val[i - 1] * 3;
Build(rot, 0, 0);
scanf("%s", T + 1);
m = strlen(T + 1);
for (int i = 1; i <= m; i++)
if (T[i] == 'S')
S[rot].rv ^= 1;
else
Insert(rot, 0);
Getans(rot, 0, 0);
for (int i = 0; i < val[n]; i++)
printf("%d%c", ans[i], i == val[n] - 1 ? 10 : 32);
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 5000005
void Read(int &p) {
p = 0;
char c = getchar();
for (; c < '0' || c > '9'; c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar())
p = p * 10 + c - '0';
}
int n, m, rot, cnt, val[N], ans[N];
char T[N];
struct Node {
int ch[3], rv, tg;
} S[N];
void Build(int &q, int d, int s) {
q = ++cnt;
if (d == n) {
S[q].tg = s;
return;
}
Build(S[q].ch[0], d + 1, s);
Build(S[q].ch[1], d + 1, s + val[d]);
Build(S[q].ch[2], d + 1, s + val[d] * 2);
}
void Pushdown(int q) {
if (S[q].rv) {
swap(S[q].ch[1], S[q].ch[2]);
S[S[q].ch[0]].rv ^= 1;
S[S[q].ch[1]].rv ^= 1;
S[S[q].ch[2]].rv ^= 1;
S[q].rv = 0;
}
}
void Insert(int q, int d) {
if (d == n)
return;
Pushdown(q);
int a = S[q].ch[0];
int b = S[q].ch[1];
int c = S[q].ch[2];
S[q].ch[1] = a;
S[q].ch[2] = b;
S[q].ch[0] = c;
Insert(S[q].ch[0], d + 1);
}
void Getans(int q, int d, int s) {
if (d == n) {
ans[S[q].tg] = s;
return;
}
Pushdown(q);
Getans(S[q].ch[0], d + 1, s);
Getans(S[q].ch[1], d + 1, s + val[d]);
Getans(S[q].ch[2], d + 1, s + val[d] * 2);
}
int main() {
Read(n);
val[0] = 1;
for (int i = 1; i <= n; i++)
val[i] = val[i - 1] * 3;
Build(rot, 0, 0);
scanf("%s", T + 1);
m = strlen(T + 1);
for (int i = 1; i <= m; i++)
if (T[i] == 'S')
S[rot].rv ^= 1;
else
Insert(rot, 0);
Getans(rot, 0, 0);
for (int i = 0; i < val[n]; i++)
printf("%d%c", ans[i], i == val[n] - 1 ? 10 : 32);
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02671 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int M = 15, N = 600005;
int n, m, Q;
char s[N];
int Pw[M];
struct Trie {
struct Node {
int ch[3];
int val;
int tag;
Node() {
ch[0] = ch[1] = ch[2] = 0;
val = -1;
tag = 0;
return;
}
} trie[N];
int tot = 1;
void insert(int x) {
vector<int> v;
int t = x;
while (t)
v.push_back(t % 3), t /= 3;
while (v.size() < m)
v.push_back(0);
int u = 1;
for (int c : v) {
if (!trie[u].ch[c])
trie[u].ch[c] = ++tot;
u = trie[u].ch[c];
}
trie[u].val = x;
return;
}
void push_down(int u) {
if (!trie[u].tag)
return;
swap(trie[u].ch[1], trie[u].ch[2]);
for (int i = 0; i < 3; i++)
trie[trie[u].ch[i]].tag ^= 1;
trie[u].tag = 0;
return;
}
void reverse(int u) {
trie[u].tag ^= 1;
return;
}
void add(int u) {
if (!u)
return;
push_down(u);
int t = trie[u].ch[2];
trie[u].ch[2] = trie[u].ch[1];
trie[u].ch[1] = trie[u].ch[0];
trie[u].ch[0] = t;
add(trie[u].ch[0]);
return;
}
void query(int u, int sum, int dep, vector<int> &res) {
if (!u)
return;
push_down(u);
if (trie[u].val != -1)
res[trie[u].val] = sum;
for (int i = 0; i < 3; i++)
query(trie[u].ch[i], sum + i * Pw[dep], dep + 1, res);
return;
}
} T;
int main() {
scanf("%d", &m);
Pw[0] = 1;
for (int i = 1; i <= m; i++)
Pw[i] = Pw[i - 1] * 3;
n = Pw[m];
scanf("%s", s + 1);
Q = strlen(s + 1);
for (int i = 0; i < n; i++)
T.insert(i);
for (int i = 1; i <= Q; i++)
if (s[i] == 'S')
T.reverse(1);
else if (s[i] == 'R')
T.add(1);
vector<int> res;
res.resize(n);
T.query(1, 0, 0, res);
for (int u : res)
printf("%d ", u);
return 0;
} | #include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int M = 15, N = 600005;
int n, m, Q;
char s[N];
int Pw[M];
struct Trie {
struct Node {
int ch[3];
int val;
int tag;
Node() {
ch[0] = ch[1] = ch[2] = 0;
val = -1;
tag = 0;
return;
}
} trie[N * 3];
int tot = 1;
void insert(int x) {
vector<int> v;
int t = x;
while (t)
v.push_back(t % 3), t /= 3;
while (v.size() < m)
v.push_back(0);
int u = 1;
for (int c : v) {
if (!trie[u].ch[c])
trie[u].ch[c] = ++tot;
u = trie[u].ch[c];
}
trie[u].val = x;
return;
}
void push_down(int u) {
if (!trie[u].tag)
return;
swap(trie[u].ch[1], trie[u].ch[2]);
for (int i = 0; i < 3; i++)
trie[trie[u].ch[i]].tag ^= 1;
trie[u].tag = 0;
return;
}
void reverse(int u) {
trie[u].tag ^= 1;
return;
}
void add(int u) {
if (!u)
return;
push_down(u);
int t = trie[u].ch[2];
trie[u].ch[2] = trie[u].ch[1];
trie[u].ch[1] = trie[u].ch[0];
trie[u].ch[0] = t;
add(trie[u].ch[0]);
return;
}
void query(int u, int sum, int dep, vector<int> &res) {
if (!u)
return;
push_down(u);
if (trie[u].val != -1)
res[trie[u].val] = sum;
for (int i = 0; i < 3; i++)
query(trie[u].ch[i], sum + i * Pw[dep], dep + 1, res);
return;
}
} T;
int main() {
scanf("%d", &m);
Pw[0] = 1;
for (int i = 1; i <= m; i++)
Pw[i] = Pw[i - 1] * 3;
n = Pw[m];
scanf("%s", s + 1);
Q = strlen(s + 1);
for (int i = 0; i < n; i++)
T.insert(i);
for (int i = 1; i <= Q; i++)
if (s[i] == 'S')
T.reverse(1);
else if (s[i] == 'R')
T.add(1);
vector<int> res;
res.resize(n);
T.query(1, 0, 0, res);
for (int u : res)
printf("%d ", u);
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02671 | C++ | Runtime Error | #include <bits/stdc++.h>
#define calc(x) swap((x)->son[1], (x)->son[2])
using namespace std;
char s[200010];
struct Node {
int x, rev;
Node *son[3];
Node() { x = -1, son[0] = son[1] = son[2] = NULL, rev = 0; }
void pushdown() {
if (!rev)
return;
son[0]->rev ^= 1, son[1]->rev ^= 1, son[2]->rev ^= 1;
calc(son[0]), calc(son[1]), calc(son[2]);
rev = 0;
}
} pool[540000], *CUR = pool;
Node *Build(int l, int r, int dep, int x) {
if (l == r) {
CUR->x = x;
return CUR++;
}
Node *now = CUR++;
int m1 = l + (r - l + 1) / 3 - 1;
int m2 = l + (r - l + 1) / 3 * 2 - 1;
now->son[0] = Build(l, m1, dep * 3, x);
now->son[1] = Build(m1 + 1, m2, dep * 3, x + dep);
now->son[2] = Build(m2 + 1, r, dep * 3, x + dep * 2);
return now;
}
void Update(Node *T) {
if (T->x != -1)
return;
T->pushdown();
swap(T->son[0], T->son[2]), swap(T->son[1], T->son[2]);
Update(T->son[0]);
}
int ans[540000];
void print(Node *T, int dep, int x) {
if (T->x != -1) {
ans[T->x] = x;
return;
}
T->pushdown();
print(T->son[0], dep * 3, x);
print(T->son[1], dep * 3, x + dep);
print(T->son[2], dep * 3, x + dep * 2);
}
int main() {
int n;
scanf("%d", &n);
int N = 1;
for (int i = 0; i < n; i++) {
N *= 3;
}
N--;
Node *T = Build(0, N, 1, 0);
scanf("%s", s);
int m = strlen(s);
for (int i = 0; i < m; i++) {
if (s[i] == 'R')
Update(T);
else {
T->rev ^= 1;
calc(T);
}
}
print(T, 1, 0);
for (int i = 0; i <= N; i++) {
printf("%d ", ans[i]);
}
printf("\n");
return 0;
}
| #include <bits/stdc++.h>
#define calc(x) swap((x)->son[1], (x)->son[2])
using namespace std;
char s[200010];
struct Node {
int x, rev;
Node *son[3];
Node() { x = -1, son[0] = son[1] = son[2] = NULL, rev = 0; }
void pushdown() {
if (!rev)
return;
son[0]->rev ^= 1, son[1]->rev ^= 1, son[2]->rev ^= 1;
calc(son[0]), calc(son[1]), calc(son[2]);
rev = 0;
}
} pool[1500000], *CUR = pool;
Node *Build(int l, int r, int dep, int x) {
if (l == r) {
CUR->x = x;
return CUR++;
}
Node *now = CUR++;
int m1 = l + (r - l + 1) / 3 - 1;
int m2 = l + (r - l + 1) / 3 * 2 - 1;
now->son[0] = Build(l, m1, dep * 3, x);
now->son[1] = Build(m1 + 1, m2, dep * 3, x + dep);
now->son[2] = Build(m2 + 1, r, dep * 3, x + dep * 2);
return now;
}
void Update(Node *T) {
if (T->x != -1)
return;
T->pushdown();
swap(T->son[0], T->son[2]), swap(T->son[1], T->son[2]);
Update(T->son[0]);
}
int ans[540000];
void print(Node *T, int dep, int x) {
if (T->x != -1) {
ans[T->x] = x;
return;
}
T->pushdown();
print(T->son[0], dep * 3, x);
print(T->son[1], dep * 3, x + dep);
print(T->son[2], dep * 3, x + dep * 2);
}
int main() {
int n;
scanf("%d", &n);
int N = 1;
for (int i = 0; i < n; i++) {
N *= 3;
}
N--;
Node *T = Build(0, N, 1, 0);
scanf("%s", s);
int m = strlen(s);
for (int i = 0; i < m; i++) {
if (s[i] == 'R')
Update(T);
else {
T->rev ^= 1;
calc(T);
}
}
print(T, 1, 0);
for (int i = 0; i <= N; i++) {
printf("%d ", ans[i]);
}
printf("\n");
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p02671 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
template <class T> inline void checkmin(T &a, const T &b) {
if (b < a)
a = b;
}
template <class T> inline void checkmax(T &a, const T &b) {
if (b > a)
a = b;
}
const int inf = 1e9 + 10;
const int maxn = 1e6 + 10;
int a[maxn * 3][3], d[maxn * 3], id[maxn * 3], ans[maxn];
int n, p[15];
string s;
void build(int c, int x, int pos) {
if (c == n) {
// cout<<x<<" "<<pos<<endl;
id[x] = pos;
return;
}
for (int i = 0; i < 3; i++) {
a[x][i] = x * 3 + i;
build(c + 1, x * 3 + i, pos + i * p[c]);
}
}
void apply(int x) {
d[x] = !d[x];
swap(a[x][1], a[x][2]);
// cout<<a[x][1]<<" "<<a[x][2]<<endl;
}
void update(int x) {
if (d[x] == false)
return;
d[x] = false;
for (int i = 0; i < 3; i++)
apply(a[x][i]);
}
void add(int c, int x) {
if (c == n) {
return;
} else {
update(x);
swap(a[x][1], a[x][2]);
swap(a[x][0], a[x][1]);
add(c + 1, a[x][0]);
}
}
void dfs(int c, int x, int pos) {
if (c == n) {
ans[id[x]] = pos;
} else {
update(x);
for (int i = 0; i < 3; i++) {
dfs(c + 1, a[x][i], pos + i * p[c]);
}
}
}
int main() {
p[0] = 1;
for (int i = 1; i < 15; i++)
p[i] = p[i - 1] * 3;
cin >> n >> s;
int n2 = n;
build(0, 1, 0);
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'S') {
apply(1);
// cout<<i<<endl;
} else {
add(0, 1);
}
dfs(0, 1, 0);
// for(int i=0;i<3;i++) cout<<ans[i]<<" "; cout<<endl;
}
dfs(0, 1, 0);
n = 1;
for (int i = 0; i < n2; i++)
n = n * 3;
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
template <class T> inline void checkmin(T &a, const T &b) {
if (b < a)
a = b;
}
template <class T> inline void checkmax(T &a, const T &b) {
if (b > a)
a = b;
}
const int inf = 1e9 + 10;
const int maxn = 1e6 + 10;
int a[maxn * 3][3], d[maxn * 3], id[maxn * 3], ans[maxn];
int n, p[15];
string s;
void build(int c, int x, int pos) {
if (c == n) {
// cout<<x<<" "<<pos<<endl;
id[x] = pos;
return;
}
for (int i = 0; i < 3; i++) {
a[x][i] = x * 3 + i;
build(c + 1, x * 3 + i, pos + i * p[c]);
}
}
void apply(int x) {
d[x] = !d[x];
swap(a[x][1], a[x][2]);
// cout<<a[x][1]<<" "<<a[x][2]<<endl;
}
void update(int x) {
if (d[x] == false)
return;
d[x] = false;
for (int i = 0; i < 3; i++)
apply(a[x][i]);
}
void add(int c, int x) {
if (c == n) {
return;
} else {
update(x);
swap(a[x][1], a[x][2]);
swap(a[x][0], a[x][1]);
add(c + 1, a[x][0]);
}
}
void dfs(int c, int x, int pos) {
if (c == n) {
ans[id[x]] = pos;
} else {
update(x);
for (int i = 0; i < 3; i++) {
dfs(c + 1, a[x][i], pos + i * p[c]);
}
}
}
int main() {
p[0] = 1;
for (int i = 1; i < 15; i++)
p[i] = p[i - 1] * 3;
cin >> n >> s;
int n2 = n;
build(0, 1, 0);
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'S') {
apply(1);
// cout<<i<<endl;
} else {
add(0, 1);
}
// dfs(0,1,0);
// for(int i=0;i<3;i++) cout<<ans[i]<<" "; cout<<endl;
}
dfs(0, 1, 0);
n = 1;
for (int i = 0; i < n2; i++)
n = n * 3;
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
cout << endl;
return 0;
}
| replace | 89 | 90 | 89 | 90 | TLE | |
p02671 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
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;
}
int res[531441];
int P[14];
int nn;
void dfs(int id, int p, int q, string s) {
if (id == nn) {
res[p] = q;
return;
}
int n = s.size();
string t;
for (int i = 0; i < n; i++) {
if (s[i] == 'S') {
if (t.size() != 0 && t.back() == 'S') {
t.pop_back();
} else {
t.push_back(s[i]);
}
} else {
t.push_back(s[i]);
}
}
for (int pp = 0; pp < 3; pp++) {
string nxt;
int k = pp;
for (int i = 0; i < n; i++) {
if (t[i] == 'S') {
if (k == 1 || k == 2) {
k = 3 - k;
}
nxt.push_back('S');
} else if (t[i] == 'R') {
k++;
if (k == 3) {
nxt.push_back('R');
k = 0;
}
}
}
dfs(id + 1, p + P[id] * pp, q + P[id] * k, nxt);
}
}
int main() {
string s;
cin >> nn >> s;
P[0] = 1;
for (int i = 1; i <= 12; i++) {
P[i] = P[i - 1] * 3;
}
dfs(0, 0, 0, s);
int k = 1;
for (int i = 0; i < nn; i++) {
k *= 3;
}
rep(i, k) { cout << res[i] << " "; }
cout << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
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;
}
int res[531441];
int P[14];
int nn;
void dfs(int id, int p, int q, string s) {
if (id == nn) {
res[p] = q;
return;
}
int n = s.size();
string t;
for (int i = 0; i < n; i++) {
if (s[i] == 'S') {
if (t.size() != 0 && t.back() == 'S') {
t.pop_back();
} else {
t.push_back(s[i]);
}
} else {
t.push_back(s[i]);
}
}
for (int pp = 0; pp < 3; pp++) {
string nxt;
int k = pp;
for (int i = 0; i < t.size(); i++) {
if (t[i] == 'S') {
if (k == 1 || k == 2) {
k = 3 - k;
}
nxt.push_back('S');
} else if (t[i] == 'R') {
k++;
if (k == 3) {
nxt.push_back('R');
k = 0;
}
}
}
dfs(id + 1, p + P[id] * pp, q + P[id] * k, nxt);
}
}
int main() {
string s;
cin >> nn >> s;
P[0] = 1;
for (int i = 1; i <= 12; i++) {
P[i] = P[i - 1] * 3;
}
dfs(0, 0, 0, s);
int k = 1;
for (int i = 0; i < nn; i++) {
k *= 3;
}
rep(i, k) { cout << res[i] << " "; }
cout << endl;
return 0;
} | replace | 77 | 78 | 77 | 78 | 0 | |
p02673 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
#define mp make_pair
#define PI pair<ll, ll>
#define poly vector<ll>
#define mem(a) memset((a), 0, sizeof(a))
#define For(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define Rep(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(ll a) {
write(a);
puts("");
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
ll rnd() {
ull ans = 0;
For(i, 0, 4) ans = ans << 15 ^ rand();
return ans % ((ull)1 << 63);
}
const int N = 100005;
ld a[N], b[N], A[N], B[N], c[N], ans;
int q[N];
ld xie(int x, int y) { return (a[y] - a[x]) / (y - x); }
int main() {
#ifdef Brollan
freopen("1.in", "r", stdin);
#endif
int n = read();
int p = 0;
For(i, 1, n) {
a[i] = read();
if (a[i] >= a[p])
p = i;
}
For(i, 1, n) b[i] = -read();
For(i, 0, n - p) {
A[i] = a[i + p];
B[i] = b[i + p];
}
For(i, n - p + 1, n) {
A[i] = a[i + p - n];
B[i] = b[i + p - n];
}
c[0] = c[1] = 0;
For(i, 2, n) c[i] = 2 * (c[i - 1] - B[i - 1]) - c[i - 2];
For(i, 0, n) { a[i] = A[i] - c[i]; }
int top = 0;
For(i, 0, n) {
while (top >= 2 && xie(q[top - 1], q[top]) < xie(q[top], i))
top--;
q[++top] = i;
}
For(i, 1, top - 1) {
For(j, q[i], q[i + 1] - 1) ans +=
c[j] + ((j - q[i]) * a[q[i + 1]] + (q[i + 1] - j) * a[q[i]]) /
(q[i + 1] - q[i]);
}
printf("%.10f\n", ans / n);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
#define mp make_pair
#define PI pair<ll, ll>
#define poly vector<ll>
#define mem(a) memset((a), 0, sizeof(a))
#define For(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define Rep(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(ll a) {
write(a);
puts("");
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
ll rnd() {
ull ans = 0;
For(i, 0, 4) ans = ans << 15 ^ rand();
return ans % ((ull)1 << 63);
}
const int N = 200005;
ld a[N], b[N], A[N], B[N], c[N], ans;
int q[N];
ld xie(int x, int y) { return (a[y] - a[x]) / (y - x); }
int main() {
#ifdef Brollan
freopen("1.in", "r", stdin);
#endif
int n = read();
int p = 0;
For(i, 1, n) {
a[i] = read();
if (a[i] >= a[p])
p = i;
}
For(i, 1, n) b[i] = -read();
For(i, 0, n - p) {
A[i] = a[i + p];
B[i] = b[i + p];
}
For(i, n - p + 1, n) {
A[i] = a[i + p - n];
B[i] = b[i + p - n];
}
c[0] = c[1] = 0;
For(i, 2, n) c[i] = 2 * (c[i - 1] - B[i - 1]) - c[i - 2];
For(i, 0, n) { a[i] = A[i] - c[i]; }
int top = 0;
For(i, 0, n) {
while (top >= 2 && xie(q[top - 1], q[top]) < xie(q[top], i))
top--;
q[++top] = i;
}
For(i, 1, top - 1) {
For(j, q[i], q[i + 1] - 1) ans +=
c[j] + ((j - q[i]) * a[q[i + 1]] + (q[i + 1] - j) * a[q[i]]) /
(q[i + 1] - q[i]);
}
printf("%.10f\n", ans / n);
}
| replace | 55 | 56 | 55 | 56 | 0 | |
p02673 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define LL long long
#define db long double
using namespace std;
template <typename T> void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
inline void write(int x) {
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
const int N = 200050;
int n;
LL a[N], b[N], tmp[N], preb[N], prebi[N];
inline void init() {
int i, id = 1;
read(n);
for (i = 1; i <= n; ++i)
read(a[i]);
for (i = 1; i <= n; ++i)
read(b[i]);
for (i = 1; i <= n; ++i)
if (a[i] > a[id])
id = i;
if (id != 1) {
--id;
for (i = 1; i <= n; ++i)
tmp[i] = a[i];
for (i = 1; i <= n; ++i)
a[(i <= id ? i + n - id : i - id)] = tmp[i];
for (i = 1; i <= n; ++i)
tmp[i] = b[i];
for (i = 1; i <= n; ++i)
b[(i <= id ? i + n - id : i - id)] = tmp[i];
}
a[n + 1] = a[1], b[n + 1] = b[1];
a[0] = a[n], b[0] = b[n];
for (i = 1; i <= n + 1; ++i)
preb[i] = preb[i - 1] + b[i], prebi[i] = prebi[i - 1] + b[i] * i;
}
inline db calc(int l, int r, int m) {
if (l == r)
return a[l];
db k = r - l,
b = (db)(2.0) * (r) * (preb[r - 1] - preb[l]) -
(db)(2.0) * (prebi[r - 1] - prebi[l]),
y = a[r] - a[l], x = (y - b) / k;
return a[l] + (m - l) * x + (db)(2.0) * (m) * (preb[m - 1] - preb[l]) -
(db)(2.0) * (prebi[m - 1] - prebi[l]);
}
int stk[N], top;
db ans, mx[N];
int main() {
init();
int i, j, ll, rr;
stk[0] = 1;
for (i = 1; i <= n + 1; ++i) {
while (top && calc(stk[top - 1], i, stk[top]) >=
calc(stk[top - 1], stk[top], stk[top]))
--top;
stk[++top] = i;
}
for (ll = 1; ll <= n + 1; ++ll)
for (rr = ll; rr <= n + 1; ++rr)
for (i = ll; i <= rr; ++i)
mx[i] = max(mx[i], calc(ll, rr, i));
for (i = 0; i <= top; ++i) {
ll = stk[i], rr = stk[i + 1];
for (j = ll; j <= rr && j <= n; ++j)
mx[j] = max(mx[j], calc(ll, rr, j));
}
for (i = 1; i <= n; ++i)
ans += mx[i]; //,cerr << i << ' ' << mx[i] << '\n';
ans /= n;
cout << fixed << setprecision(20) << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#define LL long long
#define db long double
using namespace std;
template <typename T> void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
inline void write(int x) {
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
const int N = 200050;
int n;
LL a[N], b[N], tmp[N], preb[N], prebi[N];
inline void init() {
int i, id = 1;
read(n);
for (i = 1; i <= n; ++i)
read(a[i]);
for (i = 1; i <= n; ++i)
read(b[i]);
for (i = 1; i <= n; ++i)
if (a[i] > a[id])
id = i;
if (id != 1) {
--id;
for (i = 1; i <= n; ++i)
tmp[i] = a[i];
for (i = 1; i <= n; ++i)
a[(i <= id ? i + n - id : i - id)] = tmp[i];
for (i = 1; i <= n; ++i)
tmp[i] = b[i];
for (i = 1; i <= n; ++i)
b[(i <= id ? i + n - id : i - id)] = tmp[i];
}
a[n + 1] = a[1], b[n + 1] = b[1];
a[0] = a[n], b[0] = b[n];
for (i = 1; i <= n + 1; ++i)
preb[i] = preb[i - 1] + b[i], prebi[i] = prebi[i - 1] + b[i] * i;
}
inline db calc(int l, int r, int m) {
if (l == r)
return a[l];
db k = r - l,
b = (db)(2.0) * (r) * (preb[r - 1] - preb[l]) -
(db)(2.0) * (prebi[r - 1] - prebi[l]),
y = a[r] - a[l], x = (y - b) / k;
return a[l] + (m - l) * x + (db)(2.0) * (m) * (preb[m - 1] - preb[l]) -
(db)(2.0) * (prebi[m - 1] - prebi[l]);
}
int stk[N], top;
db ans, mx[N];
int main() {
init();
int i, j, ll, rr;
stk[0] = 1;
for (i = 1; i <= n + 1; ++i) {
while (top && calc(stk[top - 1], i, stk[top]) >=
calc(stk[top - 1], stk[top], stk[top]))
--top;
stk[++top] = i;
}
for (i = 0; i <= top; ++i) {
ll = stk[i], rr = stk[i + 1];
for (j = ll; j <= rr && j <= n; ++j)
mx[j] = max(mx[j], calc(ll, rr, j));
}
for (i = 1; i <= n; ++i)
ans += mx[i]; //,cerr << i << ' ' << mx[i] << '\n';
ans /= n;
cout << fixed << setprecision(20) << ans << '\n';
return 0;
} | delete | 76 | 80 | 76 | 76 | TLE | |
p02674 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int, int>
#define mk(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define eb(x, y) emplace_back(x, y)
#define fi first
#define se second
#define Rep(x, y, z) for (int x = y; x <= z; x++)
#define Red(x, y, z) for (int x = y; x >= z; x--)
using namespace std;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
return pp1 == pp2 &&
(pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
? EOF
: *pp1++;
}
// inline char gc(){return getchar();}
inline ll read() {
ll x = 0;
for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)
if (nc == 45)
ny = -1;
if (nc < 0)
return nc;
for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;
x = (x << 3) + (x << 1) + (nc ^ 48))
;
return x * ny;
}
const int table[6][20] = {
{},
{1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 36, 108, 220, 334, 384, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 976, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001,
1001, 1001}};
int G[105];
inline void Init() {
G[1] = 0;
Rep(n, 2, 100) for (int k = 1; k < n;
k++) if ((1 << k) >= n && (1 << k) - n >= G[k]) {
G[n] = k;
break;
}
}
inline int g(ll n) {
if (n <= 100)
return G[n];
for (int k = 1;; k++)
if ((1ll << k) >= n && (1ll << k) - n >= g(k))
return k;
}
ll n;
inline int Solve(int n, int k) {
if (n < k)
swap(n, k);
if (k < 63 && (1ll << k) - n < n)
return Solve((1ll << k) - n, k);
if (k > 5)
return 1001;
return k == 0 ? 1 : table[k][n];
}
int main() {
// freopen("std.in","r",stdin);
// freopen("std.out","w",stdout);
n = read(), Init();
int ans = Solve(n, g(n));
ans += (n == 4) + (n == 7) * 2;
cout << (ans > 1000 ? -1 : ans);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int, int>
#define mk(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define eb(x, y) emplace_back(x, y)
#define fi first
#define se second
#define Rep(x, y, z) for (int x = y; x <= z; x++)
#define Red(x, y, z) for (int x = y; x >= z; x--)
using namespace std;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
return pp1 == pp2 &&
(pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
? EOF
: *pp1++;
}
// inline char gc(){return getchar();}
inline ll read() {
ll x = 0;
for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)
if (nc == 45)
ny = -1;
if (nc < 0)
return nc;
for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;
x = (x << 3) + (x << 1) + (nc ^ 48))
;
return x * ny;
}
const int table[6][20] = {
{},
{1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 36, 108, 220, 334, 384, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 976, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001,
1001, 1001}};
int G[105];
inline void Init() {
G[1] = 0;
Rep(n, 2, 100) for (int k = 1; k < n;
k++) if ((1 << k) >= n && (1 << k) - n >= G[k]) {
G[n] = k;
break;
}
}
inline int g(ll n) {
if (n <= 100)
return G[n];
for (int k = 1;; k++)
if ((1ll << k) >= n && (1ll << k) - n >= g(k))
return k;
}
ll n;
inline int Solve(ll n, ll k) {
if (n < k)
swap(n, k);
if (k < 63 && (1ll << k) - n < n)
return Solve((1ll << k) - n, k);
if (k > 5)
return 1001;
return k == 0 ? 1 : table[k][n];
}
int main() {
// freopen("std.in","r",stdin);
// freopen("std.out","w",stdout);
n = read(), Init();
int ans = Solve(n, g(n));
ans += (n == 4) + (n == 7) * 2;
cout << (ans > 1000 ? -1 : ans);
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02675 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int sum = 0, num, num1;
cin >> num;
num1 = num;
while (0 < num1) {
num1 = (num1 / 10);
sum++;
}
sum = sum - 1;
while (sum > 0) {
num = num / 10;
}
switch (num) {
case 3:
std ::cout << "bon" << endl;
break;
case 0:
case 1:
case 6:
case 8:
std ::cout << "pon" << endl;
break;
default:
std ::cout << "hon" << endl;
break;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int sum = 0, num, num1;
cin >> num;
num1 = num;
if (num < 10) {
} else {
num = num % 10;
}
switch (num) {
case 3:
std ::cout << "bon" << endl;
break;
case 0:
case 1:
case 6:
case 8:
std ::cout << "pon" << endl;
break;
default:
std ::cout << "hon" << endl;
break;
}
return 0;
} | replace | 6 | 13 | 6 | 9 | TLE | |
p02675 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string N;
char n;
n = N.at(N.size() - 1);
if (n == '3') {
cout << "bon" << endl;
} else if (n == '0' or n == '1' or n == '6' or n == '8') {
cout << "pon" << endl;
} else {
cout << "hon" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string N;
char n;
cin >> N;
n = N.at(N.size() - 1);
if (n == '3') {
cout << "bon" << endl;
} else if (n == '0' or n == '1' or n == '6' or n == '8') {
cout << "pon" << endl;
} else {
cout << "hon" << endl;
}
}
| insert | 7 | 7 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 18446744073709551615) >= this->size() (which is 0)
|
p02675 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 3; i > 0; i++) {
N = N % (10 * i);
}
if (N == 3) {
cout << "bon" << endl;
}
if (N == 0 || N == 1 || N == 6 || N == 8) {
cout << "pon" << endl;
}
if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
cout << "hon" << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 3; i > 0; i--) {
N = N % (10 * i);
}
if (N == 3) {
cout << "bon" << endl;
}
if (N == 0 || N == 1 || N == 6 || N == 8) {
cout << "pon" << endl;
}
if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
cout << "hon" << endl;
}
return 0;
}
| replace | 6 | 7 | 6 | 7 | TLE | |
p02675 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
// defines
typedef long long ll;
ll solve(ll t) { /*hon when the digit in the one's place of
N
is
2
,
4
,
5
,
7
, or
9
;
pon when the digit in the one's place of
N
is
0
,
1
,
6
or
8
;
bon when the digit in the one's place of
N
is
3
.*/
string s;
cin >> s;
ll n = s.size() - 1;
if (s[n] == '0' or s[n] == '1' or s[n] == '6' or s[n] == '8')
cout << "pon";
else if (s[n] == '3')
cout << "bon";
else
cout << "hon";
if (t > 0)
cout << "\n";
}
int32_t main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
solve(t);
}
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
// defines
typedef long long ll;
ll solve(ll t) { /*hon when the digit in the one's place of
N
is
2
,
4
,
5
,
7
, or
9
;
pon when the digit in the one's place of
N
is
0
,
1
,
6
or
8
;
bon when the digit in the one's place of
N
is
3
.*/
string s;
cin >> s;
ll n = s.size() - 1;
if (s[n] == '0' or s[n] == '1' or s[n] == '6' or s[n] == '8')
cout << "pon";
else if (s[n] == '3')
cout << "bon";
else
cout << "hon";
if (t > 0)
cout << "\n";
return 0;
}
int32_t main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
solve(t);
}
return 0;
} | insert | 54 | 54 | 54 | 55 | 0 | |
p02675 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 10 == 3)
cout << "bon";
else if (n % 0 == 0 || n % 0 == 1 || n % 0 == 6 || n % 0 == 8)
cout << "pon";
else
cout << "hon";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 10 == 3)
cout << "bon";
else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
cout << "pon";
else
cout << "hon";
} | replace | 8 | 9 | 8 | 9 | -8 | |
p02675 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
//{{{ read()
inline int read() {
register int x = 0, f = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
//}}}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n = read(), f1 = 0, f2 = 0, f3 = 0;
while (n) {
int y = n % 10;
if (y == 0 || y == 1 || y == 6 || y == 8)
f2 = 1;
if (y == 2 || y == 4 || y == 5 || y == 7 || y == 9)
f1 = 1;
if (y == 3)
f3 = 1;
}
if (f3)
puts("bon");
else if (f2)
puts("pon");
else
puts("hon");
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
//{{{ read()
inline int read() {
register int x = 0, f = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
//}}}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n = read(), f1 = 0, f2 = 0, f3 = 0;
int y = n % 10;
if (y == 0 || y == 1 || y == 6 || y == 8)
f2 = 1;
if (y == 2 || y == 4 || y == 5 || y == 7 || y == 9)
f1 = 1;
if (y == 3)
f3 = 1;
if (f3)
puts("bon");
else if (f2)
puts("pon");
else
puts("hon");
return 0;
}
| replace | 25 | 34 | 25 | 32 | TLE | |
p02675 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int out;
while (n > 0) {
if (n / 10 == 0)
out = n;
else
n = n % 10;
}
string output;
if (out == 2 || out == 4 || out == 5 || out == 7 || out == 9)
output = "hon";
else if (out == 0 || out == 1 || out == 6 || out == 8)
output = "pon";
else
output = "bon";
cout << output;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int out = n % 10;
string output;
if (out == 2 || out == 4 || out == 5 || out == 7 || out == 9)
output = "hon";
else if (out == 0 || out == 1 || out == 6 || out == 8)
output = "pon";
else
output = "bon";
cout << output;
} | replace | 7 | 14 | 7 | 8 | TLE | |
p02675 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// 12 10
// --------------------------------------------------------------------------------
#define fast_IO ios_base::sync_with_stio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define deb(name, value) cout << "->> " << name << "= " << value << " "
#define frepi(a, b, k) for (int i = a; i <= b; i += k)
#define frepj(a, b, k) for (int j = a; j <= b; j += k)
// --------------------------------------------------------------------------------
void solve() {
int n;
cin >> n;
vector<string> s;
s[0] = "hon";
s[1] = "pon";
s[2] = "bon";
int r = n % 10;
if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9) {
cout << s[0] << "\n";
return;
}
if (r == 3) {
cout << s[2];
return;
}
cout << s[1];
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("/home/suryakant/input.txt","r",stdin);
// freopen("/home/suryakant/output.txt","w",stdout);
// #endif
int t = 1;
// cin>>t;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
// 12 10
// --------------------------------------------------------------------------------
#define fast_IO ios_base::sync_with_stio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define deb(name, value) cout << "->> " << name << "= " << value << " "
#define frepi(a, b, k) for (int i = a; i <= b; i += k)
#define frepj(a, b, k) for (int j = a; j <= b; j += k)
// --------------------------------------------------------------------------------
void solve() {
int n;
cin >> n;
vector<string> s(3);
s[0] = "hon";
s[1] = "pon";
s[2] = "bon";
int r = n % 10;
if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9) {
cout << s[0] << "\n";
return;
}
if (r == 3) {
cout << s[2];
return;
}
cout << s[1];
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("/home/suryakant/input.txt","r",stdin);
// freopen("/home/suryakant/output.txt","w",stdout);
// #endif
int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| replace | 15 | 16 | 15 | 16 | -11 | |
p02675 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, i, m, j, k, s, a;
int main() {
scanf("%d", n);
n = n % 10;
if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
printf("hon");
} else if (n == 0 || n == 1 || n == 6 || n == 8) {
printf("pon");
} else if (n == 3) {
printf("bon");
}
} | #include <bits/stdc++.h>
using namespace std;
int n, i, m, j, k, s, a;
int main() {
scanf("%d", &n);
n = n % 10;
if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
printf("hon");
} else if (n == 0 || n == 1 || n == 6 || n == 8) {
printf("pon");
} else if (n == 3) {
printf("bon");
}
} | replace | 4 | 5 | 4 | 5 | -11 | |
p02675 | Python | Runtime Error | d = {n: "hon" for n in "24579"}
d.update({n: "pon" for n in "0168"})
d.update({3: "bon"})
print(d[input()[-1]])
| d = {n: "hon" for n in "24579"}
d.update({n: "pon" for n in "0168"})
d.update({"3": "bon"})
print(d[input()[-1]])
| replace | 2 | 3 | 2 | 3 | 0 | |
p02675 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
int n;
cin >> n;
vector<string> s;
s[0] = "pon";
s[1] = "pon";
s[2] = "hon";
s[3] = "bon";
s[4] = "hon";
s[5] = "hon";
s[6] = "pon";
s[7] = "hon";
s[8] = "pon";
s[9] = "hon";
cout << s[n % 10] << "\n";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
int n;
cin >> n;
vector<string> s(10);
s[0] = "pon";
s[1] = "pon";
s[2] = "hon";
s[3] = "bon";
s[4] = "hon";
s[5] = "hon";
s[6] = "pon";
s[7] = "hon";
s[8] = "pon";
s[9] = "hon";
cout << s[n % 10] << "\n";
return 0;
} | replace | 9 | 10 | 9 | 10 | -11 | |
p02675 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<string> X;
X[0] = "pon";
X[1] = "pon";
X[2] = "hon";
X[3] = "bon";
X[4] = "hon";
X[5] = "hon";
X[6] = "pon";
X[7] = "hon";
X[8] = "pon";
X[9] = "hon";
int Y;
cin >> Y;
int S = Y % 10;
cout << X[S] << endl;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<string> X(10);
X[0] = "pon";
X[1] = "pon";
X[2] = "hon";
X[3] = "bon";
X[4] = "hon";
X[5] = "hon";
X[6] = "pon";
X[7] = "hon";
X[8] = "pon";
X[9] = "hon";
int Y;
cin >> Y;
int S = Y % 10;
cout << X[S] << endl;
} | replace | 5 | 6 | 5 | 6 | -11 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
string s;
cin >> k;
cin >> s;
if (s.size() <= k) {
cout << s;
} else {
cout << s.at(0) << s.at(1) << s.at(2) << s.at(3) << s.at(4) << s.at(5)
<< s.at(6) << "...";
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
string s;
cin >> k;
cin >> s;
if (s.size() <= k) {
cout << s;
} else {
for (int i = 0; i < k; i++) {
cout << s.at(i);
}
cout << "...";
}
}
| replace | 12 | 15 | 12 | 16 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t K;
string S;
cin >> K >> S;
int64_t s_size = S.size();
if (s_size <= K) {
cout << S << endl;
} else {
cout << S.erase(7) << "..." << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t K;
string S;
cin >> K >> S;
int64_t s_size = S.size();
if (s_size <= K) {
cout << S << endl;
} else {
cout << S.erase(K) << "..." << endl;
}
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int K;
string S;
cin >> K;
cin >> S;
if (K >= sizeof(S)) {
cout << S << endl;
} else {
S = S.erase(K);
S = S + "...";
cout << S << endl;
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int K;
string S;
cin >> K;
cin >> S;
if (K >= S.length()) {
cout << S << endl;
} else {
S = S.erase(K);
S = S + "...";
cout << S << endl;
}
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
string S;
int L, K;
cin >> K;
cin >> S;
char ch;
L = S.length();
if (L <= K) {
cout << S << "";
} else {
for (int i = 0; i <= L; i++) {
ch = S.at(i);
cout << ch;
}
cout << "...";
}
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
string S;
int L, K;
cin >> K;
cin >> S;
char ch;
L = S.length();
if (L <= K) {
cout << S << "";
} else {
for (int i = 0; i <= (K - 1); i++) {
ch = S.at(i);
cout << ch;
}
cout << "...";
}
return 0;
} | replace | 13 | 14 | 13 | 14 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 15) >= this->size() (which is 15)
|
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int k;
string s;
cin >> k >> s;
string ans;
char add;
rep(i, k) {
add = s.at(i);
ans += add;
}
if (s.size() > k)
ans += "...";
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int k;
string s;
cin >> k >> s;
string ans;
char add;
rep(i, k) {
try {
add = s.at(i);
} catch (out_of_range) {
break;
}
ans += add;
}
if (s.size() > k)
ans += "...";
cout << ans << endl;
return 0;
} | replace | 13 | 14 | 13 | 18 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
string s;
cin >> s;
long long a = s.size();
if (a < k + 1) {
cout << s << endl;
} else {
for (int i = 0; i < 7; i++) {
cout << s.at(i);
}
cout << "..." << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
string s;
cin >> s;
long long a = s.size();
if (a < k + 1) {
cout << s << endl;
} else {
for (int i = 0; i < k; i++) {
cout << s.at(i);
}
cout << "..." << endl;
}
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
int main() {
string s, t;
int k;
cin >> k >> s;
if (s.size() <= k)
cout << s << endl;
if (s.size() > k) {
for (int i = 0; i < 7; i++) {
t.push_back(s.at(i));
}
cout << t + "..." << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
int main() {
string s, t;
int k;
cin >> k >> s;
if (s.size() <= k)
cout << s << endl;
if (s.size() > k) {
for (int i = 0; i < k; i++) {
t.push_back(s.at(i));
}
cout << t + "..." << endl;
}
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int X;
cin >> X;
string A;
cin >> A;
int B = 0;
if (A.size() <= X) {
cout << A << endl;
} else {
B = X - A.size();
cout << A.at(0) << A.at(1) << A.at(2) << A.at(3) << A.at(4) << A.at(5)
<< A.at(6) << "..." << endl;
}
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int X;
cin >> X;
string A;
cin >> A;
int B = 0;
if (A.size() <= X) {
cout << A << endl;
} else {
B = X - A.size();
for (int i = 0; i < X; i++) {
cout << A.at(i);
}
cout << "..." << endl;
}
} | replace | 14 | 16 | 14 | 18 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll)(1e9)
#define mod (ll)(1e9 + 7)
#define endl "\n"
#define tt \
ll testcase; \
cin >> testcase; \
while (testcase--)
const int mxn = 1e5 + 5;
ll n;
int solve() {
cin >> n;
string s;
cin >> s;
ll k = s.size();
if (k <= n) {
cout << s;
} else {
// string t = s.substr(0, n);
cout << s.substr(0, n) << "...";
}
}
int main() {
fast;
ll testcase;
testcase = 1;
// cin>>testcase;
while (testcase--) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll)(1e9)
#define mod (ll)(1e9 + 7)
#define endl "\n"
#define tt \
ll testcase; \
cin >> testcase; \
while (testcase--)
const int mxn = 1e5 + 5;
ll n;
void solve() {
cin >> n;
string s;
cin >> s;
ll k = s.size();
if (k <= n) {
cout << s;
} else {
// string t = s.substr(0, n);
cout << s.substr(0, n) << "...";
}
}
int main() {
fast;
ll testcase;
testcase = 1;
// cin>>testcase;
while (testcase--) {
solve();
}
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int ABC_168_B() {
int k;
string s;
string s_r;
cin >> k;
cin >> s;
if (s.size() <= k) {
cout << s << endl;
} else {
s_r = s.erase(7);
cout << s_r << "..." << endl;
}
return 0;
}
int main() {
ABC_168_B();
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int ABC_168_B() {
int k;
string s;
string s_r;
cin >> k;
cin >> s;
if (s.size() <= k) {
cout << s << endl;
} else {
s_r = s.erase(k);
cout << s_r << "..." << endl;
}
return 0;
}
int main() {
ABC_168_B();
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
#include <string>
int main() {
int K;
std::string S;
std::cin >> K >> S;
if (K > S.size()) {
for (int i = 0; i < K; ++i) {
std::cout << S.at(i);
}
std::cout << "...\n";
} else {
std::cout << S << "\n";
}
return 0;
} | #include <iostream>
#include <string>
int main() {
int K;
std::string S;
std::cin >> K >> S;
if (K < S.size()) {
for (int i = 0; i < K; ++i) {
std::cout << S.at(i);
}
std::cout << "...\n";
} else {
std::cout << S << "\n";
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define int32 int32_t
using namespace std;
int32 main() {
ios_base::sync_with_stdio(false);
int k;
string s;
cin >> k >> s;
if (k >= s.size()) {
cout << s;
return 1;
} else {
cout << s.substr(0, k) + "...";
}
return 0;
} | #include <bits/stdc++.h>
#define int long long
#define int32 int32_t
using namespace std;
int32 main() {
ios_base::sync_with_stdio(false);
int k;
string s;
cin >> k >> s;
if (k >= s.size()) {
cout << s;
return 0;
} else {
cout << s.substr(0, k) + "...";
}
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void) {
int N = 0;
string S;
cin >> N;
cin >> S;
for (int i = 0; i < N; i++) {
cout << S.at(i);
}
if (S.size() > N) {
cout << "...";
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void) {
int N = 0;
string S;
cin >> N;
cin >> S;
int A = S.size();
int R = min(A, N);
for (int i = 0; i < R; i++) {
cout << S.at(i);
}
if (S.size() > N) {
cout << "...";
}
} | replace | 10 | 11 | 10 | 13 | 0 | |
p02676 | Python | Runtime Error | k = int(input())
s = list(map(str, input()))
if len(s) > k:
for i in range(k):
print(s[i], end="")
print("...")
else:
for i in s:
print(s[i], end="")
print()
| k = int(input())
s = list(map(str, input()))
if len(s) > k:
for i in range(k):
print(s[i], end="")
print("...")
else:
for i in s:
print(i, end="")
print()
| replace | 8 | 9 | 8 | 9 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K = 0;
string S;
cin >> K >> S;
if (S.size() <= K)
cout << S;
else {
for (int i = 0; i < 7; i++) {
cout << S.at(i);
}
cout << "...";
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K = 0;
string S;
cin >> K >> S;
if (S.size() <= K)
cout << S;
else {
for (int i = 0; i < K; i++) {
cout << S.at(i);
}
cout << "...";
}
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02676 | C++ | Runtime Error | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
int main() {
int K;
string S;
cin >> K >> S;
int A = S.size();
string B = S.substr(K - 1);
if (A <= K) {
cout << S << endl;
}
else {
cout << B << "..." << endl;
}
} | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
int main() {
int K;
string S;
cin >> K >> S;
int A = S.size();
string B = S.substr(0, K);
if (A <= K) {
cout << S << endl;
}
else {
cout << B << "..." << endl;
}
} | replace | 25 | 26 | 25 | 26 | 0 | |
p02676 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int K;
string S;
cin >> K >> S;
if (S.size() > 7) {
cout << S.erase(K) << "..." << endl;
} else {
cout << S << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int K;
string S;
cin >> K >> S;
if (S.size() > K) {
cout << S.erase(K) << "..." << endl;
} else {
cout << S << endl;
}
} | replace | 27 | 28 | 27 | 28 | 0 | |
p02676 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <type_traits>
#include <utility>
#include <vector>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int max(int a, int b) {
int max;
if (a > b)
max = a;
else
max = b;
return max;
}
int min(int a, int b) {
int min;
if (a < b)
min = a;
else
min = b;
return min;
}
int main() {
string s;
int k;
string t;
cin >> k;
cin >> s;
if (s.size() <= k) {
cout << s << endl;
} else {
for (int i = 0; i < k; i++) {
t.at(i) = s.at(i);
}
cout << t << "..." << endl;
}
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <type_traits>
#include <utility>
#include <vector>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int max(int a, int b) {
int max;
if (a > b)
max = a;
else
max = b;
return max;
}
int min(int a, int b) {
int min;
if (a < b)
min = a;
else
min = b;
return min;
}
int main() {
string s;
int k;
string t;
cin >> k;
cin >> s;
if (s.size() <= k) {
cout << s << endl;
} else {
rep(i, k) { cout << s[i]; }
cout << "..." << endl;
}
} | replace | 52 | 58 | 52 | 54 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int k;
cin >> k;
string a, p;
cin >> a;
int b;
b = a.size();
if (k >= b) {
cout << a << endl;
} else {
p = a.substr(a.at(0), k);
cout << p << "..." << endl;
}
return (0);
} | #include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int k;
cin >> k;
string a, p;
cin >> a;
int b;
b = a.size();
if (k >= b) {
cout << a << endl;
} else {
p = a.substr(0, k);
cout << p << "..." << endl;
}
return (0);
} | replace | 14 | 15 | 14 | 15 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 110) > this->size() (which is 15)
|
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define fprintf \
if (false) \
fprintf
#endif
#define debug_int(x) fprintf(stderr, "%s = %d\n", #x, x)
#define debug_double(x) fprintf(stderr, "%s = %llf\n", #x, x)
#define debug_array(v, n) \
fprintf(stderr, "%s = [ ", #v); \
for (int i = 0; i < n; i++) \
fprintf(stderr, "%d ", v[i]); \
fprintf(stderr, "]\n")
#define forr(i, start, end) for (int i = start; i < end; i++)
using lli = long long int;
using ii = pair<int, int>;
const int MAXN = 100010;
int main() {
int k;
char s[128];
scanf("%d %s", k, s);
int n = strlen(s);
if (n <= k) {
printf("%s\n", s);
} else {
s[k] = 0;
printf("%s...\n", s);
}
}
| #include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define fprintf \
if (false) \
fprintf
#endif
#define debug_int(x) fprintf(stderr, "%s = %d\n", #x, x)
#define debug_double(x) fprintf(stderr, "%s = %llf\n", #x, x)
#define debug_array(v, n) \
fprintf(stderr, "%s = [ ", #v); \
for (int i = 0; i < n; i++) \
fprintf(stderr, "%d ", v[i]); \
fprintf(stderr, "]\n")
#define forr(i, start, end) for (int i = start; i < end; i++)
using lli = long long int;
using ii = pair<int, int>;
const int MAXN = 100010;
int main() {
int k;
char s[128];
scanf("%d %s", &k, s);
int n = strlen(s);
if (n <= k) {
printf("%s\n", s);
} else {
s[k] = 0;
printf("%s...\n", s);
}
}
| replace | 25 | 26 | 25 | 26 | -11 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
string S;
string ans = "", dots = "...";
cin >> K >> S;
for (int i = 0; i < K; i++) {
ans.push_back(S.at(i));
}
if (K < S.size()) {
ans += dots;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
string S;
string ans = "", dots = "...";
cin >> K >> S;
for (int i = 0; i < K; i++) {
if (i >= S.size()) {
break;
}
ans.push_back(S.at(i));
}
if (K < S.size()) {
ans += dots;
}
cout << ans << endl;
} | insert | 9 | 9 | 9 | 12 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int k;
string s;
cin >> k >> s;
int r = k;
s.erase(r, s.length() - k);
s += "...";
cout << s;
}
| #include <iostream>
using namespace std;
int main() {
int k;
string s;
cin >> k >> s;
if (k >= s.length()) {
cout << s;
return 0;
}
s += " ";
for (int i = 0; i < k; i++) {
if (s[i] == ' ')
break;
cout << s[i];
}
cout << "...";
return 0;
}
| replace | 8 | 12 | 8 | 20 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i = (int)N - 1; i >= 0; i--)
#define RLOOP(i, N) for (int i = (int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
int main() {
int k;
string s;
cin >> k >> s;
int len = s.size();
if (k >= len) {
cout << s << endl;
} else {
for (int i = k; i < k + 3; i++) {
s[i] = '.';
}
s.erase(k + 3);
cout << s << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i = (int)N - 1; i >= 0; i--)
#define RLOOP(i, N) for (int i = (int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
int main() {
int k;
string s;
cin >> k >> s;
int len = s.size();
if (k >= len) {
cout << s << endl;
} else {
s.erase(k);
s += '.';
s += '.';
s += '.';
cout << s << endl;
}
}
| replace | 26 | 30 | 26 | 30 | 0 | |
p02676 | C++ | Runtime Error | /**********************************************************************
File hoge.cpp
Author harunaya
Date 2020-05-17(Sun)
note
**********************************************************************/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int k;
cin >> k;
string s;
cin >> s;
int temp = s.size();
if (temp <= k) {
cout << s << endl;
} else {
for (int i = 0; i < 7; ++i) {
cout << s.at(i);
}
cout << "..." << endl;
}
return 0;
} | /**********************************************************************
File hoge.cpp
Author harunaya
Date 2020-05-17(Sun)
note
**********************************************************************/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int k;
cin >> k;
string s;
cin >> s;
int temp = s.size();
if (temp <= k) {
cout << s << endl;
} else {
for (int i = 0; i < k; ++i) {
cout << s.at(i);
}
cout << "..." << endl;
}
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int K;
string S;
cin >> K >> S;
if (sizeof(S) <= K) {
cout << S << endl;
} else {
for (int i = 0; i < K; i++) {
cout << S.at(i);
}
cout << "..." << endl;
}
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int K;
string S;
cin >> K >> S;
if (S.size() <= K) {
cout << S << endl;
} else {
for (int i = 0; i < K; i++) {
cout << S.at(i);
}
cout << "..." << endl;
}
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02676 | C++ | Runtime Error | #include <iostream>
#include <string>
int main() {
int k;
std::string s;
std::cin >> k >> s;
std::cout << s.erase(k) + (k < s.size() ? "..." : "") << std::endl;
}
| #include <iostream>
#include <string>
int main() {
int k;
std::string s;
std::cin >> k >> s;
std::cout << (k < s.size() ? s.erase(k) + "..." : s) << std::endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02676 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main() {
char a[101];
int b, c;
scanf("%d", &b);
scanf("%s", a);
for (c = 0; c < strlen(a) - 1; c++)
printf("%s", a[c]);
}
| #include <stdio.h>
#include <string.h>
int main() {
int g;
char c[101];
scanf("%d ", &g);
scanf("%s", c);
int len = strlen(c);
if (len <= g) {
printf("%s\n", c);
} else {
for (int i = 0; i < g; i++) {
printf("%c", c[i]);
}
printf("...\n");
}
return 0;
} | replace | 3 | 9 | 3 | 17 | -11 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) \
for (auto x : (v)) \
cout << x << " "; \
cout << endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int, int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;
}
template <class T> inline T powerM(T a, T b) {
if (b == 0)
return 1;
T tmp = powerM(a, b / 2);
if (b % 2 == 0)
return tmp * tmp % MOD;
else
return tmp * tmp % MOD * a % MOD;
}
template <class T> inline T power(T a, T b, T m) {
if (b == 0)
return 1;
T tmp = power(a, b / 2, m);
if (b % 2 == 0)
return tmp * tmp % m;
else
return tmp * tmp % m * a % m;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ax+by=gcd(a,b)を解く
template <class T> inline T extgcd(T a, T b, T &x, T &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
T d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
void hey() { cout << "hey" << endl; }
template <class T> struct edge {
int to;
T cost;
};
int main() {
// int n; cin >>n;
// string s; cin >>s;
// for (int i=0; i<n; i++){
// cout <<i <<" " <<s[i] <<endl;;
// if (i >= n) cout <<"hey" <<endl;
// }
// if ((int)s.size() > n) cout <<"...";
// cout <<endl;
// cout <<s[16384] <<endl;
string s = "ferelibenterhominesidquodvoluntcredunt";
cout << s[57520000] << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) \
for (auto x : (v)) \
cout << x << " "; \
cout << endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int, int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;
}
template <class T> inline T powerM(T a, T b) {
if (b == 0)
return 1;
T tmp = powerM(a, b / 2);
if (b % 2 == 0)
return tmp * tmp % MOD;
else
return tmp * tmp % MOD * a % MOD;
}
template <class T> inline T power(T a, T b, T m) {
if (b == 0)
return 1;
T tmp = power(a, b / 2, m);
if (b % 2 == 0)
return tmp * tmp % m;
else
return tmp * tmp % m * a % m;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ax+by=gcd(a,b)を解く
template <class T> inline T extgcd(T a, T b, T &x, T &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
T d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
void hey() { cout << "hey" << endl; }
template <class T> struct edge {
int to;
T cost;
};
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (s.size() <= n) {
cout << s;
} else {
for (int i = 0; i < n; i++)
cout << s[i];
cout << "...";
}
cout << endl;
}
| replace | 74 | 85 | 74 | 86 | -11 | |
p02676 | C++ | Runtime Error | /**
* created: 17.05.2020 21:02:58
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
int main() {
int k;
cin >> k;
string s;
cin >> s;
int n = s.size();
if (n <= k) {
cout << s << endl;
} else {
// cout << 11 << endl;
string ans;
rep(i, k + 3) {
if (i <= k - 1)
ans[i] = s[i];
else
ans[i] = '.';
}
rep(i, k + 3) cout << ans[i];
cout << endl;
}
} | /**
* created: 17.05.2020 21:02:58
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
int main() {
int k;
cin >> k;
string s;
cin >> s;
int n = s.size();
if (n <= k) {
cout << s << endl;
} else {
// cout << 11 << endl;
string ans;
// cout << "k+3:" <<k+3<< endl;
/*rep(i,k+3){
if(i<=k-1)
ans[i] = s[i];
else
ans[i] = '.';
cout << i << endl;
}*/
ans = s.substr(0, k);
ans += "...";
// rep(i, ans.size()) cout << ans[i];
// cout << endl;
cout << ans << endl;
}
} | replace | 21 | 29 | 21 | 34 | 0 | |
p02676 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
int K, i, l;
cin >> K;
cin >> S;
l = sizeof(S);
if (l <= K)
cout << S;
else {
for (i = 0; i < K; i++) {
cout << S.at(i);
}
cout << "...";
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
int K, i, l;
cin >> K;
cin >> S;
if (S.size() <= K)
cout << S;
else {
for (i = 0; i < K; i++) {
cout << S.at(i);
}
cout << "...";
}
} | replace | 8 | 10 | 8 | 9 | 0 | |
p02677 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
// defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define prev _prev
#define y0 _y0
#define kill _kill
#define MAX 10000
#define pie 3.1415926535898
ll solve(ll t) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
ld hm = 0.5 * (c * 60 + d);
ld mm = 6 * d;
hm = (pie * hm) / 180.0;
mm = (pie * mm) / 180.0;
ld ans = (a * cos(hm) - b * cos(mm)) * (a * cos(hm) - b * cos(mm)) +
(a * sin(hm) - b * sin(mm)) * (a * sin(hm) - b * sin(mm));
ans = sqrt(ans);
cout << fixed << setprecision(20) << ans;
if (t > 0)
cout << "\n";
}
int32_t main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
solve(t);
}
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
// defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define prev _prev
#define y0 _y0
#define kill _kill
#define MAX 10000
#define pie 3.1415926535898
ll solve(ll t) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
ld hm = 0.5 * (c * 60 + d);
ld mm = 6 * d;
hm = (pie * hm) / 180.0;
mm = (pie * mm) / 180.0;
ld ans = (a * cos(hm) - b * cos(mm)) * (a * cos(hm) - b * cos(mm)) +
(a * sin(hm) - b * sin(mm)) * (a * sin(hm) - b * sin(mm));
ans = sqrt(ans);
cout << fixed << setprecision(20) << ans;
if (t > 0)
cout << "\n";
return 0;
}
int32_t main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
solve(t);
}
return 0;
}
| insert | 34 | 34 | 34 | 35 | 0 | |
p02677 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
#define pi 3.1415926535897932
// to set precision use fixed,setprecision(number_of_points_after_decimal
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define mod 1000000007
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
void solution() {
long double a, b, h, m;
cin >> a >> b >> h >> m;
long double md = m * 6.0;
long double hd = 30.0 * h + md / 12;
long double deg = abs(hd - md);
long double codeg = cos(deg * (pi / 180));
long double answer = a * a + b * b - 2 * a * b * codeg;
answer = sqrt(answer);
cout << fixed << setprecision(10) << answer << endl;
}
int main() {
#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
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t;
cin >> t;
while (t--) {
solution();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define pi 3.1415926535897932
// to set precision use fixed,setprecision(number_of_points_after_decimal
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define mod 1000000007
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
void solution() {
long double a, b, h, m;
cin >> a >> b >> h >> m;
long double md = m * 6.0;
long double hd = 30.0 * h + md / 12;
long double deg = abs(hd - md);
long double codeg = cos(deg * (pi / 180));
long double answer = a * a + b * b - 2 * a * b * codeg;
answer = sqrt(answer);
cout << fixed << setprecision(10) << answer << endl;
}
int main() {
#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
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
// int t;cin>>t;
// while(t--){
solution();
// }
return 0;
} | replace | 35 | 40 | 35 | 39 | -6 | terminate called after throwing an instance of 'std::__ios_failure'
what(): basic_ios::clear: iostream error
|
p02677 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <set>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Rep(i, n) for (ll i = 0; i <= n; ++i)
#define yes "yes"
#define Yes "Yes"
#define no "no"
#define No "No"
namespace mydef {
void say(string some) { cout << some << "\n"; }
} // namespace mydef
using namespace mydef;
typedef long long ll;
const int INF = 1001001001;
const long double PI = 3.14159265358979323846;
// ここからいじる
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
long double a, b, h, m;
cin >> a >> b >> h >> m;
m += h * 60;
long double limit = 60 * 12 / 11;
while (m < limit) {
m -= limit;
}
long double rad = m * 11 * PI / 360;
long double C = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad);
long double c = pow(C, 0.5);
cout << setprecision(11) << c << endl;
return 0;
} | #include <bits/stdc++.h>
#include <set>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Rep(i, n) for (ll i = 0; i <= n; ++i)
#define yes "yes"
#define Yes "Yes"
#define no "no"
#define No "No"
namespace mydef {
void say(string some) { cout << some << "\n"; }
} // namespace mydef
using namespace mydef;
typedef long long ll;
const int INF = 1001001001;
const long double PI = 3.14159265358979323846;
// ここからいじる
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
long double a, b, h, m;
cin >> a >> b >> h >> m;
m += h * 60;
long double limit = 60 * 12 / 11;
// while (m < limit)
// {
// m -= limit;
// }
long double rad = m * 11 * PI / 360;
long double C = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad);
long double c = pow(C, 0.5);
cout << setprecision(11) << c << endl;
return 0;
} | replace | 30 | 33 | 30 | 34 | TLE | |
p02677 | Python | Runtime Error | import math
def main():
a, b, h, m = map(int, input().split())
if h == 0 and m == 0:
print(abs(b - a))
exit()
h_basho = h * 60 + m
m_basho = m * 12
h_m_basho = h_basho - m_basho
if h_m_basho == 360:
print(a + b)
exit()
elif h_m_basho < 360:
kakudo = 90 * h_m_basho / 180
else:
kakudo = 90 * (720 - h_m_basho) / 180
ab2 = a**2 + b**2
cos = 2 * a * b * (round(math.cos(round(math.radians(kakudo)), 20), 20))
if kakudo <= 90:
ac = ab2 - cos
print("%.20f" % math.sqrt(ac))
else:
ac = ab2 + cos
print("%.20f" % math.sqrt(ac))
if __name__ == "__main__":
main()
| import math
def main():
a, b, h, m = map(int, input().split())
th = (h * 60 + m) / 720 * 2 * math.pi
tm = m / 60 * 2 * math.pi
xh = a * math.cos(th)
yh = a * math.sin(th)
xm = b * math.cos(tm)
ym = b * math.sin(tm)
dx = xh - xm
dy = yh - ym
ans = math.sqrt(dx**2 + dy**2)
print("%.10f" % ans)
if __name__ == "__main__":
main()
| replace | 5 | 30 | 5 | 15 | TypeError: math.cos() takes exactly one argument (2 given) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s745697918.py", line 34, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s745697918.py", line 23, in main
cos = 2 * a * b * (round(math.cos(round(math.radians(kakudo)), 20), 20))
TypeError: math.cos() takes exactly one argument (2 given)
|
p02677 | Python | Runtime Error | import math
A, B, H, M = map(int, input().split())
KA = H / 12 * 360 + ((M / 60) * (360 / 12))
KB = M / 60 * 360
K = abs(KA - KB)
if K > 180:
K = 360 - K
# if K == 180:
# print(A + B)
# exit()
# if K == 0:
# print(abs(B - A))
# exit()
# cosB = round(math.cos(math.radians(K)), 13)
cosB = math.cos(math.radians(K)), 13
cc = A**2 + B**2 - (2 * B * A * cosB)
print(math.sqrt(cc))
| import math
A, B, H, M = map(int, input().split())
KA = H / 12 * 360 + ((M / 60) * (360 / 12))
KB = M / 60 * 360
K = abs(KA - KB)
if K > 180:
K = 360 - K
# if K == 180:
# print(A + B)
# exit()
# if K == 0:
# print(abs(B - A))
# exit()
# cosB = round(math.cos(math.radians(K)), 13)
cosB = math.cos(math.radians(K))
cc = A**2 + B**2 - (2 * B * A * cosB)
print(math.sqrt(cc))
| replace | 17 | 18 | 17 | 18 | TypeError: unsupported operand type(s) for -: 'int' and 'tuple' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s596954604.py", line 19, in <module>
cc = A ** 2 + B ** 2 - (2 * B * A * cosB)
TypeError: unsupported operand type(s) for -: 'int' and 'tuple'
|
p02677 | Python | Runtime Error | k = int(input())
s = list(input())
an_lis = []
if len(s) <= k:
ans = "".join(s)
print(ans)
else:
for i in range(k):
an_lis.append(s[i])
an_lis.append("...")
ans = "".join(an_lis)
print(ans)
| a, b, h, m = map(int, input().split())
import math
a_ang = (h / 12 + (1 / 12) * (m / 60)) * 2 * math.pi
b_ang = (m / 60) * 2 * math.pi
ax = a * math.cos(a_ang)
bx = b * math.cos(b_ang)
ay = a * math.sin(a_ang)
by = b * math.sin(b_ang)
x = ax - bx
y = ay - by
ans = (x**2 + y**2) ** 0.5
print(ans)
| replace | 0 | 12 | 0 | 14 | ValueError: invalid literal for int() with base 10: '3 4 9 0' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02677/Python/s504646897.py", line 1, in <module>
k = int(input())
ValueError: invalid literal for int() with base 10: '3 4 9 0'
|
p02677 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define multitest 0
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
const ll mod = 998244353;
int solve();
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
if (multitest)
cin >> t;
while (t--)
solve();
return 0;
}
ld pi = acos(-1.0);
int solve() {
int a, b, h, m;
cin >> a >> b >> h >> m;
ld angleh = 0.5 * ((ld)h * 60.0 + (ld)m);
ld anglem = 6 * (ld)m;
ld diff = fabs(angleh - anglem);
ld ans = (ld)sqrt((ld)pow((ld)a, 2) + (ld)pow((ld)b, 2) -
2.0 * (ld)a * (ld)b * cos(pi * diff / 180.0));
cout << fixed << setprecision(10) << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define multitest 0
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
const ll mod = 998244353;
int solve();
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
if (multitest)
cin >> t;
while (t--)
solve();
return 0;
}
ld pi = acos(-1.0);
int solve() {
int a, b, h, m;
cin >> a >> b >> h >> m;
ld angleh = 0.5 * ((ld)h * 60.0 + (ld)m);
ld anglem = 6 * (ld)m;
ld diff = fabs(angleh - anglem);
ld ans = (ld)sqrt((ld)pow((ld)a, 2) + (ld)pow((ld)b, 2) -
2.0 * (ld)a * (ld)b * cos(pi * diff / 180.0));
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | insert | 29 | 29 | 29 | 30 | TLE | |
p02677 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define PI 3.14159265359
int main() {
double a, b, h, m;
cin >> a >> b >> h >> m;
double time = h + m / 60;
double theta = 2 * PI / 12 * time;
double phi = 2 * PI * time;
while (phi > 2 * PI)
phi = phi / 2 * PI;
double angle;
if (phi > theta)
angle = phi - theta;
else
angle = theta - phi;
if (angle > 180)
angle = 360 - angle;
double ans = sqrt(a * a + b * b - 2 * a * b * cos(angle));
// cout << ans << endl;
printf("%.10lf\r\n", ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define PI 3.14159265359
int main() {
double a, b, h, m;
cin >> a >> b >> h >> m;
double time = h + m / 60;
double theta = 2 * PI / 12 * time;
double phi = 2 * PI * time;
while (phi > 2 * PI)
phi = phi - 2 * PI;
double angle;
if (phi > theta)
angle = phi - theta;
else
angle = theta - phi;
if (angle > 180)
angle = 360 - angle;
double ans = sqrt(a * a + b * b - 2 * a * b * cos(angle));
// cout << ans << endl;
printf("%.10lf\r\n", ans);
return 0;
} | replace | 21 | 22 | 21 | 22 | TLE | |
p02677 | C++ | Time Limit Exceeded | #include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#define PI 3.1415926535
#define eps 1.0e-18
using namespace std;
int main() {
int a, b, h, m;
long double s, c, x;
cin >> a >> b >> h >> m;
s = (h * 60 + m) / 360.0 - m / 30.0;
x = abs(a * a + b * b - 2 * a * b * cos(s * PI));
c = sqrtl(x);
while (abs(x - c * c) > eps)
c = (c + x / c) / 2.0;
cout << fixed << setprecision(10) << c;
return 0;
} | #include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#define PI 3.1415926535
#define eps 1.0e-18
using namespace std;
int main() {
int a, b, h, m;
long double s, c, x;
cin >> a >> b >> h >> m;
s = (h * 60 + m) / 360.0 - m / 30.0;
x = abs(a * a + b * b - 2 * a * b * cos(s * PI));
c = sqrtl(x);
cout << fixed << setprecision(10) << c;
return 0;
} | delete | 14 | 16 | 14 | 14 | TLE | |
p02678 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
#define PT pair<ll, int>
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<PT> E[100000];
rep(i, M) {
int a, b;
cin >> a >> b;
E[a].pb({1, b});
E[b].pb({1, a});
}
ll D[100001];
rep1(i, N) D[i] = 1e18;
D[1] = 0;
priority_queue<PT, vector<PT>, greater<PT>> que;
que.push(mp(0, 1));
while (que.size()) {
PT p = que.top();
que.pop();
int i = p.second;
if (D[i] != p.first)
continue;
for (PT p2 : E[i]) {
int j = p2.second;
ll d = D[i] + p2.first;
if (D[j] > d) {
D[j] = d;
que.push(mp(d, j));
}
}
}
int kotae[100001];
for (int i = 2; i <= N; i++) {
ll d = D[i];
for (PT p2 : E[i]) {
int j = p2.second;
if (D[j] == d - 1) {
kotae[i] = j;
}
}
}
co("Yes");
for (int i = 2; i <= N; i++)
co(kotae[i]);
Would you please return 0;
} | #pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
#define PT pair<ll, int>
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<PT> E[100001];
rep(i, M) {
int a, b;
cin >> a >> b;
E[a].pb({1, b});
E[b].pb({1, a});
}
ll D[100001];
rep1(i, N) D[i] = 1e18;
D[1] = 0;
priority_queue<PT, vector<PT>, greater<PT>> que;
que.push(mp(0, 1));
while (que.size()) {
PT p = que.top();
que.pop();
int i = p.second;
if (D[i] != p.first)
continue;
for (PT p2 : E[i]) {
int j = p2.second;
ll d = D[i] + p2.first;
if (D[j] > d) {
D[j] = d;
que.push(mp(d, j));
}
}
}
int kotae[100001];
for (int i = 2; i <= N; i++) {
ll d = D[i];
for (PT p2 : E[i]) {
int j = p2.second;
if (D[j] == d - 1) {
kotae[i] = j;
}
}
}
co("Yes");
for (int i = 2; i <= N; i++)
co(kotae[i]);
Would you please return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e9 + 7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> r(n);
vector<int> d(n, -1);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
r[a].push_back(b);
r[b].push_back(a);
}
queue<int> q;
rep(i, r[0].size()) q.push(0);
while (!q.empty()) {
int k = q.front();
q.pop();
rep(i, r[k].size()) {
if (d[r[k][i]] == -1) {
q.push(r[k][i]);
d[r[k][i]] = k;
}
}
}
rep(i, d.size() - 1) if (d[i + 1] == -1) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
rep(i, d.size() - 1) cout << d[i + 1] + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e9 + 7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> r(n);
vector<int> d(n, -1);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
r[a].push_back(b);
r[b].push_back(a);
}
queue<int> q;
q.push(0);
while (!q.empty()) {
int k = q.front();
q.pop();
rep(i, r[k].size()) {
if (d[r[k][i]] == -1) {
q.push(r[k][i]);
d[r[k][i]] = k;
}
}
}
rep(i, d.size() - 1) if (d[i + 1] == -1) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
rep(i, d.size() - 1) cout << d[i + 1] + 1 << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
vector<vector<int>> to(100010);
int dist[100010];
int pre[100010];
const int INF = 20000000;
int main() {
int N, M;
cin >> N >> M;
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].emplace_back(b);
to[b].emplace_back(a);
}
REP(i, N) dist[i] = INF;
queue<int> q;
q.push(0);
dist[0] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
for (auto nv : to[v]) {
if (dist[nv] < dist[v] + 1)
continue;
dist[nv] = dist[v] + 1;
pre[nv] = v;
q.push(nv);
}
}
int ok = 1;
REP(i, N) if (dist[i] == INF) ok = 0;
// REP(i,N) cout << dist[i] << endl;
if (ok == 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 1; i < N; i++)
cout << (pre[i] + 1) << endl;
}
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
vector<vector<int>> to(100010);
int dist[100010];
int pre[100010];
const int INF = 20000000;
int main() {
int N, M;
cin >> N >> M;
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].emplace_back(b);
to[b].emplace_back(a);
}
REP(i, N) dist[i] = INF;
queue<int> q;
q.push(0);
dist[0] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
for (auto nv : to[v]) {
if (dist[nv] <= dist[v] + 1)
continue;
dist[nv] = dist[v] + 1;
pre[nv] = v;
q.push(nv);
}
}
int ok = 1;
REP(i, N) if (dist[i] == INF) ok = 0;
// REP(i,N) cout << dist[i] << endl;
if (ok == 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 1; i < N; i++)
cout << (pre[i] + 1) << endl;
}
}
| replace | 30 | 31 | 30 | 31 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
vector<int> to[100005]; // インデックスに対応する部屋が隣接している部屋
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, INF);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
if (dist[u] != INF)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 0; i < m; i++) {
if (i == 0)
continue;
int ans = pre[i];
++ans;
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
vector<int> to[100005]; // インデックスに対応する部屋が隣接している部屋
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, INF);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
if (dist[u] != INF)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
int ans = pre[i];
++ans;
cout << ans << endl;
}
} | replace | 37 | 38 | 37 | 38 | 0 | |
p02678 | C++ | Runtime Error | #pragma region kyomukyomupurin
/**
* author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
* created : 2020-05-18 00:07:16
**/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
int n = 0;
for (auto e : vec)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &st) {
int n = 0;
for (auto e : st)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &mp) {
int n = 0;
for (auto e : mp)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
for (T &e : vec)
is >> e;
return is;
}
#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
std::cerr << head;
if (sizeof...(Tail) != 0)
std::cerr << ", ";
debug_out(std::forward<Tail>(tail)...);
}
#pragma endregion kyomukyomupurin
using graph = vector<vector<int>>;
using pii = pair<int, int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
graph g(n);
for (int i = 0; i < n; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
vector<int> ans(n, -1);
vector<bool> visited(n, false);
visited[0] = true;
queue<int> que;
que.emplace(0);
while (!que.empty()) {
int cur = que.front();
que.pop();
for (int nxt : g[cur]) {
if (visited[nxt])
continue;
ans[nxt] = cur;
visited[nxt] = true;
que.emplace(nxt);
}
}
cout << "Yes" << '\n';
for (int i = 1; i < n; ++i) {
cout << ans[i] + 1 << '\n';
}
return 0;
} | #pragma region kyomukyomupurin
/**
* author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
* created : 2020-05-18 00:07:16
**/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
int n = 0;
for (auto e : vec)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &st) {
int n = 0;
for (auto e : st)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &mp) {
int n = 0;
for (auto e : mp)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
for (T &e : vec)
is >> e;
return is;
}
#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
std::cerr << head;
if (sizeof...(Tail) != 0)
std::cerr << ", ";
debug_out(std::forward<Tail>(tail)...);
}
#pragma endregion kyomukyomupurin
using graph = vector<vector<int>>;
using pii = pair<int, int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
graph g(n);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
vector<int> ans(n, -1);
vector<bool> visited(n, false);
visited[0] = true;
queue<int> que;
que.emplace(0);
while (!que.empty()) {
int cur = que.front();
que.pop();
for (int nxt : g[cur]) {
if (visited[nxt])
continue;
ans[nxt] = cur;
visited[nxt] = true;
que.emplace(nxt);
}
}
cout << "Yes" << '\n';
for (int i = 1; i < n; ++i) {
cout << ans[i] + 1 << '\n';
}
return 0;
} | replace | 102 | 103 | 102 | 103 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
int A[M], B[M];
Graph G(N);
rep(i, M) {
cin >> A[i] >> B[i];
A[i]--;
B[i]--;
G[A[i]].push_back(B[i]);
G[B[i]].push_back(A[i]);
}
queue<int> q;
vector<int> dist(N, INF);
vector<int> an(N, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto nv : G[v]) {
if (dist[nv] < dist[v] + 1)
continue;
dist[nv] = dist[v] + 1;
an[nv] = v;
q.push(nv);
}
}
string ans = "Yes";
rep(i, N) {
if (dist[i] == INF) {
ans = "No";
break;
}
}
cout << ans << endl;
if (ans == "Yes") {
for (int i = 1; i < N; i++) {
cout << an[i] + 1 << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
int A[M], B[M];
Graph G(N);
rep(i, M) {
cin >> A[i] >> B[i];
A[i]--;
B[i]--;
G[A[i]].push_back(B[i]);
G[B[i]].push_back(A[i]);
}
queue<int> q;
vector<int> dist(N, INF);
vector<int> an(N, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto nv : G[v]) {
if (dist[nv] <= dist[v] + 1)
continue;
dist[nv] = dist[v] + 1;
an[nv] = v;
q.push(nv);
}
}
string ans = "Yes";
rep(i, N) {
if (dist[i] == INF) {
ans = "No";
break;
}
}
cout << ans << endl;
if (ans == "Yes") {
for (int i = 1; i < N; i++) {
cout << an[i] + 1 << endl;
}
}
}
| replace | 35 | 36 | 35 | 36 | TLE | |
p02678 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, a, b, p, nxt;
cin >> N >> M;
queue<int> q, next_pos;
vector<queue<int>> G(M);
vector<int> done(N, 0);
for (int i = 0; i < M; i++) {
cin >> a >> b;
G[a - 1].emplace(b - 1);
G[b - 1].emplace(a - 1);
}
q.emplace(0);
done[0] = 1;
while (!q.empty()) {
p = q.front();
q.pop();
next_pos = G[p];
while (!next_pos.empty()) {
nxt = next_pos.front();
next_pos.pop();
if (done[nxt] == 0) {
done[nxt] = p + 1;
q.emplace(nxt);
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << done[i] << endl;
}
return 0;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, a, b, p, nxt;
cin >> N >> M;
queue<int> q, next_pos;
vector<queue<int>> G(N);
vector<int> done(N, 0);
for (int i = 0; i < M; i++) {
cin >> a >> b;
G[a - 1].emplace(b - 1);
G[b - 1].emplace(a - 1);
}
q.emplace(0);
done[0] = 1;
while (!q.empty()) {
p = q.front();
q.pop();
next_pos = G[p];
while (!next_pos.empty()) {
nxt = next_pos.front();
next_pos.pop();
if (done[nxt] == 0) {
done[nxt] = p + 1;
q.emplace(nxt);
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << done[i] << endl;
}
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02678 | C++ | Runtime Error | #include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int MAX = 100005;
int head[MAX], ver[MAX], next1[MAX], a[MAX];
int cnt = 0;
int n, m;
void add(int u, int v) {
ver[cnt] = v;
next1[cnt] = head[u];
head[u] = cnt++;
}
bool bfs(int x) {
queue<int> q;
q.push(x);
a[x] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = next1[i]) {
int v = ver[i];
if (a[v] == -1) {
a[v] = u;
q.push(v);
}
}
}
for (int i = 2; i <= n; i++) {
if (a[i] == -1) {
return false;
}
}
return true;
}
int main(void) {
cin >> n >> m;
cnt = 0;
memset(head, -1, sizeof(head));
memset(a, -1, sizeof(a));
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
add(u, v);
add(v, u);
}
if (!bfs(1)) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << a[i] << endl;
}
}
return 0;
}
| #include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int MAX = 1000005;
int head[MAX], ver[MAX], next1[MAX], a[MAX];
int cnt = 0;
int n, m;
void add(int u, int v) {
ver[cnt] = v;
next1[cnt] = head[u];
head[u] = cnt++;
}
bool bfs(int x) {
queue<int> q;
q.push(x);
a[x] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = next1[i]) {
int v = ver[i];
if (a[v] == -1) {
a[v] = u;
q.push(v);
}
}
}
for (int i = 2; i <= n; i++) {
if (a[i] == -1) {
return false;
}
}
return true;
}
int main(void) {
cin >> n >> m;
cnt = 0;
memset(head, -1, sizeof(head));
memset(a, -1, sizeof(a));
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
add(u, v);
add(v, u);
}
if (!bfs(1)) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << a[i] << endl;
}
}
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <queue>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<queue<int>> ca(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
ca[a].push(b);
ca[b].push(a);
}
vector<bool> vis(N, false);
queue<int> que;
que.push(0);
vector<int> ans(N, -1);
while (!que.empty()) {
int u = que.front();
// cout << u << " ";
que.pop();
vis[u] = true;
int n = ca[u].size();
for (int i = 0; i < n; i++) {
int v = ca[u].front();
// cout << v << ' ';
ca[u].pop();
ca[u].push(v);
if (vis[v])
continue;
if (ans[v] == -1)
ans[v] = u;
que.push(v);
}
// cout << endl;
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++)
cout << ans[i] + 1 << endl;
}
| #include <bits/stdc++.h>
#include <queue>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<queue<int>> ca(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
ca[a].push(b);
ca[b].push(a);
}
vector<bool> vis(N, false);
queue<int> que;
que.push(0);
vector<int> ans(N, -1);
while (!que.empty()) {
int u = que.front();
// cout << u << " ";
que.pop();
vis[u] = true;
int n = ca[u].size();
for (int i = 0; i < n; i++) {
int v = ca[u].front();
// cout << v << ' ';
ca[u].pop();
// ca[u].push(v);
if (vis[v])
continue;
if (ans[v] == -1)
ans[v] = u;
que.push(v);
}
// cout << endl;
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++)
cout << ans[i] + 1 << endl;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 1001001001;
int main() {
lint n, m;
cin >> n >> m;
vector<int> to[m]; // 二次元配列
rep(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b); // 道筋をtoに入れる
to[b].push_back(a); // v[][]のi番目の末尾に入れる.つまり二次元配列
}
// cout << to[2][1] << endl;
queue<int> q; // 先入先出
vector<int> dist(n, INF); // 最小の距離を求めるから初期値はINFに設定しておく
vector<int> pre(n, -1); // 直前の頂点.0があるから初期値は−1
dist[0] = 0; // 頂点0から0へのの距離は0
q.push(0);
while (!q.empty()) { // qが空でない間
int v = q.front(); // vにqの先頭を入れる
q.pop(); // 先頭を消す
for (int u : to[v]) { // ex.)to[0] = [1,2,3] uに1,2,3が順に入る
if (dist[u] != INF)
continue;
dist[u] = dist[v] + 1;
pre[u] = v; // 一つ前の頂点を入れる
q.push(u);
}
}
cout << "Yes" << endl;
rep(i, n) {
if (i == 0)
continue;
cout << ++pre[i] << endl; // インクリメント忘れずに
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 1001001001;
int main() {
lint n, m;
cin >> n >> m;
vector<int> to[100005]; // 二次元配列
rep(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b); // 道筋をtoに入れる
to[b].push_back(a); // v[][]のi番目の末尾に入れる.つまり二次元配列
}
// cout << to[2][1] << endl;
queue<int> q; // 先入先出
vector<int> dist(n, INF); // 最小の距離を求めるから初期値はINFに設定しておく
vector<int> pre(n, -1); // 直前の頂点.0があるから初期値は−1
dist[0] = 0; // 頂点0から0へのの距離は0
q.push(0);
while (!q.empty()) { // qが空でない間
int v = q.front(); // vにqの先頭を入れる
q.pop(); // 先頭を消す
for (int u : to[v]) { // ex.)to[0] = [1,2,3] uに1,2,3が順に入る
if (dist[u] != INF)
continue;
dist[u] = dist[v] + 1;
pre[u] = v; // 一つ前の頂点を入れる
q.push(u);
}
}
cout << "Yes" << endl;
rep(i, n) {
if (i == 0)
continue;
cout << ++pre[i] << endl; // インクリメント忘れずに
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02678 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define NIL = -1;
#define all(x) x.begin(), x.end()
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
int digit(ll x) {
if (x / 10 == 0)
return 1;
return digit(x / 10) + 1;
}
ll gcd(long long a, long long b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return ((a * b == 0)) ? 0 : (a / gcd(a, b) * b); }
double DegreeToRadian(double degree) { return degree * M_PI / 180.0; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
///////////////////////////////////////////////////////////////////////////////////
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n, vector<int>(n));
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> dist(n, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
int node = q.front();
q.pop();
for (int i = 0; i < g[node].size(); i++) {
int next = g[node][i];
if (dist[next] == -1) {
dist[next] = node;
q.push(next);
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << dist[i] + 1 << endl;
}
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define NIL = -1;
#define all(x) x.begin(), x.end()
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
int digit(ll x) {
if (x / 10 == 0)
return 1;
return digit(x / 10) + 1;
}
ll gcd(long long a, long long b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return ((a * b == 0)) ? 0 : (a / gcd(a, b) * b); }
double DegreeToRadian(double degree) { return degree * M_PI / 180.0; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
///////////////////////////////////////////////////////////////////////////////////
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> dist(n, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
int node = q.front();
q.pop();
for (int i = 0; i < g[node].size(); i++) {
int next = g[node][i];
if (dist[next] == -1) {
dist[next] = node;
q.push(next);
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << dist[i] + 1 << endl;
}
} | replace | 38 | 39 | 38 | 39 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.