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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p00540 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int n, m, a, b, c[100000], D[100000], E[100000];
map<vector<int>, tuple<vector<int>, vector<int>, vector<int>>> M;
void make(int n) {
queue<vector<int>> Q;
for (int i = 1; i <= n; i++) {
vector<int> ichi;
ichi.push_back(i);
Q.push(ichi);
}
while (Q.size() > 1) {
vector<int> b1 = Q.front();
Q.pop();
vector<int> b2 = Q.front();
Q.pop();
vector<int> b3 = Q.front();
Q.pop();
vector<int> sum;
for (int i = 0; i < b1.size(); i++)
sum.push_back(b1[i]);
for (int i = 0; i < b2.size(); i++)
sum.push_back(b2[i]);
for (int i = 0; i < b3.size(); i++)
sum.push_back(b3[i]);
sort(sum.begin(), sum.end());
M[sum] = make_tuple(b1, b2, b3);
Q.push(sum);
}
Q.pop();
}
int solve(vector<int> vec, int border) {
if (vec.size() == 1) {
if (c[vec[0]] < border && c[vec[0]] >= 1)
return 10000000;
if (c[vec[0]] >= border && c[vec[0]] >= 1)
return 0;
return 1;
}
int s[3] = {solve(get<0>(M[vec]), border), solve(get<1>(M[vec]), border),
solve(get<2>(M[vec]), border)};
sort(s, s + 3);
return s[0] + s[1];
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
c[b] = a;
D[i] = a;
}
for (int i = m; i < n; i++) {
cin >> a;
D[i] = a;
E[i - m] = a;
}
sort(D, D + n);
sort(E, E + n - m);
make(n);
int maxn = 0;
vector<int> Ball;
for (int i = 1; i <= n; i++)
Ball.push_back(i);
for (int i = 0; i < n; i++) {
int F = solve(Ball, D[i]);
int pos1 = lower_bound(E, E + n - m, D[i] - 1) - E;
pos1 = (n - m) - pos1;
if (F <= pos1)
maxn = max(maxn, D[i]);
}
cout << maxn << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
int n, m, a, b, c[100000], D[100000], E[100000];
map<vector<int>, tuple<vector<int>, vector<int>, vector<int>>> M;
void make(int n) {
queue<vector<int>> Q;
for (int i = 1; i <= n; i++) {
vector<int> ichi;
ichi.push_back(i);
Q.push(ichi);
}
while (Q.size() > 1) {
vector<int> b1 = Q.front();
Q.pop();
vector<int> b2 = Q.front();
Q.pop();
vector<int> b3 = Q.front();
Q.pop();
vector<int> sum;
for (int i = 0; i < b1.size(); i++)
sum.push_back(b1[i]);
for (int i = 0; i < b2.size(); i++)
sum.push_back(b2[i]);
for (int i = 0; i < b3.size(); i++)
sum.push_back(b3[i]);
sort(sum.begin(), sum.end());
M[sum] = make_tuple(b1, b2, b3);
Q.push(sum);
}
Q.pop();
}
int solve(vector<int> vec, int border) {
if (vec.size() == 1) {
if (c[vec[0]] < border && c[vec[0]] >= 1)
return 10000000;
if (c[vec[0]] >= border && c[vec[0]] >= 1)
return 0;
return 1;
}
int s[3] = {solve(get<0>(M[vec]), border), solve(get<1>(M[vec]), border),
solve(get<2>(M[vec]), border)};
sort(s, s + 3);
return s[0] + s[1];
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
c[b] = a;
D[i] = a;
}
for (int i = m; i < n; i++) {
cin >> a;
D[i] = a;
E[i - m] = a;
}
sort(D, D + n);
sort(E, E + n - m);
make(n);
int maxn = 0;
vector<int> Ball;
for (int i = 1; i <= n; i++)
Ball.push_back(i);
//--------------------------------------------Binary
//Search------------------------------------
int L = 0, R = n, M;
while (true) {
bool Y1 = false, Y2 = false;
M = (L + R) / 2;
if (M < n) {
int F = solve(Ball, D[M]);
int pos1 = lower_bound(E, E + n - m, D[M] - 1) - E;
pos1 = (n - m) - pos1;
if (F <= pos1)
Y1 = true;
}
if (M < n - 1) {
int F = solve(Ball, D[M + 1]);
int pos2 = lower_bound(E, E + n - m, D[M + 1] - 1) - E;
pos2 = (n - m) - pos2;
if (F <= pos2)
Y2 = true;
}
if (Y1 == true && Y2 == false) {
maxn = D[M];
break;
}
if (Y1 == false) {
R = M;
}
if (Y2 == true) {
L = M;
}
}
cout << maxn << endl;
return 0;
} | replace | 67 | 73 | 67 | 98 | TLE | |
p00541 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = (int)4004;
int H, W, L, P;
int a[maxn][maxn];
int _up[maxn][maxn], _down[maxn][maxn], _left[maxn][maxn], _right[maxn][maxn];
long long res;
int BIT[maxn][2];
int get(int id, int x) {
int ret = 0;
while (x > 0) {
ret += BIT[x][id];
x -= x & (-x);
}
return ret;
}
void upd(int id, int x, int val) {
while (x < maxn) {
BIT[x][id] += val;
x += x & (-x);
}
}
void update(int id, int x, int y, int val) {
if (x > y)
return;
upd(id, x, val);
upd(id, y + 1, -val);
}
void solve(int _x, int _y) {
for (int i = 0; i < maxn; i++)
BIT[i][0] = BIT[i][1] = 0;
int x = _x, y = _y;
vector<pair<int, pair<int, int>>> V;
while (x <= H && y <= W) {
V.push_back(make_pair(min(_left[x][y], _up[x][y]), make_pair(1, x)));
V.push_back(make_pair(min(_right[x][y], _down[x][y]), make_pair(0, x)));
x++;
y++;
}
sort(V.begin(), V.end());
for (int i = 0; i < V.size(); i++) {
int sz = V[i].first;
int type = V[i].second.first;
int pos = V[i].second.second;
/// cout << sz << ' ' << pos << ' ' << type << endl;
if (type == 1) {
res += get(1, pos);
update(0, pos - sz + 1, pos - L, 1);
} else {
res += get(0, pos);
update(1, pos + L, pos + sz - 1, 1);
}
}
}
int main() {
/// freopen("test.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin >> H >> W >> L >> P;
L--;
while (P--) {
int x, y;
cin >> x >> y;
a[x][y] = 1;
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
_up[i][j] = (a[i][j] ? 0 : _up[i - 1][j] + 1);
_left[i][j] = (a[i][j] ? 0 : _left[i][j - 1] + 1);
}
}
for (int i = H; i >= 1; i--) {
for (int j = W; j >= 1; j--) {
_down[i][j] = (a[i][j] ? 0 : _down[i + 1][j] + 1);
_right[i][j] = (a[i][j] ? 0 : _right[i][j + 1] + 1);
}
}
/// solve(2, 1);
for (int i = 1; i <= H; i++)
solve(i, 1);
for (int i = 2; i <= W; i++)
solve(1, i);
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = (int)4004;
int H, W, L, P;
bool a[maxn][maxn];
short _up[maxn][maxn], _down[maxn][maxn], _left[maxn][maxn], _right[maxn][maxn];
long long res;
int BIT[maxn][2];
int get(int id, int x) {
int ret = 0;
while (x > 0) {
ret += BIT[x][id];
x -= x & (-x);
}
return ret;
}
void upd(int id, int x, int val) {
while (x < maxn) {
BIT[x][id] += val;
x += x & (-x);
}
}
void update(int id, int x, int y, int val) {
if (x > y)
return;
upd(id, x, val);
upd(id, y + 1, -val);
}
void solve(int _x, int _y) {
for (int i = 0; i < maxn; i++)
BIT[i][0] = BIT[i][1] = 0;
int x = _x, y = _y;
vector<pair<int, pair<int, int>>> V;
while (x <= H && y <= W) {
V.push_back(make_pair(min(_left[x][y], _up[x][y]), make_pair(1, x)));
V.push_back(make_pair(min(_right[x][y], _down[x][y]), make_pair(0, x)));
x++;
y++;
}
sort(V.begin(), V.end());
for (int i = 0; i < V.size(); i++) {
int sz = V[i].first;
int type = V[i].second.first;
int pos = V[i].second.second;
/// cout << sz << ' ' << pos << ' ' << type << endl;
if (type == 1) {
res += get(1, pos);
update(0, pos - sz + 1, pos - L, 1);
} else {
res += get(0, pos);
update(1, pos + L, pos + sz - 1, 1);
}
}
}
int main() {
/// freopen("test.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin >> H >> W >> L >> P;
L--;
while (P--) {
int x, y;
cin >> x >> y;
a[x][y] = 1;
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
_up[i][j] = (a[i][j] ? 0 : _up[i - 1][j] + 1);
_left[i][j] = (a[i][j] ? 0 : _left[i][j - 1] + 1);
}
}
for (int i = H; i >= 1; i--) {
for (int j = W; j >= 1; j--) {
_down[i][j] = (a[i][j] ? 0 : _down[i + 1][j] + 1);
_right[i][j] = (a[i][j] ? 0 : _right[i][j + 1] + 1);
}
}
/// solve(2, 1);
for (int i = 1; i <= H; i++)
solve(i, 1);
for (int i = 2; i <= W; i++)
solve(1, i);
cout << res << endl;
} | replace | 6 | 8 | 6 | 8 | MLE | |
p00541 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 4005;
int n, m, P, L;
int a[N][N];
int l[N][N], r[N][N], u[N][N], d[N][N];
long long ans;
int T[N];
void upd(int x, int v) {
for (; x <= n; x += x & -x)
T[x] += v;
}
int get(int x) {
int res = 0;
for (; x > 0; x -= x & -x)
res += T[x];
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> L >> P;
for (int i = 1; i <= P; ++i) {
int u, v;
cin >> u >> v;
a[u][v] = 1;
}
for (int i = 1; i <= n; ++i) {
l[i][0] = 0;
r[i][m + 1] = m + 1;
for (int j = 1; j <= m; ++j)
l[i][j] = (a[i][j] ? j : l[i][j - 1]);
for (int j = m; j >= 1; --j)
r[i][j] = (a[i][j] ? j : r[i][j + 1]);
}
for (int j = 1; j <= m; ++j) {
u[0][j] = 0;
d[n + 1][j] = n + 1;
for (int i = 1; i <= n; ++i)
u[i][j] = (a[i][j] ? i : u[i - 1][j]);
for (int i = n; i >= 1; --i)
d[i][j] = (a[i][j] ? i : d[i + 1][j]);
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
d[i][j] = min(d[i][j] - i, r[i][j] - j) - 1;
u[i][j] = min(i - u[i][j], j - l[i][j]) - 1;
// cerr << i << ' ' << j << ' ' << d[i][j] << ' ' << u[i][j] << endl;
}
for (int h = 1 - m; h <= n - 1; ++h) {
// cerr << h << endl;
vector<int> Z;
vector<pair<int, int>> v;
for (int i = n; i >= 1; --i) {
int j = i - h;
if (j < 1 || j > m)
continue;
v.push_back(make_pair(i - u[i][j], i));
}
sort(v.begin(), v.end());
for (int i = 0; i <= n; ++i)
T[i] = 0;
int ptr = 0;
for (int i = 1; i <= n; ++i) {
int j = i - h;
if (j < 1 || j > m)
continue;
// cerr << h << " -> " << i << ' ' << j << endl;
while (ptr < (int)v.size() && v[ptr].first <= i) {
int k = v[ptr].second; // cerr << k << ' ' << v[ptr].first << endl;
upd(k, 1);
++ptr;
}
if (!a[i][j] && d[i][j] + i >= i + L - 1)
ans += (get(min(d[i][j] + i, n)) - get(min(n, i + L - 2)));
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 4005;
int n, m, P, L;
bool a[N][N];
short l[N][N], r[N][N], u[N][N], d[N][N];
long long ans;
int T[N];
void upd(int x, int v) {
for (; x <= n; x += x & -x)
T[x] += v;
}
int get(int x) {
int res = 0;
for (; x > 0; x -= x & -x)
res += T[x];
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> L >> P;
for (int i = 1; i <= P; ++i) {
int u, v;
cin >> u >> v;
a[u][v] = 1;
}
for (int i = 1; i <= n; ++i) {
l[i][0] = 0;
r[i][m + 1] = m + 1;
for (int j = 1; j <= m; ++j)
l[i][j] = (a[i][j] ? j : l[i][j - 1]);
for (int j = m; j >= 1; --j)
r[i][j] = (a[i][j] ? j : r[i][j + 1]);
}
for (int j = 1; j <= m; ++j) {
u[0][j] = 0;
d[n + 1][j] = n + 1;
for (int i = 1; i <= n; ++i)
u[i][j] = (a[i][j] ? i : u[i - 1][j]);
for (int i = n; i >= 1; --i)
d[i][j] = (a[i][j] ? i : d[i + 1][j]);
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
d[i][j] = min(d[i][j] - i, r[i][j] - j) - 1;
u[i][j] = min(i - u[i][j], j - l[i][j]) - 1;
// cerr << i << ' ' << j << ' ' << d[i][j] << ' ' << u[i][j] << endl;
}
for (int h = 1 - m; h <= n - 1; ++h) {
// cerr << h << endl;
vector<int> Z;
vector<pair<int, int>> v;
for (int i = n; i >= 1; --i) {
int j = i - h;
if (j < 1 || j > m)
continue;
v.push_back(make_pair(i - u[i][j], i));
}
sort(v.begin(), v.end());
for (int i = 0; i <= n; ++i)
T[i] = 0;
int ptr = 0;
for (int i = 1; i <= n; ++i) {
int j = i - h;
if (j < 1 || j > m)
continue;
// cerr << h << " -> " << i << ' ' << j << endl;
while (ptr < (int)v.size() && v[ptr].first <= i) {
int k = v[ptr].second; // cerr << k << ' ' << v[ptr].first << endl;
upd(k, 1);
++ptr;
}
if (!a[i][j] && d[i][j] + i >= i + L - 1)
ans += (get(min(d[i][j] + i, n)) - get(min(n, i + L - 2)));
}
}
cout << ans << endl;
} | replace | 6 | 8 | 6 | 8 | MLE | |
p00541 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i, n) for (int i = 0; i < n; ++i)
#define ff(i, n) for (int i = 1; i < n; ++i)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> pi;
typedef long long ll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> pl;
typedef vector<pil> vil;
const int N = 4002;
int board[N][N], U[N][N], L[N][N], R[N][N], D[N][N];
int bit[N][2];
ll ans = 0;
int h, w, p, l;
void update(int u, int id, int val) {
while (u < N) {
bit[u][id] += val;
u += (u & (-u));
}
}
int get(int u, int id) {
int ans = 0;
while (u > 0) {
ans += bit[u][id];
u -= (u & (-u));
}
return ans;
}
void up(int id, int le, int ri) {
if (le > ri)
return;
update(le, id, 1);
update(ri + 1, id, -1);
}
void work(int x, int y) {
vector<pair<int, pii>> a;
fo(i, N) fo(j, 3) bit[i][j] = 0;
while (x <= h && y <= w) {
a.push_back(mp(min(L[x][y], U[x][y]), mp(1, x)));
a.push_back(mp(min(R[x][y], D[x][y]), mp(0, x)));
x++;
y++;
}
sort(a.begin(), a.end());
fo(i, a.size()) {
pair<int, pii> u = a[i];
if (u.nd.st == 1) {
ans += 1LL * get(u.nd.nd, 1);
up(0, u.nd.nd - u.st + 1, u.nd.nd - l + 1);
} else {
ans += 1LL * get(u.nd.nd, 0);
up(1, u.nd.nd + l - 1, u.nd.nd + u.st - 1);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w >> l >> p;
fo(i, p) {
int u, v;
cin >> u >> v;
board[u][v] = 1;
}
ff(i, h + 1) ff(j, w + 1) {
if (board[i][j]) {
L[i][j] = U[i][j] = 0;
} else {
L[i][j] = L[i][j - 1] + 1;
U[i][j] = U[i - 1][j] + 1;
}
}
for (int i = h; i >= 1; --i)
for (int j = w; j >= 1; --j) {
if (board[i][j]) {
R[i][j] = D[i][j] = 0;
} else {
R[i][j] = R[i][j + 1] + 1;
D[i][j] = D[i + 1][j] + 1;
}
}
ff(i, h + 1) work(i, 1);
for (int j = 2; j <= w; ++j)
work(1, j);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i, n) for (int i = 0; i < n; ++i)
#define ff(i, n) for (int i = 1; i < n; ++i)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> pi;
typedef long long ll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> pl;
typedef vector<pil> vil;
const int N = 4002;
short board[N][N], U[N][N], L[N][N], R[N][N], D[N][N];
int bit[N][2];
ll ans = 0;
int h, w, p, l;
void update(int u, int id, int val) {
while (u < N) {
bit[u][id] += val;
u += (u & (-u));
}
}
int get(int u, int id) {
int ans = 0;
while (u > 0) {
ans += bit[u][id];
u -= (u & (-u));
}
return ans;
}
void up(int id, int le, int ri) {
if (le > ri)
return;
update(le, id, 1);
update(ri + 1, id, -1);
}
void work(int x, int y) {
vector<pair<int, pii>> a;
fo(i, N) fo(j, 3) bit[i][j] = 0;
while (x <= h && y <= w) {
a.push_back(mp(min(L[x][y], U[x][y]), mp(1, x)));
a.push_back(mp(min(R[x][y], D[x][y]), mp(0, x)));
x++;
y++;
}
sort(a.begin(), a.end());
fo(i, a.size()) {
pair<int, pii> u = a[i];
if (u.nd.st == 1) {
ans += 1LL * get(u.nd.nd, 1);
up(0, u.nd.nd - u.st + 1, u.nd.nd - l + 1);
} else {
ans += 1LL * get(u.nd.nd, 0);
up(1, u.nd.nd + l - 1, u.nd.nd + u.st - 1);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w >> l >> p;
fo(i, p) {
int u, v;
cin >> u >> v;
board[u][v] = 1;
}
ff(i, h + 1) ff(j, w + 1) {
if (board[i][j]) {
L[i][j] = U[i][j] = 0;
} else {
L[i][j] = L[i][j - 1] + 1;
U[i][j] = U[i - 1][j] + 1;
}
}
for (int i = h; i >= 1; --i)
for (int j = w; j >= 1; --j) {
if (board[i][j]) {
R[i][j] = D[i][j] = 0;
} else {
R[i][j] = R[i][j + 1] + 1;
D[i][j] = D[i + 1][j] + 1;
}
}
ff(i, h + 1) work(i, 1);
for (int j = 2; j <= w; ++j)
work(1, j);
cout << ans << endl;
} | replace | 24 | 25 | 24 | 25 | MLE | |
p00542 | C++ | Runtime Error | #include <stdio.h>
int main(void) {
int e, f, x, y[4], z, i, j;
scanf("%d %d %d %d %d %d", y[0], y[1], y[2], y[3], &e, &f);
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 4; j++) {
if (y[i] < y[j]) {
z = y[i];
y[i] = y[j];
y[j] = z;
}
}
}
x = y[0] + y[1] + y[2];
if (e >= f) {
x = x + e;
printf("%d\n", x);
} else {
x = x + f;
printf("%d\n", x);
}
return 0;
}
| #include <stdio.h>
int main(void) {
int e, f, x, y[4], z, i, j;
scanf("%d %d %d %d %d %d", &y[0], &y[1], &y[2], &y[3], &e, &f);
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 4; j++) {
if (y[i] < y[j]) {
z = y[i];
y[i] = y[j];
y[j] = z;
}
}
}
x = y[0] + y[1] + y[2];
if (e >= f) {
x = x + e;
printf("%d\n", x);
} else {
x = x + f;
printf("%d\n", x);
}
return 0;
}
| replace | 3 | 4 | 3 | 4 | -11 | |
p00542 | C++ | Runtime Error | #include <bits/stdc++.h>
#define GPA 4
#define ROLLMAN endl
using namespace std;
typedef int OTAKU;
OTAKU main() {
OTAKU roll[GPA], man[GPA];
for (OTAKU i = 0; i < 4; i++)
cin >> roll[i];
for (OTAKU i = 0; i < 2; i++)
cin >> man[i];
sort(roll, roll + 4);
sort(man, man + 2);
OTAKU Happy_Birthday = 0;
for (OTAKU i = 3; i > 0; i--)
Happy_Birthday += roll[i];
Happy_Birthday += man[1];
cout << Happy_Birthday << ROLLMAN;
return GPA;
} | #include <bits/stdc++.h>
#define GPA 4
#define ROLLMAN endl
using namespace std;
typedef int OTAKU;
OTAKU main() {
OTAKU roll[GPA], man[GPA];
for (OTAKU i = 0; i < 4; i++)
cin >> roll[i];
for (OTAKU i = 0; i < 2; i++)
cin >> man[i];
sort(roll, roll + 4);
sort(man, man + 2);
OTAKU Happy_Birthday = 0;
for (OTAKU i = 3; i > 0; i--)
Happy_Birthday += roll[i];
Happy_Birthday += man[1];
cout << Happy_Birthday << ROLLMAN;
return GPA - 4;
} | replace | 26 | 27 | 26 | 27 | 4 | |
p00544 | C++ | Runtime Error | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int a, b, ans = 0, W = 0, B = 0, R = 0;
int tansaku(int iti, int ryo, vector<string> c) {
int kariAns = 0;
for (int i = 0; i < b; i++) {
for (int j = 0; j < ryo; j++) {
if (c[iti + j][i] != 'B')
kariAns++;
}
for (int j = 1; j < iti; j++) {
if (c[iti - j][i] != 'W')
kariAns++;
}
for (int j = iti + ryo; j < a - 1; j++) {
if (c[j][i] != 'R')
kariAns++;
}
}
if (iti == a - 1) {
iti = 1;
ryo++;
} else {
iti++;
}
if (ryo >= a - 1)
return kariAns;
return min(kariAns, tansaku(iti, ryo, c));
}
int main() {
cin >> a >> b;
vector<string> c(a);
for (int i = 0; i < a; i++) {
cin >> c[i];
}
for (int i = 0; i < b; i++) {
if (c[0][i] != 'W')
ans++;
if (c[c.size() - 1][i] != 'R')
ans++;
}
cout << ans + tansaku(1, 1, c) << endl;
} | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int a, b, ans = 0, W = 0, B = 0, R = 0;
int tansaku(int iti, int ryo, vector<string> c) {
int kariAns = 0;
for (int i = 0; i < b; i++) {
for (int j = 0; j < ryo; j++) {
if (c[iti + j][i] != 'B')
kariAns++;
}
for (int j = 1; j < iti; j++) {
if (c[iti - j][i] != 'W')
kariAns++;
}
for (int j = iti + ryo; j < a - 1; j++) {
if (c[j][i] != 'R')
kariAns++;
}
}
if (iti + ryo == a - 1) {
iti = 1;
ryo++;
} else {
iti++;
}
if (ryo >= a - 1)
return kariAns;
return min(kariAns, tansaku(iti, ryo, c));
}
int main() {
cin >> a >> b;
vector<string> c(a);
for (int i = 0; i < a; i++) {
cin >> c[i];
}
for (int i = 0; i < b; i++) {
if (c[0][i] != 'W')
ans++;
if (c[c.size() - 1][i] != 'R')
ans++;
}
cout << ans + tansaku(1, 1, c) << endl;
} | replace | 26 | 27 | 26 | 27 | -11 | |
p00544 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long int
#define rep(a, b, c) for (int a = b; a < c; a++)
#define repm(a, b, c) for (int a = (b - 1); a >= c; a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d", &a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
using namespace std;
const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int strnum(str s) {
double ans = 0;
rep(i, 0, s.length()) { ans += (s[i] - '0') * pow(10, s.length() - i - 1); }
return (int)ans;
}
inline string numstr(int m) {
str s = "";
while (m > 0) {
char c;
int a = m / 10;
if (a > 0)
a = m % (a * 10);
else
a = m;
c = (char)('0' + a);
s += c;
m /= 10;
}
str st = "";
for (int i = s.size() - 1; i >= 0; i--) {
st += s[i];
}
return st;
}
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
str s[21];
rep(i, 0, n) { cin >> s[i]; }
int a, b, c, ans = INF, num = 0;
rep(i, 0, n - 2) {
a = 0;
// a=i;
rep(u, 0, i + 1) {
rep(l, 0, m) {
if (s[u][l] != 'W')
a++;
}
}
rep(j, i + 1, n - 1) {
b = 0;
rep(u, i + 1, j + 1) {
rep(l, 0, m) {
if (s[u][l] != 'B')
b++;
}
}
c = 0;
rep(k, j + 1, n) {
rep(l, 0, m) {
if (s[k][l] != 'R')
c++;
}
}
if (ans > (a + b + c)) {
// cout << a <<" "<< b <<" "<<c << endl;
// cout << i <<j<<(n-j) << endl;
ans = (a + b + c);
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define int long long int
#define rep(a, b, c) for (int a = b; a < c; a++)
#define repm(a, b, c) for (int a = (b - 1); a >= c; a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d", &a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
using namespace std;
const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int strnum(str s) {
double ans = 0;
rep(i, 0, s.length()) { ans += (s[i] - '0') * pow(10, s.length() - i - 1); }
return (int)ans;
}
inline string numstr(int m) {
str s = "";
while (m > 0) {
char c;
int a = m / 10;
if (a > 0)
a = m % (a * 10);
else
a = m;
c = (char)('0' + a);
s += c;
m /= 10;
}
str st = "";
for (int i = s.size() - 1; i >= 0; i--) {
st += s[i];
}
return st;
}
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
str s[51];
rep(i, 0, n) { cin >> s[i]; }
int a, b, c, ans = INF, num = 0;
rep(i, 0, n - 2) {
a = 0;
// a=i;
rep(u, 0, i + 1) {
rep(l, 0, m) {
if (s[u][l] != 'W')
a++;
}
}
rep(j, i + 1, n - 1) {
b = 0;
rep(u, i + 1, j + 1) {
rep(l, 0, m) {
if (s[u][l] != 'B')
b++;
}
}
c = 0;
rep(k, j + 1, n) {
rep(l, 0, m) {
if (s[k][l] != 'R')
c++;
}
}
if (ans > (a + b + c)) {
// cout << a <<" "<< b <<" "<<c << endl;
// cout << i <<j<<(n-j) << endl;
ans = (a + b + c);
}
}
}
cout << ans << endl;
return 0;
} | replace | 51 | 52 | 51 | 52 | 0 | |
p00545 | C++ | Runtime Error |
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long;
const ll inf = 4e18;
ll n, t, q;
ll a[123456];
bool d[123456];
ll x[1000];
vector<ll> talkp;
ll place[123456];
inline ll mean(ll a, ll b) { return a / 2 + b / 2; }
int main() {
scanf("%lld %lld %lld", &n, &t, &q);
a[0] = -inf;
d[0] = true;
for (int i = 1; i <= n; ++i) {
int tmpd;
scanf("%lld %d", a + i, &tmpd);
d[i] = (tmpd == 1);
}
a[n + 1] = inf;
d[n + 1] = false;
for (int j = 0; j < q; ++j) {
scanf("%lld", x + j);
}
for (int i = 0; i <= n; ++i) {
if (d[i] && !d[i + 1]) {
talkp.push_back(mean(a[i], a[i + 1]));
}
}
auto fritr = talkp.begin();
auto bkitr = talkp.begin();
for (int i = 0; i <= n; ++i) {
place[i] = a[i];
while ((*fritr) < a[i]) {
bkitr = fritr;
++fritr;
}
if (d[i]) {
ll dist = (*fritr) - a[i];
if (dist < t)
place[i] += dist;
else
place[i] += t;
} else {
ll dist = a[i] - (*bkitr);
if (dist < t)
place[i] -= dist;
else
place[i] -= t;
}
}
for (int j = 0; j < q; ++j) {
printf("%lld\n", place[x[j]]);
}
return 0;
} |
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long;
const ll inf = 4e18;
ll n, t, q;
ll a[123456];
bool d[123456];
ll x[1000];
vector<ll> talkp;
ll place[123456];
inline ll mean(ll a, ll b) { return a / 2 + b / 2; }
int main() {
scanf("%lld %lld %lld", &n, &t, &q);
a[0] = -inf;
d[0] = true;
for (int i = 1; i <= n; ++i) {
int tmpd;
scanf("%lld %d", a + i, &tmpd);
d[i] = (tmpd == 1);
}
a[n + 1] = inf;
d[n + 1] = false;
for (int j = 0; j < q; ++j) {
scanf("%lld", x + j);
}
for (int i = 0; i <= n; ++i) {
if (d[i] && !d[i + 1]) {
talkp.push_back(mean(a[i], a[i + 1]));
}
}
auto fritr = talkp.begin();
auto bkitr = talkp.begin();
for (int i = 0; i <= n; ++i) {
place[i] = a[i];
while (fritr != talkp.end() && (*fritr) < a[i]) {
bkitr = fritr;
++fritr;
}
if (d[i]) {
ll dist = (*fritr) - a[i];
if (dist < t)
place[i] += dist;
else
place[i] += t;
} else {
ll dist = a[i] - (*bkitr);
if (dist < t)
place[i] -= dist;
else
place[i] -= t;
}
}
for (int j = 0; j < q; ++j) {
printf("%lld\n", place[x[j]]);
}
return 0;
} | replace | 43 | 44 | 43 | 44 | 0 | |
p00545 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <set>
using namespace std;
struct person {
long long start;
long long end;
long long way;
bool finished;
};
person person[100005];
long long n, t, q, key[1005];
int main() {
// cout<<endl;
cin >> n >> t >> q;
priority_queue<long long> crash;
// crash.push(-100000000000000000000000);
for (int i = 1; i <= n; i++) {
cin >> person[i].start >> person[i].way;
person[i].finished = false;
}
for (int i = 1; i <= n; i++) {
if (i == 1 && person[i].way == 2) {
person[i].end = person[i].start - t;
person[i].finished = true;
continue;
}
if (person[i].way == 2) {
if (person[i - 1].way == 1) {
if ((person[i].start - person[i - 1].start) / 2 > t) {
person[i].end = person[i].start - t;
person[i - 1].end = person[i - 1].start + t;
} else {
person[i].end = (person[i].start + person[i - 1].start) / 2;
person[i - 1].end = (person[i].start + person[i - 1].start) / 2;
crash.pop();
crash.push((person[i].start + person[i - 1].start) / 2);
for (int j = 1; j < i - 1; j++) {
if (person[j].finished != true && person[j].way == 1) {
if (person[j].start + t >= crash.top()) {
person[j].end = crash.top();
person[j].finished = true;
} else
person[j].end = person[j].start + t;
person[j].finished = true;
}
}
}
person[i].finished = true;
person[i - 1].finished = true;
continue;
} else if (person[i].start - t <= crash.top()) {
person[i].end = crash.top();
person[i].finished = true;
continue;
} else {
person[i].end = person[i].start - t;
person[i].finished = true;
}
}
}
for (int i = 1; i <= n; i++) {
if (person[i].finished != true) {
if (person[i].way == 1) {
person[i].end = person[i].start + t;
person[i].finished = true;
} else {
person[i].end = person[i].start - t;
person[i].finished = true;
}
}
}
// for(int i=1; i<=n; i++) cout<<"person["<<i<<"].end=="<<person[i].end<<endl;
for (int i = 1; i <= q; i++) {
cin >> key[i];
cout << person[key[i]].end << endl;
}
} | #include <iostream>
#include <queue>
#include <set>
using namespace std;
struct person {
long long start;
long long end;
long long way;
bool finished;
};
person person[100005];
long long n, t, q, key[1005];
int main() {
// cout<<endl;
cin >> n >> t >> q;
priority_queue<long long> crash;
crash.push(-9000000000000000000);
for (int i = 1; i <= n; i++) {
cin >> person[i].start >> person[i].way;
person[i].finished = false;
}
for (int i = 1; i <= n; i++) {
if (i == 1 && person[i].way == 2) {
person[i].end = person[i].start - t;
person[i].finished = true;
continue;
}
if (person[i].way == 2) {
if (person[i - 1].way == 1) {
if ((person[i].start - person[i - 1].start) / 2 > t) {
person[i].end = person[i].start - t;
person[i - 1].end = person[i - 1].start + t;
} else {
person[i].end = (person[i].start + person[i - 1].start) / 2;
person[i - 1].end = (person[i].start + person[i - 1].start) / 2;
crash.pop();
crash.push((person[i].start + person[i - 1].start) / 2);
for (int j = 1; j < i - 1; j++) {
if (person[j].finished != true && person[j].way == 1) {
if (person[j].start + t >= crash.top()) {
person[j].end = crash.top();
person[j].finished = true;
} else
person[j].end = person[j].start + t;
person[j].finished = true;
}
}
}
person[i].finished = true;
person[i - 1].finished = true;
continue;
} else if (person[i].start - t <= crash.top()) {
person[i].end = crash.top();
person[i].finished = true;
continue;
} else {
person[i].end = person[i].start - t;
person[i].finished = true;
}
}
}
for (int i = 1; i <= n; i++) {
if (person[i].finished != true) {
if (person[i].way == 1) {
person[i].end = person[i].start + t;
person[i].finished = true;
} else {
person[i].end = person[i].start - t;
person[i].finished = true;
}
}
}
// for(int i=1; i<=n; i++) cout<<"person["<<i<<"].end=="<<person[i].end<<endl;
for (int i = 1; i <= q; i++) {
cin >> key[i];
cout << person[key[i]].end << endl;
}
} | replace | 17 | 18 | 17 | 18 | -11 | |
p00545 | C++ | Runtime Error | // Walking in JOI Kingdom
#include <iostream>
using namespace std;
typedef long long ll;
static const int MAX = 100;
enum DIRECTION { EAST = 1, WEST = 2 };
struct House {
ll a;
int d;
House() {}
House(ll a, int d) : a(a), d(d) {}
};
int N, Q;
ll T;
House H[MAX + 1];
ll A[MAX + 1];
bool Traced[MAX + 1];
ll trace(int target) {
if (Traced[target])
return A[target];
ll a;
if (H[target].d == EAST) {
if (target == N)
a = H[target].a + T;
else {
int neighbor = target + 1;
if (H[neighbor].d == EAST) {
if (H[neighbor].a - H[target].a >= T) {
a = H[target].a + T;
} else {
a = min(H[target].a + T, trace(neighbor));
}
} else
a = min(H[target].a + T, (H[target].a + H[neighbor].a) / 2);
}
} else if (H[target].d == WEST) {
if (target == 1)
a = H[target].a - T;
else {
int neighbor = target - 1;
if (H[neighbor].d == WEST) {
if (H[target].a - H[neighbor].a >= T) {
a = H[target].a - T;
} else {
a = max(H[target].a - T, trace(neighbor));
}
} else
a = max(H[target].a - T, (H[target].a + H[neighbor].a) / 2);
}
}
Traced[target] = true;
A[target] = a;
return a;
}
int main() {
scanf("%d %lld %d", &N, &T, &Q);
ll a;
int d;
for (int i = 1; i < N + 1; i++) {
scanf("%lld %d", &a, &d);
H[i] = House(a, d);
Traced[i] = false;
}
int target;
for (int i = 0; i < Q; i++) {
scanf("%d", &target);
cout << trace(target) << endl;
}
}
| // Walking in JOI Kingdom
#include <iostream>
using namespace std;
typedef long long ll;
static const int MAX = 100000;
enum DIRECTION { EAST = 1, WEST = 2 };
struct House {
ll a;
int d;
House() {}
House(ll a, int d) : a(a), d(d) {}
};
int N, Q;
ll T;
House H[MAX + 1];
ll A[MAX + 1];
bool Traced[MAX + 1];
ll trace(int target) {
if (Traced[target])
return A[target];
ll a;
if (H[target].d == EAST) {
if (target == N)
a = H[target].a + T;
else {
int neighbor = target + 1;
if (H[neighbor].d == EAST) {
if (H[neighbor].a - H[target].a >= T) {
a = H[target].a + T;
} else {
a = min(H[target].a + T, trace(neighbor));
}
} else
a = min(H[target].a + T, (H[target].a + H[neighbor].a) / 2);
}
} else if (H[target].d == WEST) {
if (target == 1)
a = H[target].a - T;
else {
int neighbor = target - 1;
if (H[neighbor].d == WEST) {
if (H[target].a - H[neighbor].a >= T) {
a = H[target].a - T;
} else {
a = max(H[target].a - T, trace(neighbor));
}
} else
a = max(H[target].a - T, (H[target].a + H[neighbor].a) / 2);
}
}
Traced[target] = true;
A[target] = a;
return a;
}
int main() {
scanf("%d %lld %d", &N, &T, &Q);
ll a;
int d;
for (int i = 1; i < N + 1; i++) {
scanf("%lld %d", &a, &d);
H[i] = House(a, d);
Traced[i] = false;
}
int target;
for (int i = 0; i < Q; i++) {
scanf("%d", &target);
cout << trace(target) << endl;
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p00545 | C++ | Runtime Error | //============================================================================
// Name : JOI.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
// 1. dp?????????
ll dp[100001];
// 2. n?????????
ll N, T, Q;
ll A[10001];
int D[10001];
// 7. calc?????????
ll calc(int k) {
// 8. dp???????????°??????
if (dp[k] != A[k])
return dp[k];
// 9. dp????¨????
if (D[k] == 1) {
if (D[k + 1] == 1) {
dp[k] = min(A[k] + T, calc(k + 1));
} else {
dp[k] = min((A[k] + A[k + 1]) / 2, A[k] + T);
}
}
if (D[k] == 2) {
if (D[k - 1] == 2) {
dp[k] = max(A[k] - T, calc(k - 1));
} else {
dp[k] = max((A[k] + A[k - 1]) / 2, A[k] - T);
}
}
return dp[k];
}
int main() {
cin >> N >> T >> Q;
// 3.?????????
// 4.??\???
for (int i = 1; i < N + 1; i++) {
cin >> A[i] >> D[i];
dp[i] = A[i];
}
// 5.???????????¨???
if (D[1] == 2) {
dp[1] -= T;
}
if (D[N] == 1) {
dp[N] += T;
}
// 6.??????
int X;
for (int i = 1; i < Q + 1; i++) {
cin >> X;
cout << calc(X) << endl;
}
return 0;
} | //============================================================================
// Name : JOI.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
// 1. dp?????????
ll dp[100001];
// 2. n?????????
ll N, T, Q;
ll A[100001];
int D[100001];
// 7. calc?????????
ll calc(int k) {
// 8. dp???????????°??????
if (dp[k] != A[k])
return dp[k];
// 9. dp????¨????
if (D[k] == 1) {
if (D[k + 1] == 1) {
dp[k] = min(A[k] + T, calc(k + 1));
} else {
dp[k] = min((A[k] + A[k + 1]) / 2, A[k] + T);
}
}
if (D[k] == 2) {
if (D[k - 1] == 2) {
dp[k] = max(A[k] - T, calc(k - 1));
} else {
dp[k] = max((A[k] + A[k - 1]) / 2, A[k] - T);
}
}
return dp[k];
}
int main() {
cin >> N >> T >> Q;
// 3.?????????
// 4.??\???
for (int i = 1; i < N + 1; i++) {
cin >> A[i] >> D[i];
dp[i] = A[i];
}
// 5.???????????¨???
if (D[1] == 2) {
dp[1] -= T;
}
if (D[N] == 1) {
dp[N] += T;
}
// 6.??????
int X;
for (int i = 1; i < Q + 1; i++) {
cin >> X;
cout << calc(X) << endl;
}
return 0;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p00545 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int n;
ll t;
int q;
ll a[100000];
int d[100000];
int x[1000];
int main() {
scanf("%d%lld%d", &n, &t, &q);
rep(i, n) { scanf("%lld%d", &a[i], &d[i]); }
rep(i, q) { scanf("%d", &x[i]); }
int i = 0;
while (i < n && d[i] == 2) {
a[i] -= t;
}
while (i < n) {
int j = 0;
while (i + j < n && d[i + j] == 1) {
++j;
}
int k = 0;
while (i + j + k < n && d[i + j + k] == 2) {
++k;
}
if (k == 0) {
rep(z, j) { a[i + z] += t; }
} else {
ll p = (a[i + j - 1] + a[i + j]) / 2;
rep(z, j) { a[i + z] = min(a[i + z] + t, p); }
rep(z, k) { a[i + j + z] = max(a[i + j + z] - t, p); }
}
i += j + k;
}
rep(i, q) { printf("%lld\n", a[x[i] - 1]); }
return 0;
} | #include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int n;
ll t;
int q;
ll a[100000];
int d[100000];
int x[1000];
int main() {
scanf("%d%lld%d", &n, &t, &q);
rep(i, n) { scanf("%lld%d", &a[i], &d[i]); }
rep(i, q) { scanf("%d", &x[i]); }
int i = 0;
while (i < n && d[i] == 2) {
a[i++] -= t;
}
while (i < n) {
int j = 0;
while (i + j < n && d[i + j] == 1) {
++j;
}
int k = 0;
while (i + j + k < n && d[i + j + k] == 2) {
++k;
}
if (k == 0) {
rep(z, j) { a[i + z] += t; }
} else {
ll p = (a[i + j - 1] + a[i + j]) / 2;
rep(z, j) { a[i + z] = min(a[i + z] + t, p); }
rep(z, k) { a[i + j + z] = max(a[i + j + z] - t, p); }
}
i += j + k;
}
rep(i, q) { printf("%lld\n", a[x[i] - 1]); }
return 0;
} | replace | 23 | 24 | 23 | 24 | TLE | |
p00545 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
int N, T, Q;
cin >> N >> T >> Q;
vector<LL> A(N), D(N);
set<LL> s[2];
for (auto i = 0; i < N; ++i) {
cin >> A[i] >> D[i];
s[--D[i]].emplace(A[i]);
}
s[0].emplace(-2e18);
s[1].emplace(2e18);
for (auto q = 0; q < Q; ++q) {
int X;
cin >> X;
if (D[--X]) {
auto x = *--s[0].upper_bound(A[X]);
auto y = *s[1].upper_bound(x);
cout << max(A[X] - T, x + (y - x) / 2) << endl;
} else {
auto x = *s[1].upper_bound(A[X]);
auto y = *--s[0].upper_bound(x);
cout << min(A[X] + T, x - (x - y) / 2) << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
LL N, T, Q;
cin >> N >> T >> Q;
vector<LL> A(N), D(N);
set<LL> s[2];
for (auto i = 0; i < N; ++i) {
cin >> A[i] >> D[i];
s[--D[i]].emplace(A[i]);
}
s[0].emplace(-2e18);
s[1].emplace(2e18);
for (auto q = 0; q < Q; ++q) {
int X;
cin >> X;
if (D[--X]) {
auto x = *--s[0].upper_bound(A[X]);
auto y = *s[1].upper_bound(x);
cout << max(A[X] - T, x + (y - x) / 2) << endl;
} else {
auto x = *s[1].upper_bound(A[X]);
auto y = *--s[0].upper_bound(x);
cout << min(A[X] + T, x - (x - y) / 2) << endl;
}
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p00545 | C++ | Runtime Error | #include <stdio.h>
int main() {
int N, Q, flag = 0;
long long int T, A[10000], D[10000], X[10000];
scanf("%d %lld %d", &N, &T, &Q);
for (int i = 1; i <= N; i++) {
scanf("%lld %lld", &A[i], &D[i]);
}
for (int i = 1; i <= Q; i++) {
scanf("%lld", &X[i]);
}
for (int i = 1; i <= Q; i++) {
if (D[X[i]] == 1) {
for (int j = X[i] + 1; j <= N; j++) {
if (D[j] == 2) {
if ((A[j - 1] + A[j]) / 2 <= A[X[i]] + T) {
printf("%lld\n", (A[j - 1] + A[j]) / 2);
flag = 1;
}
break;
}
}
if (flag == 0) {
printf("%lld\n", A[X[i]] + T);
}
}
if (D[X[i]] == 2) {
for (int j = X[i] - 1; j >= 1; j--) {
if (D[j] == 1) {
if ((A[j + 1] + A[j]) / 2 >= A[X[i]] - T) {
printf("%lld\n", (A[j + 1] + A[j]) / 2);
flag = 1;
}
break;
}
}
if (flag == 0) {
printf("%lld\n", A[X[i]] - T);
}
}
flag = 0;
}
return 0;
} | #include <stdio.h>
int main() {
int N, Q, flag = 0;
long long int T, A[100000], D[100000], X[100000];
scanf("%d %lld %d", &N, &T, &Q);
for (int i = 1; i <= N; i++) {
scanf("%lld %lld", &A[i], &D[i]);
}
for (int i = 1; i <= Q; i++) {
scanf("%lld", &X[i]);
}
for (int i = 1; i <= Q; i++) {
if (D[X[i]] == 1) {
for (int j = X[i] + 1; j <= N; j++) {
if (D[j] == 2) {
if ((A[j - 1] + A[j]) / 2 <= A[X[i]] + T) {
printf("%lld\n", (A[j - 1] + A[j]) / 2);
flag = 1;
}
break;
}
}
if (flag == 0) {
printf("%lld\n", A[X[i]] + T);
}
}
if (D[X[i]] == 2) {
for (int j = X[i] - 1; j >= 1; j--) {
if (D[j] == 1) {
if ((A[j + 1] + A[j]) / 2 >= A[X[i]] - T) {
printf("%lld\n", (A[j + 1] + A[j]) / 2);
flag = 1;
}
break;
}
}
if (flag == 0) {
printf("%lld\n", A[X[i]] - T);
}
}
flag = 0;
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00546 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long int
#define rep(a, b, c) for (int a = b; a < c; a++)
#define repm(a, b, c) for (int a = (b - 1); a >= c; a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d", &a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
using namespace std;
const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s) {
double ans = 0;
rep(i, 0, s.length()) { ans += (s[i] - '0') * pow(10, s.length() - i - 1); }
return (int)ans;
}
inline string numstr(int m) {
str s = "";
while (m > 0) {
char c;
int a = m / 10;
if (a > 0)
a = m % (a * 10);
else
a = m;
c = (char)('0' + a);
s += c;
m /= 10;
}
str st = "";
for (int i = s.size() - 1; i >= 0; i--) {
st += s[i];
}
return st;
}
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
vector<int> load[100001];
vi lo[100001];
vi ki;
int kiki[100001];
int cost[100001];
///(A->to)=cost
struct edge {
int to, cost;
};
/// pii//first...???????????¢///second...????????????
int V;
const int MAX_V = 100001; //?¶??????°!!
vector<edge> G[MAX_V];
int d[MAX_V];
void dijkstra(int s) {
priority_queue<pii, vector<pii>, greater<pii>> que;
rep(i, 0, MAX_V) d[i] = INF;
d[s] = 0;
que.push(pii(0, s));
while (!que.empty()) {
pii p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, 0, G[v].size()) {
edge e = G[v][i];
// cout << "c" << d[e.to] << " " << d[v]+e.cost << endl;
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(pii(d[e.to], e.to));
}
}
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
rep(i, 0, 100001) {
cost[i] = 0;
kiki[i] = 0;
}
int n, m, k, s;
cin >> n >> m >> k >> s;
int pco, qco;
cin >> pco >> qco;
rep(j, 0, k) {
int c;
cin >> c;
ki.pb(c);
kiki[c] = 1;
}
rep(i, 0, m) {
int x, y;
cin >> x >> y;
if (!kiki[y])
load[x].pb(y);
if (!kiki[x])
load[y].pb(x);
}
queue<pii> que;
for (int v : ki) {
// cout << v << endl;
bool used[100001] = {false};
cost[v] = INF;
que.push(mp(v, s));
while (!que.empty()) {
pii q = que.front();
que.pop();
int pla = q.first;
int num = q.second;
// if(used[pla])continue;
// used[pla]=true;
for (int va : load[pla]) {
// cout << pla<<"<-"<<va << endl;
if (cost[va] != INF)
cost[va] = qco;
if ((num - 1) > 0)
que.push(mp(va, num - 1));
}
}
}
rep(i, 1, n + 1) {
if (cost[i] == 0)
cost[i] = pco;
// cout << i << "="<< cost[i] << endl;
}
rep(i, 1, n + 1) {
rep(j, 0, load[i].size()) {
int a = load[i][j];
if (cost[a] == INF)
continue;
edge e;
e.to = a;
e.cost = cost[a];
G[i].pb(e);
// cout << e.to << "<-" << i << "=" <<e.cost << endl;
}
}
dijkstra(1);
cout << d[n] - cost[n] << endl;
return 0;
} | #include <bits/stdc++.h>
#define int long long int
#define rep(a, b, c) for (int a = b; a < c; a++)
#define repm(a, b, c) for (int a = (b - 1); a >= c; a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d", &a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
using namespace std;
const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s) {
double ans = 0;
rep(i, 0, s.length()) { ans += (s[i] - '0') * pow(10, s.length() - i - 1); }
return (int)ans;
}
inline string numstr(int m) {
str s = "";
while (m > 0) {
char c;
int a = m / 10;
if (a > 0)
a = m % (a * 10);
else
a = m;
c = (char)('0' + a);
s += c;
m /= 10;
}
str st = "";
for (int i = s.size() - 1; i >= 0; i--) {
st += s[i];
}
return st;
}
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
vector<int> load[100001];
vi lo[100001];
vi ki;
int kiki[100001];
int cost[100001];
///(A->to)=cost
struct edge {
int to, cost;
};
/// pii//first...???????????¢///second...????????????
int V;
const int MAX_V = 100001; //?¶??????°!!
vector<edge> G[MAX_V];
int d[MAX_V];
void dijkstra(int s) {
priority_queue<pii, vector<pii>, greater<pii>> que;
rep(i, 0, MAX_V) d[i] = INF;
d[s] = 0;
que.push(pii(0, s));
while (!que.empty()) {
pii p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, 0, G[v].size()) {
edge e = G[v][i];
// cout << "c" << d[e.to] << " " << d[v]+e.cost << endl;
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(pii(d[e.to], e.to));
}
}
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
rep(i, 0, 100001) {
cost[i] = 0;
kiki[i] = 0;
}
int n, m, k, s;
cin >> n >> m >> k >> s;
int pco, qco;
cin >> pco >> qco;
rep(j, 0, k) {
int c;
cin >> c;
ki.pb(c);
kiki[c] = 1;
}
rep(i, 0, m) {
int x, y;
cin >> x >> y;
if (!kiki[y])
load[x].pb(y);
if (!kiki[x])
load[y].pb(x);
}
queue<pii> que;
for (int v : ki) {
// cout << v << endl;
bool used[100001] = {false};
cost[v] = INF;
que.push(mp(v, s));
while (!que.empty()) {
pii q = que.front();
que.pop();
int pla = q.first;
int num = q.second;
if (used[pla])
continue;
used[pla] = true;
for (int va : load[pla]) {
// cout << pla<<"<-"<<va << endl;
if (cost[va] != INF)
cost[va] = qco;
if ((num - 1) > 0)
que.push(mp(va, num - 1));
}
}
}
rep(i, 1, n + 1) {
if (cost[i] == 0)
cost[i] = pco;
// cout << i << "="<< cost[i] << endl;
}
rep(i, 1, n + 1) {
rep(j, 0, load[i].size()) {
int a = load[i][j];
if (cost[a] == INF)
continue;
edge e;
e.to = a;
e.cost = cost[a];
G[i].pb(e);
// cout << e.to << "<-" << i << "=" <<e.cost << endl;
}
}
dijkstra(1);
cout << d[n] - cost[n] << endl;
return 0;
} | replace | 117 | 119 | 117 | 120 | 0 | |
p00546 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef double db;
struct edge {
ll to;
ll cost;
};
ll N, M, K, S;
ll Pa, Q, C[100000], A[200000], B[200000];
bool zon[100000];
bool terr[100000];
queue<ll> q[2];
vector<edge> G[100000];
ll b = 0;
ll d[100000];
vector<ll> hen[100000];
const ll INF = 0xffffffffff;
int main() {
scanf("%lld%lld%lld%lld%lld%lld", &N, &M, &K, &S, &Pa, &Q);
for (ll i = 0; i < K; i++) {
scanf("%lld", &C[i]);
C[i]--;
zon[C[i]] = 1;
terr[C[i]] = 1;
q[b].push(C[i]);
}
for (ll i = 0; i < M; i++) {
scanf("%lld%lld", &A[i], &B[i]);
A[i]--;
B[i]--;
hen[A[i]].push_back(B[i]);
hen[B[i]].push_back(A[i]);
}
for (ll i = 0; i < S; i++) {
while (q[b].size()) {
ll now = q[b].front();
q[b].pop();
for (ll j = 0; j < hen[now].size(); j++) {
if (!terr[hen[now][j]]) {
terr[hen[now][j]] = 1;
q[!b].push(hen[now][j]);
}
}
}
b = !b;
}
for (ll i = 0; i < M; i++) {
if (!zon[A[i]] && !zon[B[i]]) {
if (terr[B[i]]) {
G[A[i]].push_back((edge){B[i], Q});
} else {
G[A[i]].push_back((edge){B[i], Pa});
}
if (terr[A[i]]) {
G[B[i]].push_back((edge){A[i], Q});
} else {
G[B[i]].push_back((edge){A[i], Pa});
}
}
}
fill(d, d + N, INF);
d[0] = 0;
priority_queue<P> que;
que.push(P(0, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
ll x = p.second;
if (d[x] < p.first)
continue;
for (ll i = 0; i < G[x].size(); i++) {
edge e = G[x][i];
if (d[e.to] > d[x] + e.cost) {
d[e.to] = d[x] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
if (terr[N - 1])
d[N - 1] -= Q;
else
d[N - 1] -= Pa;
printf("%lld\n", d[N - 1]);
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef double db;
struct edge {
ll to;
ll cost;
};
ll N, M, K, S;
ll Pa, Q, C[100000], A[200000], B[200000];
bool zon[100000];
bool terr[100000];
queue<ll> q[2];
vector<edge> G[100000];
ll b = 0;
ll d[100000];
vector<ll> hen[100000];
const ll INF = 0xffffffffff;
int main() {
scanf("%lld%lld%lld%lld%lld%lld", &N, &M, &K, &S, &Pa, &Q);
for (ll i = 0; i < K; i++) {
scanf("%lld", &C[i]);
C[i]--;
zon[C[i]] = 1;
terr[C[i]] = 1;
q[b].push(C[i]);
}
for (ll i = 0; i < M; i++) {
scanf("%lld%lld", &A[i], &B[i]);
A[i]--;
B[i]--;
hen[A[i]].push_back(B[i]);
hen[B[i]].push_back(A[i]);
}
for (ll i = 0; i < S; i++) {
while (q[b].size()) {
ll now = q[b].front();
q[b].pop();
for (ll j = 0; j < hen[now].size(); j++) {
if (!terr[hen[now][j]]) {
terr[hen[now][j]] = 1;
q[!b].push(hen[now][j]);
}
}
}
b = !b;
}
for (ll i = 0; i < M; i++) {
if (!zon[A[i]] && !zon[B[i]]) {
if (terr[B[i]]) {
G[A[i]].push_back((edge){B[i], Q});
} else {
G[A[i]].push_back((edge){B[i], Pa});
}
if (terr[A[i]]) {
G[B[i]].push_back((edge){A[i], Q});
} else {
G[B[i]].push_back((edge){A[i], Pa});
}
}
}
fill(d, d + N, INF);
d[0] = 0;
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
ll x = p.second;
if (d[x] < p.first)
continue;
for (ll i = 0; i < G[x].size(); i++) {
edge e = G[x][i];
if (d[e.to] > d[x] + e.cost) {
d[e.to] = d[x] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
if (terr[N - 1])
d[N - 1] -= Q;
else
d[N - 1] -= Pa;
printf("%lld\n", d[N - 1]);
} | replace | 73 | 74 | 73 | 74 | TLE | |
p00546 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
int main() {
ll n, m, k, t, b[2];
cin >> n >> m >> k >> t >> b[0] >> b[1];
int c[n];
ll d[n];
for (int i = 0; i < n; i++)
c[i] = 1 << 29, d[i] = INF;
queue<int> que2;
for (int i = 0; i < k; i++) {
int x;
scanf("%d", &x);
x--;
c[x] = 0;
que2.push(x);
}
vector<int> v[n];
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
v[x].push_back(y);
v[y].push_back(x);
}
while (!que2.empty()) {
int x = que2.front();
que2.pop();
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
if (c[y] <= c[x] + 1)
continue;
c[y] = c[x] + 1;
que2.push(y);
}
}
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, 0));
d[0] = 0;
while (!que.empty()) {
P p = que.top();
que.pop();
ll x = p.second, cost = p.second;
if (d[x] < cost)
continue;
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
ll cc = d[x] + (c[y] > t ? b[0] : b[1]);
if (!c[y])
continue;
if (d[y] >= cc) {
d[y] = cc;
que.push(P(cc, y));
}
}
}
cout << d[n - 1] - (c[n - 1] > t ? b[0] : b[1]) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
int main() {
ll n, m, k, t, b[2];
cin >> n >> m >> k >> t >> b[0] >> b[1];
int c[n];
ll d[n];
for (int i = 0; i < n; i++)
c[i] = 1 << 29, d[i] = INF;
queue<int> que2;
for (int i = 0; i < k; i++) {
int x;
scanf("%d", &x);
x--;
c[x] = 0;
que2.push(x);
}
vector<int> v[n];
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
v[x].push_back(y);
v[y].push_back(x);
}
while (!que2.empty()) {
int x = que2.front();
que2.pop();
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
if (c[y] <= c[x] + 1)
continue;
c[y] = c[x] + 1;
que2.push(y);
}
}
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, 0));
d[0] = 0;
while (!que.empty()) {
P p = que.top();
que.pop();
ll x = p.second, cost = p.second;
if (d[x] < cost)
continue;
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
ll cc = d[x] + (c[y] > t ? b[0] : b[1]);
if (!c[y])
continue;
if (d[y] > cc) {
d[y] = cc;
que.push(P(cc, y));
}
}
}
cout << d[n - 1] - (c[n - 1] > t ? b[0] : b[1]) << endl;
return 0;
} | replace | 54 | 55 | 54 | 55 | TLE | |
p00546 | C++ | Time Limit Exceeded | /* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) \
get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b)-1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template <class T, class U> void chmin(T &x, const U &y) { x = min<T>(x, y); }
template <class T, class U> void chmax(T &x, const U &y) { x = max<T>(x, y); }
struct prepare_ {
prepare_() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
}
} prepare__;
/* ]]] */
int n, m, k, s;
int p, q;
int x[100000];
ll c[100000];
vector<int> g[100000];
ll d[100000];
int main() {
cin >> n >> m >> k >> s;
cin >> p >> q;
rep(i, k) cin >> x[i];
rep(i, m) {
int a, b;
cin >> a >> b;
g[a - 1].push_back(b - 1);
g[b - 1].push_back(a - 1);
}
fill_n(d, 100000, inf_ll);
queue<int> qu;
rep(i, k) {
d[x[i] - 1] = 0;
qu.push(x[i] - 1);
}
while (qu.size()) {
int v = qu.front();
qu.pop();
each(u, g[v]) {
if (d[u] == inf_ll) {
d[u] = d[v] + 1;
qu.push(u);
}
}
}
rep(i, 1, n - 1) {
if (d[i] == 0)
c[i] = inf_ll;
else if (d[i] <= s)
c[i] = q;
else
c[i] = p;
}
priority_queue<pair<ll, int>> pq;
fill_n(d, 100000, inf_ll);
d[0] = 0;
pq.emplace(0, 0);
while (pq.size()) {
ll sm;
int v;
tie(sm, v) = pq.top();
pq.pop();
if (d[v] < sm)
continue;
each(u, g[v]) {
if (d[u] > sm + c[u]) {
d[u] = sm + c[u];
pq.emplace(sm + c[u], u);
}
}
}
cout << d[n - 1] << endl;
} | /* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) \
get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b)-1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template <class T, class U> void chmin(T &x, const U &y) { x = min<T>(x, y); }
template <class T, class U> void chmax(T &x, const U &y) { x = max<T>(x, y); }
struct prepare_ {
prepare_() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
}
} prepare__;
/* ]]] */
int n, m, k, s;
int p, q;
int x[100000];
ll c[100000];
vector<int> g[100000];
ll d[100000];
int main() {
cin >> n >> m >> k >> s;
cin >> p >> q;
rep(i, k) cin >> x[i];
rep(i, m) {
int a, b;
cin >> a >> b;
g[a - 1].push_back(b - 1);
g[b - 1].push_back(a - 1);
}
fill_n(d, 100000, inf_ll);
queue<int> qu;
rep(i, k) {
d[x[i] - 1] = 0;
qu.push(x[i] - 1);
}
while (qu.size()) {
int v = qu.front();
qu.pop();
each(u, g[v]) {
if (d[u] == inf_ll) {
d[u] = d[v] + 1;
qu.push(u);
}
}
}
rep(i, 1, n - 1) {
if (d[i] == 0)
c[i] = inf_ll;
else if (d[i] <= s)
c[i] = q;
else
c[i] = p;
}
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
pq;
fill_n(d, 100000, inf_ll);
d[0] = 0;
pq.emplace(0, 0);
while (pq.size()) {
ll sm;
int v;
tie(sm, v) = pq.top();
pq.pop();
if (d[v] < sm)
continue;
each(u, g[v]) {
if (d[u] > sm + c[u]) {
d[u] = sm + c[u];
pq.emplace(sm + c[u], u);
}
}
}
cout << d[n - 1] << endl;
} | replace | 84 | 85 | 84 | 86 | TLE | |
p00546 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, int> Pair;
vector<vector<int>> e;
int N, M, S, K;
int P, Q;
int iszombi[100000];
int danger[100000];
ll d[100000];
void bfs() {
queue<Pair> q;
for (int i = 0; i < K; i++)
q.push(Pair(danger[i], S));
while (q.size()) {
auto tmp = q.front();
q.pop();
if (tmp.second == 0)
continue;
for (int i = 0; i < e[tmp.first].size(); i++) {
auto next = e[tmp.first][i];
if (iszombi[next] != 2) {
iszombi[next] = 1;
q.push(Pair(next, tmp.second - 1));
}
}
}
}
void djk() {
for (int i = 0; i < N; i++)
d[i] = 1145141919810;
priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
pq.push(Pair(0, 0));
d[0] = 0;
while (pq.size()) {
auto tmp = pq.top();
pq.pop();
if (tmp.first > d[tmp.second])
continue;
for (int i = 0; i < e[tmp.second].size(); i++) {
auto next = e[tmp.second][i];
ll plus = iszombi[next] == 1 ? Q : P;
if (iszombi[next] == 2)
continue;
if (d[next] > d[tmp.second] + plus) {
d[next] = d[tmp.second] + plus;
pq.push(Pair(d[next], next));
}
}
}
}
int main() {
cin >> N >> M >> K >> S;
cin >> P >> Q;
for (int i = 0; i < K; i++) {
int a;
cin >> a;
iszombi[a - 1] = 2;
danger[i] = a - 1;
}
e.resize(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--, b--;
e[a].push_back(b);
e[b].push_back(a);
}
bfs();
djk();
cout << d[N - 1] - (iszombi[N - 1] == 1
? Q
: (iszombi[N - 1] == 0 ? P : 1145141919810))
<< endl;
return 0;
} | #include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, int> Pair;
vector<vector<int>> e;
int N, M, S, K;
int P, Q;
int iszombi[100000];
int danger[100000];
ll d[100000];
void bfs() {
queue<Pair> q;
for (int i = 0; i < K; i++)
q.push(Pair(danger[i], S));
while (q.size()) {
auto tmp = q.front();
q.pop();
if (tmp.second == 0)
continue;
for (int i = 0; i < e[tmp.first].size(); i++) {
auto next = e[tmp.first][i];
if (iszombi[next] == 0) {
iszombi[next] = 1;
q.push(Pair(next, tmp.second - 1));
}
}
}
}
void djk() {
for (int i = 0; i < N; i++)
d[i] = 1145141919810;
priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
pq.push(Pair(0, 0));
d[0] = 0;
while (pq.size()) {
auto tmp = pq.top();
pq.pop();
if (tmp.first > d[tmp.second])
continue;
for (int i = 0; i < e[tmp.second].size(); i++) {
auto next = e[tmp.second][i];
ll plus = iszombi[next] == 1 ? Q : P;
if (iszombi[next] == 2)
continue;
if (d[next] > d[tmp.second] + plus) {
d[next] = d[tmp.second] + plus;
pq.push(Pair(d[next], next));
}
}
}
}
int main() {
cin >> N >> M >> K >> S;
cin >> P >> Q;
for (int i = 0; i < K; i++) {
int a;
cin >> a;
iszombi[a - 1] = 2;
danger[i] = a - 1;
}
e.resize(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--, b--;
e[a].push_back(b);
e[b].push_back(a);
}
bfs();
djk();
cout << d[N - 1] - (iszombi[N - 1] == 1
? Q
: (iszombi[N - 1] == 0 ? P : 1145141919810))
<< endl;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p00546 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define INF (1LL << 60)
#define ll long long
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M, K, S;
cin >> N >> M >> K >> S;
ll P, Q;
cin >> P >> Q;
vector<vector<ll>> G(N + 1, vector<ll>(N + 1));
vector<ll> cost(N + 1, P);
vector<bool> kiken(N + 1, false);
for (int i = 0; i < K; i++) {
int k;
cin >> k;
kiken[k] = true;
G[0].push_back(k);
cost[k] = INF;
}
for (int i = 0; i < M; i++) {
ll a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
queue<pair<ll, ll>> qq;
qq.push({0, 0});
vector<bool> f(N + 1, false);
while (!qq.empty()) {
auto p = qq.front();
qq.pop();
ll s = p.first, n = p.second;
if (n <= S) {
for (auto e : G[s]) {
if (f[e] == false) {
f[e] = true;
if (n != 0)
cost[e] = Q;
qq.push({e, n + 1});
}
}
}
}
vector<ll> dist(N + 1, INF);
queue<ll> q;
q.push(1);
dist[1] = 0;
while (!q.empty()) {
auto n = q.front();
q.pop();
for (auto e : G[n]) {
// if (kiken[e] == true)continue;
if (dist[e] > dist[n] + cost[e]) {
dist[e] = dist[n] + cost[e];
q.push(e);
}
}
}
cout << dist[N] - cost[N] << endl;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define INF (1LL << 60)
#define ll long long
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M, K, S;
cin >> N >> M >> K >> S;
ll P, Q;
cin >> P >> Q;
vector<vector<ll>> G(N + 1);
vector<ll> cost(N + 1, P);
vector<bool> kiken(N + 1, false);
for (int i = 0; i < K; i++) {
int k;
cin >> k;
kiken[k] = true;
G[0].push_back(k);
cost[k] = INF;
}
for (int i = 0; i < M; i++) {
ll a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
queue<pair<ll, ll>> qq;
qq.push({0, 0});
vector<bool> f(N + 1, false);
while (!qq.empty()) {
auto p = qq.front();
qq.pop();
ll s = p.first, n = p.second;
if (n <= S) {
for (auto e : G[s]) {
if (f[e] == false) {
f[e] = true;
if (n != 0)
cost[e] = Q;
qq.push({e, n + 1});
}
}
}
}
vector<ll> dist(N + 1, INF);
queue<ll> q;
q.push(1);
dist[1] = 0;
while (!q.empty()) {
auto n = q.front();
q.pop();
for (auto e : G[n]) {
// if (kiken[e] == true)continue;
if (dist[e] > dist[n] + cost[e]) {
dist[e] = dist[n] + cost[e];
q.push(e);
}
}
}
cout << dist[N] - cost[N] << endl;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p00546 | C++ | Time Limit Exceeded | #include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define INF (1000000000000000000LL)
typedef pair<long long, int> PLLI;
int main() {
int N, M, K, S;
cin >> N >> M >> K >> S;
long long P, Q;
cin >> P >> Q;
vector<long long> town(N);
for (int i = 0; i < N; ++i)
town[i] = P;
town[N - 1] = 0;
queue<PLLI> q;
set<int> zom;
for (int i = 0; i < K; ++i) {
int temp;
cin >> temp;
town[temp - 1] = INF;
q.push(PLLI(S, temp - 1));
zom.insert(temp - 1);
}
vector<int> road[N];
vector<int> temp_road[N];
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
temp_road[a - 1].push_back(b - 1);
temp_road[b - 1].push_back(a - 1);
if (zom.count(a - 1) == 0 && zom.count(b - 1) == 0) {
road[a - 1].push_back(b - 1);
road[b - 1].push_back(a - 1);
}
}
while (!q.empty()) {
PLLI p = q.front();
q.pop();
long long d = p.first;
int t = p.second;
--d;
for (auto x : temp_road[t]) {
if (town[x] == P) {
town[x] = Q;
if (d != 0)
q.push(PLLI(d, x));
}
}
}
priority_queue<PLLI, vector<PLLI>, greater<PLLI>> pq;
vector<long long> cost(N);
for (int i = 0; i < N; ++i)
cost[i] = INF;
cost[0] = 0;
pq.push(PLLI(0, 0));
while (!pq.empty()) {
PLLI p = pq.top();
pq.pop();
long long c = p.first;
int t = p.second;
if (t == N - 1)
break;
if (cost[t] < c)
continue;
for (auto x : road[t]) {
if (cost[x] < c + town[x])
continue;
cost[x] = c + town[x];
pq.push(PLLI(cost[x], x));
}
}
cout << cost[N - 1] << endl;
return 0;
} | #include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define INF (1000000000000000000LL)
typedef pair<long long, int> PLLI;
int main() {
int N, M, K, S;
cin >> N >> M >> K >> S;
long long P, Q;
cin >> P >> Q;
vector<long long> town(N);
for (int i = 0; i < N; ++i)
town[i] = P;
town[N - 1] = 0;
queue<PLLI> q;
set<int> zom;
for (int i = 0; i < K; ++i) {
int temp;
cin >> temp;
town[temp - 1] = INF;
q.push(PLLI(S, temp - 1));
zom.insert(temp - 1);
}
vector<int> road[N];
vector<int> temp_road[N];
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
temp_road[a - 1].push_back(b - 1);
temp_road[b - 1].push_back(a - 1);
if (zom.count(a - 1) == 0 && zom.count(b - 1) == 0) {
road[a - 1].push_back(b - 1);
road[b - 1].push_back(a - 1);
}
}
while (!q.empty()) {
PLLI p = q.front();
q.pop();
long long d = p.first;
int t = p.second;
--d;
for (auto x : temp_road[t]) {
if (town[x] == P) {
town[x] = Q;
if (d != 0)
q.push(PLLI(d, x));
}
}
}
priority_queue<PLLI, vector<PLLI>, greater<PLLI>> pq;
vector<long long> cost(N);
for (int i = 0; i < N; ++i)
cost[i] = INF;
cost[0] = 0;
pq.push(PLLI(0, 0));
while (!pq.empty()) {
PLLI p = pq.top();
pq.pop();
long long c = p.first;
int t = p.second;
if (t == N - 1)
break;
if (cost[t] < c)
continue;
for (auto x : road[t]) {
if (cost[x] <= c + town[x])
continue;
cost[x] = c + town[x];
pq.push(PLLI(cost[x], x));
}
}
cout << cost[N - 1] << endl;
return 0;
} | replace | 83 | 84 | 83 | 84 | TLE | |
p00547 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>
using namespace std;
struct State {
bool x[3][3];
};
int p[1020][1020], H, W, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
map<short, int> M[1020][1020];
State slide(int rx, int ry, State S) {
State T;
for (int i = 0; i < 9; i++)
T.x[i / 3][i % 3] = false;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int h1 = i - rx, h2 = j - ry;
if (h1 < 0 || h2 < 0)
continue;
T.x[h1][h2] = S.x[i][j];
}
}
return T;
}
int solve(int cx, int cy, State S) {
State SV = S;
short SV2 = 0;
for (int i = 0; i < 9; i++) {
if (S.x[i / 3][i % 3] == true)
SV2 += (1 << i);
}
if (M[cx][cy][SV2] >= 1)
return M[cx][cy][SV2] - 1;
if (cx == H && cy == W) {
M[cx][cy][SV2] = 1;
return 0;
}
if (cx > H || cy > W) {
M[cx][cy][SV2] = 100000000;
return 99999999;
}
int e1 = 0;
if (S.x[1][1] == false && p[cx][cy] >= 1) {
S.x[1][1] = true;
e1 = p[cx][cy];
}
vector<tuple<int, int, int>> v;
for (int i = 0; i < 4; i++) {
int fx = cx + dx[i], fy = cy + dy[i];
if (p[fx][fy] >= 1 && S.x[1 + dx[i]][1 + dy[i]] == false)
v.push_back(make_tuple(fx, fy, i));
}
if (v.size() == 0) {
int e3 = min(solve(cx + 1, cy, slide(1, 0, S)),
solve(cx, cy + 1, slide(0, 1, S))) +
e1;
M[cx][cy][SV2] = e3 + 1;
return e3;
}
int ret = 99999999;
for (int i = 0; i < (int)v.size(); i++) {
State Y = S;
int e2 = 0;
for (int j = 0; j < v.size(); j++) {
if (i != j) {
Y.x[1 + dx[get<2>(v[j])]][1 + dy[get<2>(v[j])]] = true;
e2 += p[get<0>(v[j])][get<1>(v[j])];
}
}
ret = min(ret, solve(cx + 1, cy, slide(1, 0, Y)) + e2 + e1);
ret = min(ret, solve(cx, cy + 1, slide(0, 1, Y)) + e2 + e1);
}
M[cx][cy][SV2] = ret + 1;
return ret;
}
int main() {
cin >> H >> W;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
char c;
cin >> c;
if (c >= '1' && c <= '9')
p[i][j] = c - '0';
}
}
State T;
for (int i = 0; i < 9; i++)
T.x[i / 3][i % 3] = false;
int ans = solve(1, 1, T);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>
using namespace std;
struct State {
bool x[3][3];
};
int p[1020][1020], H, W, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int M[1020][1020][128];
State slide(int rx, int ry, State S) {
State T;
for (int i = 0; i < 9; i++)
T.x[i / 3][i % 3] = false;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int h1 = i - rx, h2 = j - ry;
if (h1 < 0 || h2 < 0)
continue;
T.x[h1][h2] = S.x[i][j];
}
}
return T;
}
int solve(int cx, int cy, State S) {
State SV = S;
short SV2 = 0;
for (int i = 0; i < 9; i++) {
if (S.x[i / 3][i % 3] == true)
SV2 += (1 << i);
}
if (M[cx][cy][SV2] >= 1)
return M[cx][cy][SV2] - 1;
if (cx == H && cy == W) {
M[cx][cy][SV2] = 1;
return 0;
}
if (cx > H || cy > W) {
M[cx][cy][SV2] = 100000000;
return 99999999;
}
int e1 = 0;
if (S.x[1][1] == false && p[cx][cy] >= 1) {
S.x[1][1] = true;
e1 = p[cx][cy];
}
vector<tuple<int, int, int>> v;
for (int i = 0; i < 4; i++) {
int fx = cx + dx[i], fy = cy + dy[i];
if (p[fx][fy] >= 1 && S.x[1 + dx[i]][1 + dy[i]] == false)
v.push_back(make_tuple(fx, fy, i));
}
if (v.size() == 0) {
int e3 = min(solve(cx + 1, cy, slide(1, 0, S)),
solve(cx, cy + 1, slide(0, 1, S))) +
e1;
M[cx][cy][SV2] = e3 + 1;
return e3;
}
int ret = 99999999;
for (int i = 0; i < (int)v.size(); i++) {
State Y = S;
int e2 = 0;
for (int j = 0; j < v.size(); j++) {
if (i != j) {
Y.x[1 + dx[get<2>(v[j])]][1 + dy[get<2>(v[j])]] = true;
e2 += p[get<0>(v[j])][get<1>(v[j])];
}
}
ret = min(ret, solve(cx + 1, cy, slide(1, 0, Y)) + e2 + e1);
ret = min(ret, solve(cx, cy + 1, slide(0, 1, Y)) + e2 + e1);
}
M[cx][cy][SV2] = ret + 1;
return ret;
}
int main() {
cin >> H >> W;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
char c;
cin >> c;
if (c >= '1' && c <= '9')
p[i][j] = c - '0';
}
}
State T;
for (int i = 0; i < 9; i++)
T.x[i / 3][i % 3] = false;
int ans = solve(1, 1, T);
cout << ans << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | MLE | |
p00547 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
int dp[1002][1002][16];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
int H, W;
cin >> H >> W;
for (int i = 0; i < 1002; ++i)
for (int j = 0; j < 1002; ++j)
for (int k = 0; k < 16; ++k) {
dp[i][j][k] = 1e9;
}
dp[1][1][0] = 0;
vector<vector<int>> field(H + 2, vector<int>(W + 2));
for (int i = 0; i < H; ++i) {
string st;
cin >> st;
for (int j = 0; j < W; ++j) {
if (st[j] != '.') {
field[i + 1][j + 1] = st[j] - '0';
}
}
}
for (int nowy = 1; nowy < H + 1; ++nowy) {
for (int nowx = 1; nowx < W + 1; ++nowx) {
for (int n = 0; n < 16; ++n) {
const int eat_ld = n & 1;
const int eat_d = (n & 2) >> 1;
const int eat_r = (n & 4) >> 2;
const int eat_ru = (n & 8) >> 3;
if (1e9 <= dp[nowy][nowx][n])
continue;
vector<vector<char>> eats(4, vector<char>(4));
eats[2][0] = eat_ld;
eats[2][1] = eat_d;
eats[1][2] = eat_r;
eats[0][2] = eat_ru;
eats[1][1] = true;
for (int way = 0; way < 2; ++way) {
const int nextx = nowx + dx[way];
const int nexty = nowy + dy[way];
const int ax = 1 + dx[way];
const int ay = 1 + dy[way];
for (int w = 0; w < 4; ++w) {
int nexteat_ld = eats[2 + dy[way]][0 + dx[way]];
int nexteat_d = eats[2 + dy[way]][1 + dx[way]];
int nexteat_r = eats[1 + dy[way]][2 + dx[way]];
int nexteat_ru = eats[0 + dy[way]][2 + dx[way]];
int eat_sum = 0;
if (!eats[ay][ax]) {
if (ay == 2 + dy[way] && ax == 0 + dx[way])
nexteat_ld = true;
if (ay == 2 + dy[way] && ax == 1 + dx[way])
nexteat_d = true;
if (ay == 1 + dy[way] && ax == 2 + dx[way])
nexteat_r = true;
if (ay == 0 + dy[way] && ax == 2 + dx[way])
nexteat_ru = true;
eat_sum += field[nexty][nextx];
}
for (int v = 0; v < 4; ++v) {
if (v == w)
continue;
else {
if (!eats[ay + dy[v]][ax + dx[v]]) {
if (ay + dy[v] == 2 + dy[way] && ax + dx[v] == 0 + dx[way])
nexteat_ld = true;
if (ay + dy[v] == 2 + dy[way] && ax + dx[v] == 1 + dx[way])
nexteat_d = true;
if (ay + dy[v] == 1 + dy[way] && ax + dx[v] == 2 + dx[way])
nexteat_r = true;
if (ay + dy[v] == 0 + dy[way] && ax + dx[v] == 2 + dx[way])
nexteat_ru = true;
eat_sum += field[nexty + dy[v]][nextx + dx[v]];
}
}
}
int n =
dp[nowy][nowx][eat_ld + 2 * eat_d + 4 * eat_r + 8 * eat_ru] +
eat_sum;
dp[nexty][nextx]
[nexteat_ld + 2 * nexteat_d + 4 * nexteat_r + 8 * nexteat_ru] =
min(dp[nexty][nextx][nexteat_ld + 2 * nexteat_d +
4 * nexteat_r + 8 * nexteat_ru],
n);
}
}
}
}
}
int ans = 1e9;
for (int l = 0; l < 16; ++l) {
ans = min(ans, dp[H][W][l]);
}
cout << ans << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
int dp[1002][1002][16];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
int H, W;
cin >> H >> W;
for (int i = 0; i < 1002; ++i)
for (int j = 0; j < 1002; ++j)
for (int k = 0; k < 16; ++k) {
dp[i][j][k] = 1e9;
}
dp[1][1][0] = 0;
vector<vector<int>> field(H + 3, vector<int>(W + 3));
for (int i = 0; i < H; ++i) {
string st;
cin >> st;
for (int j = 0; j < W; ++j) {
if (st[j] != '.') {
field[i + 1][j + 1] = st[j] - '0';
}
}
}
for (int nowy = 1; nowy < H + 1; ++nowy) {
for (int nowx = 1; nowx < W + 1; ++nowx) {
for (int n = 0; n < 16; ++n) {
const int eat_ld = n & 1;
const int eat_d = (n & 2) >> 1;
const int eat_r = (n & 4) >> 2;
const int eat_ru = (n & 8) >> 3;
if (1e9 <= dp[nowy][nowx][n])
continue;
vector<vector<char>> eats(4, vector<char>(4));
eats[2][0] = eat_ld;
eats[2][1] = eat_d;
eats[1][2] = eat_r;
eats[0][2] = eat_ru;
eats[1][1] = true;
for (int way = 0; way < 2; ++way) {
const int nextx = nowx + dx[way];
const int nexty = nowy + dy[way];
const int ax = 1 + dx[way];
const int ay = 1 + dy[way];
for (int w = 0; w < 4; ++w) {
int nexteat_ld = eats[2 + dy[way]][0 + dx[way]];
int nexteat_d = eats[2 + dy[way]][1 + dx[way]];
int nexteat_r = eats[1 + dy[way]][2 + dx[way]];
int nexteat_ru = eats[0 + dy[way]][2 + dx[way]];
int eat_sum = 0;
if (!eats[ay][ax]) {
if (ay == 2 + dy[way] && ax == 0 + dx[way])
nexteat_ld = true;
if (ay == 2 + dy[way] && ax == 1 + dx[way])
nexteat_d = true;
if (ay == 1 + dy[way] && ax == 2 + dx[way])
nexteat_r = true;
if (ay == 0 + dy[way] && ax == 2 + dx[way])
nexteat_ru = true;
eat_sum += field[nexty][nextx];
}
for (int v = 0; v < 4; ++v) {
if (v == w)
continue;
else {
if (!eats[ay + dy[v]][ax + dx[v]]) {
if (ay + dy[v] == 2 + dy[way] && ax + dx[v] == 0 + dx[way])
nexteat_ld = true;
if (ay + dy[v] == 2 + dy[way] && ax + dx[v] == 1 + dx[way])
nexteat_d = true;
if (ay + dy[v] == 1 + dy[way] && ax + dx[v] == 2 + dx[way])
nexteat_r = true;
if (ay + dy[v] == 0 + dy[way] && ax + dx[v] == 2 + dx[way])
nexteat_ru = true;
eat_sum += field[nexty + dy[v]][nextx + dx[v]];
}
}
}
int n =
dp[nowy][nowx][eat_ld + 2 * eat_d + 4 * eat_r + 8 * eat_ru] +
eat_sum;
dp[nexty][nextx]
[nexteat_ld + 2 * nexteat_d + 4 * nexteat_r + 8 * nexteat_ru] =
min(dp[nexty][nextx][nexteat_ld + 2 * nexteat_d +
4 * nexteat_r + 8 * nexteat_ru],
n);
}
}
}
}
}
int ans = 1e9;
for (int l = 0; l < 16; ++l) {
ans = min(ans, dp[H][W][l]);
}
cout << ans << endl;
return 0;
} | replace | 17 | 18 | 17 | 18 | -11 | |
p00548 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LLINF = 1LL << 60;
int main() {
ll N, M, K;
ll dp[20005];
ll A[20005];
fill_n(dp, 20005, LLINF);
cin >> N >> M >> K;
dp[0] = 0;
for (ll i = 0; i < N; i++)
cin >> A[i];
for (ll i = 0; i < N; i++) {
ll maxv = -1, minv = LLINF;
for (ll j = 0; j < M; j++) {
maxv = max(A[i + j], maxv);
minv = min(A[i + j], minv);
dp[i + j + 1] = min(dp[i + j + 1], dp[i] + K + (j + 1) * (maxv - minv));
}
}
cout << dp[N] << endl;
return (0);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LLINF = 1LL << 60;
int main() {
ll N, M, K;
ll dp[20005];
ll A[20005];
fill_n(dp, 20005, LLINF);
cin >> N >> M >> K;
dp[0] = 0;
for (ll i = 0; i < N; i++)
cin >> A[i];
for (ll i = 0; i < N; i++) {
ll maxv = -1, minv = LLINF;
for (ll j = 0; j < M; j++) {
if (i + j >= N)
continue;
maxv = max(A[i + j], maxv);
minv = min(A[i + j], minv);
dp[i + j + 1] = min(dp[i + j + 1], dp[i] + K + (j + 1) * (maxv - minv));
}
}
cout << dp[N] << endl;
return (0);
}
| insert | 16 | 16 | 16 | 18 | 0 | |
p00548 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[20005], dp[20005];
long long solve(long long p) {
if (p > n)
return 1LL << 62;
if (p == n)
return 0;
if (dp[p] >= 1)
return dp[p];
long long p1 = 1LL << 62, p2 = 0, ret = 1LL << 62;
for (int i = p + 1; i <= p + m; i++) {
p1 = min(p1, a[i - 1]);
p2 = max(p2, a[i - 1]);
ret = min(ret, solve(i) + (p2 - p1) * (i - p) + k);
}
dp[p] = ret;
return ret;
}
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
cout << solve(0) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[100005], dp[100005];
long long solve(long long p) {
if (p > n)
return 1LL << 62;
if (p == n)
return 0;
if (dp[p] >= 1)
return dp[p];
long long p1 = 1LL << 62, p2 = 0, ret = 1LL << 62;
for (int i = p + 1; i <= p + m; i++) {
p1 = min(p1, a[i - 1]);
p2 = max(p2, a[i - 1]);
ret = min(ret, solve(i) + (p2 - p1) * (i - p) + k);
}
dp[p] = ret;
return ret;
}
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
cout << solve(0) << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p00548 | C++ | Runtime Error | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
long long int dp[20001];
int main() {
fill(dp, dp + sizeof(dp), static_cast<long long int>(1e18));
dp[0] = 0;
int N, M, K;
cin >> N >> M >> K;
vector<long long int> ws(N);
for (int i = 0; i < N; ++i) {
cin >> ws[i];
}
for (int i = 0; i < N; ++i) {
long long int amin = 1e18;
long long int amax = 0;
long long int cost = K;
for (int j = 0; j < min(N - i, M); ++j) {
amin = min(amin, ws[i + j]);
amax = max(amax, ws[i + j]);
dp[i + j + 1] =
min(dp[i + j + 1], dp[i] + cost + (j + 1) * (amax - amin));
}
}
cout << dp[N] << endl;
return 0;
} | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
long long int dp[20001];
int main() {
for (int i = 0; i < 20001; ++i) {
dp[i] = 1e18;
}
dp[0] = 0;
int N, M, K;
cin >> N >> M >> K;
vector<long long int> ws(N);
for (int i = 0; i < N; ++i) {
cin >> ws[i];
}
for (int i = 0; i < N; ++i) {
long long int amin = 1e18;
long long int amax = 0;
long long int cost = K;
for (int j = 0; j < min(N - i, M); ++j) {
amin = min(amin, ws[i + j]);
amax = max(amax, ws[i + j]);
dp[i + j + 1] =
min(dp[i + j + 1], dp[i] + cost + (j + 1) * (amax - amin));
}
}
cout << dp[N] << endl;
return 0;
} | replace | 14 | 15 | 14 | 17 | -11 | |
p00548 | C++ | Runtime Error | #include <stdio.h>
#include <stdlib.h>
#define inf 10e18
typedef long long ll;
int main(void) {
ll i, j, k, n, m;
scanf("%lld%lld%lld", &n, &m, &k);
ll a[n], **sum, dp[n];
sum = (ll **)malloc(sizeof(ll *) * (n + 10));
for (i = 0; i < n; ++i)
sum[i] = (ll *)malloc(sizeof(ll) * (m + 10));
for (i = 0; i < n; ++i)
scanf("%lld", &a[i]);
for (i = 0; i < n; ++i)
dp[i] = inf;
dp[0] = k;
for (i = 0; i < n; ++i) {
ll min = inf, max = 0;
for (j = 0; j < n; ++j) {
if (i - j >= 0) {
if (min > a[i - j])
min = a[i - j];
if (max < a[i - j])
max = a[i - j];
sum[i][j] = k + (j + 1) * (max - min);
}
}
}
for (i = 1; i < n; ++i) {
for (j = 0; j < m; ++j) {
if (i - j > 0) {
if (dp[i] > sum[i][j] + dp[i - j - 1])
dp[i] = sum[i][j] + dp[i - j - 1];
} else if (!(i - j)) {
if (dp[i] > sum[i][j])
dp[i] = sum[i][j];
}
}
}
printf("%lld\n", dp[n - 1]);
for (i = 0; i < n; ++i)
free(sum[i]);
free(sum);
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
#define inf 10e18
typedef long long ll;
int main(void) {
ll i, j, k, n, m;
scanf("%lld%lld%lld", &n, &m, &k);
ll a[n], **sum, dp[n];
sum = (ll **)malloc(sizeof(ll *) * (n + 10));
for (i = 0; i < n; ++i)
sum[i] = (ll *)malloc(sizeof(ll) * (m + 10));
for (i = 0; i < n; ++i)
scanf("%lld", &a[i]);
for (i = 0; i < n; ++i)
dp[i] = inf;
dp[0] = k;
for (i = 0; i < n; ++i) {
ll min = inf, max = 0;
for (j = 0; j < m; ++j) {
if (i - j >= 0) {
if (min > a[i - j])
min = a[i - j];
if (max < a[i - j])
max = a[i - j];
sum[i][j] = k + (j + 1) * (max - min);
}
}
}
for (i = 1; i < n; ++i) {
for (j = 0; j < m; ++j) {
if (i - j > 0) {
if (dp[i] > sum[i][j] + dp[i - j - 1])
dp[i] = sum[i][j] + dp[i - j - 1];
} else if (!(i - j)) {
if (dp[i] > sum[i][j])
dp[i] = sum[i][j];
}
}
}
printf("%lld\n", dp[n - 1]);
for (i = 0; i < n; ++i)
free(sum[i]);
free(sum);
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p00548 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, M, K;
ll A[100005];
ll dp[20005];
const ll INF = 1000000000000000000LL;
ll solve() {
fill(dp, dp + N + 1, INF);
dp[0] = 0;
for (ll i = 1; i <= N; i++) {
ll a = -INF, b = INF;
for (ll j = i - 1; j >= max(0LL, i - M); j--) {
b = min(A[j], b);
a = max(A[j], a);
ll c = K + (i - j) * (a - b);
assert(c >= 0);
dp[i] = min(dp[i], dp[j] + c);
}
}
return dp[N];
}
int main() {
cin >> N >> M >> K;
assert(N < 20000);
for (int i = 0; i < N; i++)
cin >> A[i];
cout << solve() << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, M, K;
ll A[100005];
ll dp[20005];
const ll INF = 1000000000000000000LL;
ll solve() {
fill(dp, dp + N + 1, INF);
dp[0] = 0;
for (ll i = 1; i <= N; i++) {
ll a = -INF, b = INF;
for (ll j = i - 1; j >= max(0LL, i - M); j--) {
b = min(A[j], b);
a = max(A[j], a);
ll c = K + (i - j) * (a - b);
assert(c >= 0);
dp[i] = min(dp[i], dp[j] + c);
}
}
return dp[N];
}
int main() {
cin >> N >> M >> K;
assert(N <= 20000);
for (int i = 0; i < N; i++)
cin >> A[i];
cout << solve() << endl;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p00548 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 200001
const int inf = 1e18;
int mn[2][1010], mx[2][1010];
int a[MAX], dp[2][1010];
signed main() {
int n, m, k;
fill((int *)dp, (int *)(dp + 2), inf);
fill((int *)mn, (int *)(mn + 2), inf);
scanf("%lld%lld%lld", &n, &m, &k);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
dp[0][0] = k;
mn[0][0] = mx[0][0] = a[0];
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
mn[1][j] = inf;
mx[1][j] = 0;
dp[1][j] = inf;
}
for (int j = 1; j < m; j++) {
if (dp[0][j - 1] == inf)
continue;
mn[1][j] = min(mn[0][j - 1], a[i]);
mx[1][j] = max(mx[0][j - 1], a[i]);
dp[1][j] = dp[0][j - 1];
}
for (int j = 0; j < m; j++) {
if (dp[0][j] == inf)
continue;
int sum = dp[0][j] + (j + 1) * (mx[0][j] - mn[0][j]) + k;
dp[1][0] = min(dp[1][0], sum);
mx[1][0] = mn[1][0] = a[i];
}
for (int j = 0; j < m; j++) {
mn[0][j] = mn[1][j];
mx[0][j] = mx[1][j];
dp[0][j] = dp[1][j];
}
}
int ans = dp[0][0];
for (int i = 1; i < m; i++) {
int sum = dp[0][i] + (i + 1) * (mx[0][i] - mn[0][i]);
ans = min(ans, sum);
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 200001
const int inf = 1e18;
int mn[2][1010], mx[2][1010];
int a[MAX], dp[2][1010];
signed main() {
int n, m, k;
fill((int *)dp, (int *)(dp + 2), inf);
fill((int *)mn, (int *)(mn + 2), inf);
scanf("%lld%lld%lld", &n, &m, &k);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
dp[0][0] = k;
mn[0][0] = mx[0][0] = a[0];
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
mn[1][j] = inf;
mx[1][j] = 0;
dp[1][j] = inf;
}
for (int j = 1; j < m; j++) {
if (dp[0][j - 1] == inf)
continue;
mn[1][j] = min(mn[0][j - 1], a[i]);
mx[1][j] = max(mx[0][j - 1], a[i]);
dp[1][j] = dp[0][j - 1];
}
for (int j = 0; j < m; j++) {
if (dp[0][j] == inf)
continue;
int sum = dp[0][j] + (j + 1) * (mx[0][j] - mn[0][j]) + k;
dp[1][0] = min(dp[1][0], sum);
mx[1][0] = mn[1][0] = a[i];
}
for (int j = 0; j < m; j++) {
mn[0][j] = mn[1][j];
mx[0][j] = mx[1][j];
dp[0][j] = dp[1][j];
}
}
int ans = dp[0][0];
for (int i = 1; i < m; i++) {
int sum = dp[0][i] + (i + 1) * (mx[0][i] - mn[0][i]);
ans = min(ans, sum);
}
printf("%lld\n", ans);
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p00548 | C++ | Runtime Error | //============================================================================
// Name : JOI.cpp
// Author :2015 ho3
// Version :???11:08
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
long long N, M, K;
long long A[20001] = {};
long long dp[20001];
long long mmD[20001][1001];
const long long INF = 100000000000000000;
long long calc(long long n1) {
if (dp[n1] > -1)
return dp[n1];
long long ans = INF;
for (long long i = 1; i < M + 1 && i < n1 + 1; ++i) {
ans = min(ans, calc(n1 - i) + K + i * mmD[n1 - i][i]);
}
dp[n1] = ans;
return ans;
}
int main() {
cin >> N >> M >> K;
for (long long i = 1; i < N + 1; i++)
cin >> A[i];
fill(dp, dp + 20001, -1);
long long maxD[1001] = {};
long long minD[1001] = {};
for (int i = 0; i < N + 1; i++) {
maxD[0] = 0;
minD[0] = INF;
for (int j = 1; j < M + 1; j++) {
maxD[j] = max(maxD[j - 1], A[i + j]);
minD[j] = min(minD[j - 1], A[i + j]);
mmD[i][j] = maxD[j] - minD[j];
}
}
dp[0] = 0;
// long long R;
// for(int i=1;i<N;i++){
// for(int j=0;j<M+1;j++)
// R=calc(i,j);
// }
// R=calc(N,0);
// cout<<R<<endl;
cout << calc(N) << endl;
return 0;
} | //============================================================================
// Name : JOI.cpp
// Author :2015 ho3
// Version :???11:08
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
long long N, M, K;
long long A[20001] = {};
long long dp[20001];
long long mmD[20001][1001];
const long long INF = 100000000000000000;
long long calc(long long n1) {
if (dp[n1] > -1)
return dp[n1];
long long ans = INF;
for (long long i = 1; i < M + 1 && i < n1 + 1; ++i) {
ans = min(ans, calc(n1 - i) + K + i * mmD[n1 - i][i]);
}
dp[n1] = ans;
return ans;
}
int main() {
cin >> N >> M >> K;
for (long long i = 1; i < N + 1; i++)
cin >> A[i];
fill(dp, dp + 20001, -1);
long long maxD[1001] = {};
long long minD[1001] = {};
for (int i = 0; i < N + 1; i++) {
maxD[0] = 0;
minD[0] = INF;
for (int j = 1; j < M + 1 && (i + j) < N + 1; j++) {
maxD[j] = max(maxD[j - 1], A[i + j]);
minD[j] = min(minD[j - 1], A[i + j]);
mmD[i][j] = maxD[j] - minD[j];
}
}
dp[0] = 0;
// long long R;
// for(int i=1;i<N;i++){
// for(int j=0;j<M+1;j++)
// R=calc(i,j);
// }
// R=calc(N,0);
// cout<<R<<endl;
cout << calc(N) << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | -11 | |
p00548 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define DEBUG
#define int long long
#define INF 1000000000000000000
#define REP(i, n) for (int i = 1; i <= n; i++)
int n, m, k;
int a[20002];
int cs[20002][1002];
int sm[20002];
signed main() {
cin >> n >> m >> k;
REP(i, n) cin >> a[i];
REP(i, n) {
int mx = 0;
int mn = INF;
REP(j, m) {
mx = max(mx, a[i + j - 1]);
mn = min(mn, a[i + j - 1]);
cs[i][j] = k + j * (mx - mn);
}
}
REP(i, n) sm[i] = INF;
REP(i, n) REP(j, m) {
if (n < i - 1 + j)
continue;
sm[i - 1 + j] = min(sm[i - 1 + j], sm[i - 1] + cs[i][j]);
}
#ifdef DEBUG
REP(i, n) {
REP(j, m) cout << cs[i][j] << " ";
cout << endl;
}
REP(i, n) cout << sm[i] << " ";
cout << endl;
#endif
cout << sm[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// #define DEBUG
#define int long long
#define INF 1000000000000000000
#define REP(i, n) for (int i = 1; i <= n; i++)
int n, m, k;
int a[20002];
int cs[20002][1002];
int sm[20002];
signed main() {
cin >> n >> m >> k;
REP(i, n) cin >> a[i];
REP(i, n) {
int mx = 0;
int mn = INF;
REP(j, m) {
if (n < i + j - 1)
continue;
mx = max(mx, a[i + j - 1]);
mn = min(mn, a[i + j - 1]);
cs[i][j] = k + j * (mx - mn);
}
}
REP(i, n) sm[i] = INF;
REP(i, n) REP(j, m) {
if (n < i - 1 + j)
continue;
sm[i - 1 + j] = min(sm[i - 1 + j], sm[i - 1] + cs[i][j]);
}
#ifdef DEBUG
REP(i, n) {
REP(j, m) cout << cs[i][j] << " ";
cout << endl;
}
REP(i, n) cout << sm[i] << " ";
cout << endl;
#endif
cout << sm[n] << endl;
return 0;
} | insert | 19 | 19 | 19 | 21 | -11 | |
p00548 | C++ | Runtime Error | #include <iostream>
#define INF 1e+18
#define int long long
using namespace std;
signed main() {
int n, m, k, a[20000];
int dp[20001][1001];
cin >> n >> m >> k;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 1000; j++)
dp[i][j] = INF;
}
dp[0][0] = 0;
dp[0][1000] = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
int mi = a[i - 1], ma = a[i - 1];
for (int j = 0; j < min(m, i); j++) {
dp[i][j] = dp[i - j - 1][1000] + k + (j + 1) * (ma - mi);
dp[i][1000] = min(dp[i][1000], dp[i][j]);
if (i - j - 2 >= 0) {
mi = min(mi, a[i - j - 2]);
ma = max(ma, a[i - j - 2]);
}
}
}
cout << dp[n][1000] << endl;
return 0;
} | #include <iostream>
#define INF 1e+18
#define int long long
using namespace std;
signed main() {
int n, m, k, a[20000];
static int dp[20001][1001];
cin >> n >> m >> k;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 1000; j++)
dp[i][j] = INF;
}
dp[0][0] = 0;
dp[0][1000] = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
int mi = a[i - 1], ma = a[i - 1];
for (int j = 0; j < min(m, i); j++) {
dp[i][j] = dp[i - j - 1][1000] + k + (j + 1) * (ma - mi);
dp[i][1000] = min(dp[i][1000], dp[i][j]);
if (i - j - 2 >= 0) {
mi = min(mi, a[i - j - 2]);
ma = max(ma, a[i - j - 2]);
}
}
}
cout << dp[n][1000] << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p00549 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
string S;
string ns;
const string JOI = "JOI#";
ll IC[100005];
ll JC[100005];
ll dp[10005][4];
ll solve(const string &s) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < 4; j++) {
if (s[i] == JOI[j])
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j] += dp[i][j];
}
}
return dp[s.size()][3];
}
int main() {
cin >> N;
cin >> S;
ll res = solve(S);
S = "a" + S;
for (int i = 1; i <= N; i++) {
if (S[i] == 'J')
JC[i] = JC[i - 1] + 1;
else
JC[i] = JC[i - 1];
}
for (int i = N; i >= 1; i--) {
if (S[i] == 'I')
IC[i] = IC[i + 1] + 1;
else
IC[i] = IC[i + 1];
}
ll lmax = 0;
for (int i = 1; i <= N; i++) {
lmax = max(lmax, JC[i] * IC[i]);
}
res = res + lmax;
S = S.substr(1);
ns = "J" + S;
res = max(res, solve(ns));
ns = S + "I";
res = max(res, solve(ns));
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
string S;
string ns;
const string JOI = "JOI#";
ll IC[100005];
ll JC[100005];
ll dp[100005][4];
ll solve(const string &s) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < 4; j++) {
if (s[i] == JOI[j])
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j] += dp[i][j];
}
}
return dp[s.size()][3];
}
int main() {
cin >> N;
cin >> S;
ll res = solve(S);
S = "a" + S;
for (int i = 1; i <= N; i++) {
if (S[i] == 'J')
JC[i] = JC[i - 1] + 1;
else
JC[i] = JC[i - 1];
}
for (int i = N; i >= 1; i--) {
if (S[i] == 'I')
IC[i] = IC[i + 1] + 1;
else
IC[i] = IC[i + 1];
}
ll lmax = 0;
for (int i = 1; i <= N; i++) {
lmax = max(lmax, JC[i] * IC[i]);
}
res = res + lmax;
S = S.substr(1);
ns = "J" + S;
res = max(res, solve(ns));
ns = S + "I";
res = max(res, solve(ns));
cout << res << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p00550 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n, m, q;
vector<P> dist(100010);
vector<vector<P>> G(100010);
void dijkstra(int s) {
for (int i = 0; i < n; i++)
dist[i] = P(1e9, 1e9);
priority_queue<T, vector<T>, greater<T>> que;
dist[s] = P(0, q);
que.push(T(0, s, q));
while (!que.empty()) {
int ccost, cv, cyear;
tie(ccost, cv, cyear) = que.top();
que.pop();
for (auto x : G[cv]) {
int nv, nyear;
tie(nv, nyear) = x;
int nnyear = min(nyear, cyear);
int ncost = ccost + 1;
if (ncost == dist[nv].fs) {
if (dist[nv].sc < nnyear) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
} else if (ncost < dist[nv].fs) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
}
}
}
int main() {
cin >> n >> m >> q;
vector<int> u(m), v(m);
for (int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
u[i]--, v[i]--;
}
vector<int> changeYear(m, q);
for (int i = 0; i < q; i++) {
int r;
cin >> r;
r--;
changeYear[r] = i;
}
for (int i = 0; i < m; i++) {
G[u[i]].eb(P(v[i], changeYear[i]));
G[v[i]].eb(P(u[i], changeYear[i]));
}
dijkstra(0);
vector<int> cnt(q + 1);
for (int i = 0; i < n; i++) {
cnt[dist[i].sc]++;
}
for (int i = 0; i < q; i++) {
if (0 < i)
cnt[i] += cnt[i - 1];
cout << cnt[i] << endl;
}
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n, m, q;
vector<P> dist(100010);
vector<vector<P>> G(100010);
void dijkstra(int s) {
for (int i = 0; i < n; i++)
dist[i] = P(1e9, 1e9);
priority_queue<T, vector<T>, greater<T>> que;
dist[s] = P(0, q);
que.push(T(0, s, q));
while (!que.empty()) {
int ccost, cv, cyear;
tie(ccost, cv, cyear) = que.top();
que.pop();
if (ccost == dist[cv].fs) {
if (dist[cv].sc > cyear)
continue;
}
// if(dist[cv].fs < ccost) continue;
for (auto x : G[cv]) {
int nv, nyear;
tie(nv, nyear) = x;
int nnyear = min(nyear, cyear);
int ncost = ccost + 1;
if (ncost == dist[nv].fs) {
if (dist[nv].sc < nnyear) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
} else if (ncost < dist[nv].fs) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
}
}
}
int main() {
cin >> n >> m >> q;
vector<int> u(m), v(m);
for (int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
u[i]--, v[i]--;
}
vector<int> changeYear(m, q);
for (int i = 0; i < q; i++) {
int r;
cin >> r;
r--;
changeYear[r] = i;
}
for (int i = 0; i < m; i++) {
G[u[i]].eb(P(v[i], changeYear[i]));
G[v[i]].eb(P(u[i], changeYear[i]));
}
dijkstra(0);
vector<int> cnt(q + 1);
for (int i = 0; i < n; i++) {
cnt[dist[i].sc]++;
}
for (int i = 0; i < q; i++) {
if (0 < i)
cnt[i] += cnt[i - 1];
cout << cnt[i] << endl;
}
}
| insert | 61 | 61 | 61 | 68 | TLE | |
p00550 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
inline void reader(int &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = k - '0';
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
if (m)
x = -x;
}
inline void writer(int x, char c) {
int s = 0, m = 0;
char f[10];
if (x < 0)
m = 1, x = -x;
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
using namespace std;
vector<int> E[100000], G[100000];
int l[100000], d[100000], b[100000], cnt[200001], u[200000], v[200000],
r[200000], que[100000];
int main() {
int n, m, q;
reader(n);
reader(m);
reader(q);
rep(i, m) {
reader(u[i]);
reader(v[i]);
u[i]--;
v[i]--;
r[i] = q;
l[u[i]]++;
l[v[i]]++;
}
rep(i, n) E[i].reserve(l[i]), G[i].reserve(l[i]), l[i] = 0;
rep(i, q) {
int a;
reader(a);
r[a - 1] = i;
}
rep(i, m) {
E[u[i]][l[u[i]]] = v[i];
G[u[i]][l[u[i]]++] = r[i];
E[v[i]][l[v[i]]] = u[i];
G[v[i]][l[u[i]]++] = r[i];
}
d[0] = 1;
b[0] = q;
int s = 0, g = 1;
while (s != g) {
int p = que[s++];
rep(i, l[p]) {
int a = E[p][i];
if (d[a] == 0) {
d[a] = d[p] + 1;
que[g++] = a;
}
if (d[a] == d[p] + 1)
b[a] = max(b[a], min(b[p], G[p][i]));
}
}
rep(i, n) cnt[b[i]]++;
int ans = 0;
rep(i, q) {
ans += cnt[i];
writer(ans, '\n');
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
inline void reader(int &x) {
int k, m = 0;
x = 0;
for (;;) {
mygc(k);
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
x = k - '0';
break;
}
}
for (;;) {
mygc(k);
if (k < '0' || k > '9')
break;
x = x * 10 + k - '0';
}
if (m)
x = -x;
}
inline void writer(int x, char c) {
int s = 0, m = 0;
char f[10];
if (x < 0)
m = 1, x = -x;
while (x)
f[s++] = x % 10, x /= 10;
if (!s)
f[s++] = 0;
if (m)
mypc('-');
while (s--)
mypc(f[s] + '0');
mypc(c);
}
using namespace std;
vector<int> E[100000], G[100000];
int l[100000], d[100000], b[100000], cnt[200001], u[200000], v[200000],
r[200000], que[100000];
int main() {
int n, m, q;
reader(n);
reader(m);
reader(q);
rep(i, m) {
reader(u[i]);
reader(v[i]);
u[i]--;
v[i]--;
r[i] = q;
l[u[i]]++;
l[v[i]]++;
}
rep(i, n) E[i].reserve(l[i]), G[i].reserve(l[i]), l[i] = 0;
rep(i, q) {
int a;
reader(a);
r[a - 1] = i;
}
rep(i, m) {
E[u[i]][l[u[i]]] = v[i];
G[u[i]][l[u[i]]++] = r[i];
E[v[i]][l[v[i]]] = u[i];
G[v[i]][l[v[i]]++] = r[i];
}
d[0] = 1;
b[0] = q;
int s = 0, g = 1;
while (s != g) {
int p = que[s++];
rep(i, l[p]) {
int a = E[p][i];
if (d[a] == 0) {
d[a] = d[p] + 1;
que[g++] = a;
}
if (d[a] == d[p] + 1)
b[a] = max(b[a], min(b[p], G[p][i]));
}
}
rep(i, n) cnt[b[i]]++;
int ans = 0;
rep(i, q) {
ans += cnt[i];
writer(ans, '\n');
}
} | replace | 71 | 72 | 71 | 72 | 0 | |
p00550 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <math.h>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define fir first
#define sec second
int R[200002];
const int INF = 1001001001;
vector<pair<int, int>> edge[100002];
int d[100002];
int s[100002];
int sans[200002];
int N, M, Q;
int main() {
scanf("%d %d %d", &N, &M, &Q);
rep(i, M) {
R[i] = INF;
int u, v;
scanf("%d %d", &u, &v);
u--;
v--;
edge[u].pb(make_pair(v, i));
edge[v].pb(make_pair(u, i));
}
rep(i, Q) {
int r;
scanf("%d", &r);
r--;
R[r] = i;
}
fill(&d[0], &d[N + 1], INF);
fill(&s[0], &s[N + 1], INF);
// dijkstra
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
q;
q.push(make_pair(0, 0));
while (q.size()) {
pair<int, int> p = q.top();
q.pop();
int n = p.second;
int c = p.first;
if (d[n] < c)
continue;
rep(i, edge[n].size()) {
int to = edge[n][i].fir;
int ro = edge[n][i].sec;
if (c + 1 == d[to]) {
s[to] = max(s[to], min(s[n], R[ro]));
if (s[to] < min(s[n], R[ro]))
q.push(make_pair(c + 1, to));
} else if (c + 1 < d[to]) {
s[to] = min(s[n], R[ro]);
d[to] = c + 1;
if (s[to] < min(s[n], R[ro]))
q.push(make_pair(c + 1, to));
q.push(make_pair(c + 1, to));
}
}
}
rep(i, N) {
if (i != 0)
sans[s[i]]++;
}
int ans = 0;
rep(i, Q) {
ans += sans[i];
printf("%d\n", ans);
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <math.h>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define fir first
#define sec second
int R[200002];
const int INF = 1001001001;
vector<pair<int, int>> edge[100002];
int d[100002];
int s[100002];
int sans[200002];
int N, M, Q;
int main() {
scanf("%d %d %d", &N, &M, &Q);
rep(i, M) {
R[i] = INF;
int u, v;
scanf("%d %d", &u, &v);
u--;
v--;
edge[u].pb(make_pair(v, i));
edge[v].pb(make_pair(u, i));
}
rep(i, Q) {
int r;
scanf("%d", &r);
r--;
R[r] = i;
}
fill(&d[0], &d[N + 1], INF);
fill(&s[0], &s[N + 1], INF);
// dijkstra
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
q;
q.push(make_pair(0, 0));
while (q.size()) {
pair<int, int> p = q.top();
q.pop();
int n = p.second;
int c = p.first;
if (d[n] < c)
continue;
rep(i, edge[n].size()) {
int to = edge[n][i].fir;
int ro = edge[n][i].sec;
if (c + 1 == d[to]) {
s[to] = max(s[to], min(s[n], R[ro]));
if (s[to] < min(s[n], R[ro]))
q.push(make_pair(c + 1, to));
} else if (c + 1 < d[to]) {
s[to] = min(s[n], R[ro]);
d[to] = c + 1;
if (s[to] < min(s[n], R[ro]))
q.push(make_pair(c + 1, to));
q.push(make_pair(c + 1, to));
}
}
}
rep(i, N) {
if (i != 0 && s[i] < Q)
sans[s[i]]++;
}
int ans = 0;
rep(i, Q) {
ans += sans[i];
printf("%d\n", ans);
}
return 0;
} | replace | 66 | 67 | 66 | 67 | 0 | |
p00550 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_set>
#define DEBUG
using std::endl;
constexpr int32_t INF = 1000000000;
std::unordered_set<int32_t> graph[100000];
int32_t path[100000][2];
int32_t N, M, Q;
int32_t D[100000];
void dij(int32_t s) {
using P = std::pair<int32_t, int32_t>;
std::queue<P> que;
for (auto &i : D)
i = INF;
D[0] = 0;
que.emplace(0, 0);
while (!que.empty()) {
auto n = que.front();
que.pop();
if (D[n.second] < n.first) {
continue;
}
for (auto &e : graph[n.second]) {
auto cost = n.first + 1;
if (cost < D[e]) {
D[e] = cost;
que.emplace(cost, e);
}
}
}
}
int main() {
std::cin >> N >> M >> Q;
for (int i = 0; i < M; ++i) {
std::cin >> path[i][0] >> path[i][1];
--path[i][0];
--path[i][1];
graph[path[i][0]].insert(path[i][1]);
graph[path[i][1]].insert(path[i][0]);
}
dij(0);
int32_t count = 0;
for (int i = 0; i < Q; ++i) {
int32_t R;
std::cin >> R;
--R;
int32_t from = path[R][0];
int32_t to = path[R][1];
graph[from].erase(graph[from].find(to));
graph[to].erase(graph[to].find(from));
if (D[to] == D[from]) {
std::cout << count << endl;
continue;
}
if (D[to] < D[from]) {
std::swap(from, to);
}
if (D[to] >= INF) {
std::cout << count << endl;
continue;
}
// 辺を逆にたどる
bool used[100000] = {}; //[1]:tmp
std::queue<int32_t> que;
que.emplace(to);
used[to] = true;
while (!que.empty()) {
auto n = que.front();
que.pop();
if (D[n] >= INF) {
continue;
}
bool path_is_exsists = false;
for (auto &e : graph[n]) {
if (D[e] < D[n]) {
path_is_exsists = true;
break;
}
}
if (path_is_exsists) {
// OK
} else {
++count;
D[n] = INF;
for (auto &e : graph[n]) {
if (!used[e] && D[e] < INF) {
used[e] = true;
que.push(e);
}
}
}
}
std::cout << count << endl;
}
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_set>
#define DEBUG
using std::endl;
constexpr int32_t INF = 1000000000;
std::unordered_set<int32_t> graph[100000];
int32_t path[200000][2];
int32_t N, M, Q;
int32_t D[100000];
void dij(int32_t s) {
using P = std::pair<int32_t, int32_t>;
std::queue<P> que;
for (auto &i : D)
i = INF;
D[0] = 0;
que.emplace(0, 0);
while (!que.empty()) {
auto n = que.front();
que.pop();
if (D[n.second] < n.first) {
continue;
}
for (auto &e : graph[n.second]) {
auto cost = n.first + 1;
if (cost < D[e]) {
D[e] = cost;
que.emplace(cost, e);
}
}
}
}
int main() {
std::cin >> N >> M >> Q;
for (int i = 0; i < M; ++i) {
std::cin >> path[i][0] >> path[i][1];
--path[i][0];
--path[i][1];
graph[path[i][0]].insert(path[i][1]);
graph[path[i][1]].insert(path[i][0]);
}
dij(0);
int32_t count = 0;
for (int i = 0; i < Q; ++i) {
int32_t R;
std::cin >> R;
--R;
int32_t from = path[R][0];
int32_t to = path[R][1];
graph[from].erase(graph[from].find(to));
graph[to].erase(graph[to].find(from));
if (D[to] == D[from]) {
std::cout << count << endl;
continue;
}
if (D[to] < D[from]) {
std::swap(from, to);
}
if (D[to] >= INF) {
std::cout << count << endl;
continue;
}
// 辺を逆にたどる
bool used[100000] = {}; //[1]:tmp
std::queue<int32_t> que;
que.emplace(to);
used[to] = true;
while (!que.empty()) {
auto n = que.front();
que.pop();
if (D[n] >= INF) {
continue;
}
bool path_is_exsists = false;
for (auto &e : graph[n]) {
if (D[e] < D[n]) {
path_is_exsists = true;
break;
}
}
if (path_is_exsists) {
// OK
} else {
++count;
D[n] = INF;
for (auto &e : graph[n]) {
if (!used[e] && D[e] < INF) {
used[e] = true;
que.push(e);
}
}
}
}
std::cout << count << endl;
}
} | replace | 10 | 11 | 10 | 11 | 0 | |
p00550 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n, m, q;
vector<P> dist(100010);
vector<vector<P>> G(100010);
void dijkstra(int s) {
for (int i = 0; i < n; i++)
dist[i] = P(1e9, 1e9);
priority_queue<T, vector<T>, greater<T>> que;
dist[s] = P(0, q);
que.push(T(0, s, q));
while (!que.empty()) {
int ccost, cv, cyear;
tie(ccost, cv, cyear) = que.top();
// cout << ccost << " " << cv << " " << cyear << endl;
que.pop();
if (ccost == dist[cv].fs) {
if (dist[cv].fs > cyear)
continue;
}
if (dist[cv].fs < ccost)
continue;
for (auto x : G[cv]) {
int nv, nyear;
tie(nv, nyear) = x;
int nnyear = min(nyear, cyear);
int ncost = ccost + 1;
// cout << nv << " " << nyear << " " << nnyear << " " << ncost << endl;
if (ncost == dist[nv].fs) {
if (dist[nv].sc < nnyear) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
} else if (ncost < dist[nv].fs) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
}
}
}
int main() {
cin >> n >> m >> q;
vector<int> u(m), v(m);
for (int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
u[i]--, v[i]--;
}
vector<int> changeYear(m, q);
for (int i = 0; i < q; i++) {
int r;
cin >> r;
r--;
changeYear[r] = i;
}
for (int i = 0; i < m; i++) {
G[u[i]].eb(P(v[i], changeYear[i]));
G[v[i]].eb(P(u[i], changeYear[i]));
}
dijkstra(0);
/*
for(int i=0; i<n; i++){
cout << dist[i].fs << " " << dist[i].sc << endl;
}
*/
vector<int> cnt(q + 1);
for (int i = 0; i < n; i++) {
cnt[dist[i].sc]++;
}
for (int i = 0; i < q; i++) {
if (0 < i)
cnt[i] += cnt[i - 1];
cout << cnt[i] << endl;
}
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n, m, q;
vector<P> dist(100010);
vector<vector<P>> G(100010);
void dijkstra(int s) {
for (int i = 0; i < n; i++)
dist[i] = P(1e9, 1e9);
priority_queue<T, vector<T>, greater<T>> que;
dist[s] = P(0, q);
que.push(T(0, s, q));
while (!que.empty()) {
int ccost, cv, cyear;
tie(ccost, cv, cyear) = que.top();
// cout << ccost << " " << cv << " " << cyear << endl;
que.pop();
if (ccost == dist[cv].fs) {
if (dist[cv].sc > cyear)
continue;
}
if (dist[cv].fs < ccost)
continue;
for (auto x : G[cv]) {
int nv, nyear;
tie(nv, nyear) = x;
int nnyear = min(nyear, cyear);
int ncost = ccost + 1;
// cout << nv << " " << nyear << " " << nnyear << " " << ncost << endl;
if (ncost == dist[nv].fs) {
if (dist[nv].sc < nnyear) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
} else if (ncost < dist[nv].fs) {
dist[nv] = P(ncost, nnyear);
que.push(T(dist[nv].fs, nv, nnyear));
}
}
}
}
int main() {
cin >> n >> m >> q;
vector<int> u(m), v(m);
for (int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
u[i]--, v[i]--;
}
vector<int> changeYear(m, q);
for (int i = 0; i < q; i++) {
int r;
cin >> r;
r--;
changeYear[r] = i;
}
for (int i = 0; i < m; i++) {
G[u[i]].eb(P(v[i], changeYear[i]));
G[v[i]].eb(P(u[i], changeYear[i]));
}
dijkstra(0);
/*
for(int i=0; i<n; i++){
cout << dist[i].fs << " " << dist[i].sc << endl;
}
*/
vector<int> cnt(q + 1);
for (int i = 0; i < n; i++) {
cnt[dist[i].sc]++;
}
for (int i = 0; i < q; i++) {
if (0 < i)
cnt[i] += cnt[i - 1];
cout << cnt[i] << endl;
}
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p00550 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
FILE *in = freopen("./input.txt", "r", stdin);
FILE *out = freopen("./output.txt", "w", stdout);
const int INF = 999999999;
int N, M, Q;
int main() {
scanf("%d%d%d", &N, &M, &Q);
vector<vector<int>> G(N);
vector<int> s(M), t(M);
for (int i = 0; i < M; i++) {
scanf("%d%d", &s[i], &t[i]);
s[i]--, t[i]--;
G[s[i]].push_back(t[i]);
G[t[i]].push_back(s[i]);
}
queue<int> que1;
que1.push(0);
vector<int> dist(N, INF);
dist[0] = 0;
while (!que1.empty()) {
int u = que1.front();
que1.pop();
for (int i : G[u]) {
if (dist[i] == INF) {
dist[i] = dist[u] + 1;
que1.push(i);
}
}
}
for (int i = 0; i < M; i++) {
if (dist[s[i]] > dist[t[i]])
swap(s[i], t[i]);
if (dist[s[i]] + 1 != dist[t[i]])
s[i] = -1;
}
vector<int> x(Q), f(M);
for (int i = 0; i < Q; i++)
scanf("%d", &x[i]), f[--x[i]] = 1;
vector<set<int>> G2(N);
vector<vector<int>> G3(N);
for (int i = 0; i < M; i++) {
if (!f[i] && s[i] != -1)
G2[s[i]].insert(t[i]);
if (s[i] != -1)
G3[t[i]].push_back(s[i]);
}
queue<int> que2;
que2.push(0);
vector<int> dist2(N, INF);
dist2[0] = 0;
while (!que2.empty()) {
int u = que2.front();
que2.pop();
for (int i : G2[u]) {
if (dist2[i] == INF) {
dist2[i] = dist2[u] + 1;
que2.push(i);
}
}
}
vector<int> ok(N);
for (int i = 0; i < N; i++) {
if (dist[i] == dist2[i])
ok[i] = 1;
}
int sum = 0;
for (int i = 0; i < N; i++)
sum += ok[i];
reverse(x.begin(), x.end());
vector<int> ret(Q);
for (int i = 0; i < Q; i++) {
ret[i] = N - sum;
int z = x[i];
if (s[z] == -1)
continue;
G2[s[z]].insert(t[z]);
if (ok[s[z]] == ok[t[z]])
continue;
if (!ok[s[z]])
swap(s[z], t[z]);
queue<int> que3;
que3.push(s[z]);
while (!que3.empty()) {
int u = que3.front();
que3.pop();
vector<int> moved;
for (int i : G2[u]) {
if (!ok[i]) {
ok[i] = 1;
sum++;
moved.push_back(i);
que3.push(i);
}
}
for (int i : moved) {
for (int j : G3[i]) {
G2[j].erase(i);
}
}
}
}
reverse(ret.begin(), ret.end());
for (int i : ret)
printf("%d\n", i);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
const int INF = 999999999;
int N, M, Q;
int main() {
scanf("%d%d%d", &N, &M, &Q);
vector<vector<int>> G(N);
vector<int> s(M), t(M);
for (int i = 0; i < M; i++) {
scanf("%d%d", &s[i], &t[i]);
s[i]--, t[i]--;
G[s[i]].push_back(t[i]);
G[t[i]].push_back(s[i]);
}
queue<int> que1;
que1.push(0);
vector<int> dist(N, INF);
dist[0] = 0;
while (!que1.empty()) {
int u = que1.front();
que1.pop();
for (int i : G[u]) {
if (dist[i] == INF) {
dist[i] = dist[u] + 1;
que1.push(i);
}
}
}
for (int i = 0; i < M; i++) {
if (dist[s[i]] > dist[t[i]])
swap(s[i], t[i]);
if (dist[s[i]] + 1 != dist[t[i]])
s[i] = -1;
}
vector<int> x(Q), f(M);
for (int i = 0; i < Q; i++)
scanf("%d", &x[i]), f[--x[i]] = 1;
vector<set<int>> G2(N);
vector<vector<int>> G3(N);
for (int i = 0; i < M; i++) {
if (!f[i] && s[i] != -1)
G2[s[i]].insert(t[i]);
if (s[i] != -1)
G3[t[i]].push_back(s[i]);
}
queue<int> que2;
que2.push(0);
vector<int> dist2(N, INF);
dist2[0] = 0;
while (!que2.empty()) {
int u = que2.front();
que2.pop();
for (int i : G2[u]) {
if (dist2[i] == INF) {
dist2[i] = dist2[u] + 1;
que2.push(i);
}
}
}
vector<int> ok(N);
for (int i = 0; i < N; i++) {
if (dist[i] == dist2[i])
ok[i] = 1;
}
int sum = 0;
for (int i = 0; i < N; i++)
sum += ok[i];
reverse(x.begin(), x.end());
vector<int> ret(Q);
for (int i = 0; i < Q; i++) {
ret[i] = N - sum;
int z = x[i];
if (s[z] == -1)
continue;
G2[s[z]].insert(t[z]);
if (ok[s[z]] == ok[t[z]])
continue;
if (!ok[s[z]])
swap(s[z], t[z]);
queue<int> que3;
que3.push(s[z]);
while (!que3.empty()) {
int u = que3.front();
que3.pop();
vector<int> moved;
for (int i : G2[u]) {
if (!ok[i]) {
ok[i] = 1;
sum++;
moved.push_back(i);
que3.push(i);
}
}
for (int i : moved) {
for (int j : G3[i]) {
G2[j].erase(i);
}
}
}
}
reverse(ret.begin(), ret.end());
for (int i : ret)
printf("%d\n", i);
return 0;
} | delete | 7 | 9 | 7 | 7 | -11 | |
p00550 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> x[1 << 17], d[1 << 17];
int a[1 << 17], b[1 << 17], ret[1 << 17], ans[1 << 17], n, m, q, dist[1 << 17];
vector<pair<int, int>> y[1 << 17];
map<pair<int, int>, int> M;
int main() {
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i];
x[a[i]].push_back(b[i]);
x[b[i]].push_back(a[i]);
}
for (int i = 1; i <= q; i++) {
int c;
cin >> c;
M[make_pair(a[c], b[c])] = i;
M[make_pair(b[c], a[c])] = i;
}
queue<int> Q;
Q.push(1);
for (int i = 1; i <= n; i++)
dist[i] = (1 << 25);
dist[1] = 0;
while (!Q.empty()) {
int a1 = Q.front();
Q.pop();
for (int j = 0; j < (int)x[a1].size(); j++) {
int i = x[a1][j];
if (dist[i] > dist[a1] + 1) {
dist[i] = dist[a1] + 1;
Q.push(i);
}
}
}
for (int i = 1; i <= n; i++) {
d[dist[i]].push_back(i);
for (int k = 0; k < (int)x[i].size(); k++) {
int j = x[i][k];
if (dist[i] > dist[j]) {
y[i].push_back(make_pair(j, M[make_pair(i, j)]));
// cout<<i<<' '<<j<<' '<<M[make_pair(i,j)]<<endl;
}
}
}
ret[1] = 1 << 30;
for (int h = 1; h <= n; h++) {
for (int l = 0; l < (int)d[h].size(); l++) {
int i = d[h][l];
for (int k = 0; k < (int)y[i].size(); k++) {
pair<int, int> j = y[i][k];
int cs = j.second;
if (cs == 0)
cs = (1 << 30);
ret[i] = max(ret[i], min(ret[j.first], cs));
}
}
}
// for(int i=1;i<=n;i++)cout<<ret[i]<<' '<<dist[i]<<endl;
for (int i = 1; i <= n; i++) {
if (ret[i] <= q)
ans[ret[i]]++;
}
for (int i = 1; i <= q; i++) {
ans[i] += ans[i - 1];
cout << ans[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> x[1 << 17], d[1 << 17];
int a[1 << 18], b[1 << 18], ret[1 << 17], ans[1 << 18], n, m, q, dist[1 << 17];
vector<pair<int, int>> y[1 << 17];
map<pair<int, int>, int> M;
int main() {
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i];
x[a[i]].push_back(b[i]);
x[b[i]].push_back(a[i]);
}
for (int i = 1; i <= q; i++) {
int c;
cin >> c;
M[make_pair(a[c], b[c])] = i;
M[make_pair(b[c], a[c])] = i;
}
queue<int> Q;
Q.push(1);
for (int i = 1; i <= n; i++)
dist[i] = (1 << 25);
dist[1] = 0;
while (!Q.empty()) {
int a1 = Q.front();
Q.pop();
for (int j = 0; j < (int)x[a1].size(); j++) {
int i = x[a1][j];
if (dist[i] > dist[a1] + 1) {
dist[i] = dist[a1] + 1;
Q.push(i);
}
}
}
for (int i = 1; i <= n; i++) {
d[dist[i]].push_back(i);
for (int k = 0; k < (int)x[i].size(); k++) {
int j = x[i][k];
if (dist[i] > dist[j]) {
y[i].push_back(make_pair(j, M[make_pair(i, j)]));
// cout<<i<<' '<<j<<' '<<M[make_pair(i,j)]<<endl;
}
}
}
ret[1] = 1 << 30;
for (int h = 1; h <= n; h++) {
for (int l = 0; l < (int)d[h].size(); l++) {
int i = d[h][l];
for (int k = 0; k < (int)y[i].size(); k++) {
pair<int, int> j = y[i][k];
int cs = j.second;
if (cs == 0)
cs = (1 << 30);
ret[i] = max(ret[i], min(ret[j.first], cs));
}
}
}
// for(int i=1;i<=n;i++)cout<<ret[i]<<' '<<dist[i]<<endl;
for (int i = 1; i <= n; i++) {
if (ret[i] <= q)
ans[ret[i]]++;
}
for (int i = 1; i <= q; i++) {
ans[i] += ans[i - 1];
cout << ans[i] << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00550 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
Int n, m, q;
cin >> n >> m >> q;
vector<vector<Int>> G(n);
auto T = G;
vector<Int> u(m), v(m);
vector<map<Int, Int>> R(n);
for (Int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
u[i]--;
v[i]--;
G[u[i]].emplace_back(v[i]);
G[v[i]].emplace_back(u[i]);
R[u[i]][v[i]] = i;
R[v[i]][u[i]] = i;
}
vector<Int> dp(n, -1);
{
dp[0] = 0;
queue<Int> qu({0});
while (!qu.empty()) {
Int v = qu.front();
qu.pop();
for (Int u : G[v]) {
if (~dp[u])
continue;
dp[u] = dp[v] + 1;
qu.emplace(u);
}
}
}
vector<Int> b(q), c(m, q);
for (Int i = 0; i < q; i++) {
cin >> b[i];
b[i]--;
c[b[i]] = i;
}
vector<Int> dp2(n, -1);
{
using P = pair<Int, Int>;
priority_queue<P, vector<P>, greater<P>> qu;
dp2[0] = q;
qu.emplace(q, 0);
while (!qu.empty()) {
P p = qu.top();
qu.pop();
Int d = p.first, x = p.second;
// cout<<x<<":"<<d<<endl;
if (dp2[x] > d)
continue;
for (Int y : G[x]) {
if (dp[x] + 1 != dp[y])
continue;
if (min(d, c[R[x][y]]) <= dp2[y])
continue;
dp2[y] = min(d, c[R[x][y]]);
qu.emplace(dp2[y], y);
}
}
}
vector<Int> a(q + 1, 0);
for (Int i = 0; i < n; i++)
a[dp2[i]]++;
for (Int i = q; i > 0; i--)
a[i - 1] += a[i];
for (Int i = 1; i <= q; i++)
cout << n - a[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
Int n, m, q;
cin >> n >> m >> q;
vector<vector<Int>> G(n);
auto T = G;
vector<Int> u(m), v(m);
vector<map<Int, Int>> R(n);
for (Int i = 0; i < m; i++) {
cin >> u[i] >> v[i];
u[i]--;
v[i]--;
G[u[i]].emplace_back(v[i]);
G[v[i]].emplace_back(u[i]);
R[u[i]][v[i]] = i;
R[v[i]][u[i]] = i;
}
vector<Int> dp(n, -1);
{
dp[0] = 0;
queue<Int> qu({0});
while (!qu.empty()) {
Int v = qu.front();
qu.pop();
for (Int u : G[v]) {
if (~dp[u])
continue;
dp[u] = dp[v] + 1;
qu.emplace(u);
}
}
}
vector<Int> b(q), c(m, q);
for (Int i = 0; i < q; i++) {
cin >> b[i];
b[i]--;
c[b[i]] = i;
}
vector<Int> dp2(n, -1);
{
using P = pair<Int, Int>;
priority_queue<P> qu;
dp2[0] = q;
qu.emplace(q, 0);
while (!qu.empty()) {
P p = qu.top();
qu.pop();
Int d = p.first, x = p.second;
// cout<<x<<":"<<d<<endl;
if (dp2[x] > d)
continue;
for (Int y : G[x]) {
if (dp[x] + 1 != dp[y])
continue;
if (min(d, c[R[x][y]]) <= dp2[y])
continue;
dp2[y] = min(d, c[R[x][y]]);
qu.emplace(dp2[y], y);
}
}
}
vector<Int> a(q + 1, 0);
for (Int i = 0; i < n; i++)
a[dp2[i]]++;
for (Int i = q; i > 0; i--)
a[i - 1] += a[i];
for (Int i = 1; i <= q; i++)
cout << n - a[i] << endl;
return 0;
} | replace | 46 | 47 | 46 | 47 | TLE | |
p00552 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
int seg = 1;
class RAQ {
vector<int> dat;
public:
RAQ() : dat(seg * 2 - 1) {}
void add(int a, int b, int x, int k = 0, int l = 0, int r = seg) {
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
dat[k] += x;
return;
}
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
int get(int i) {
int s = 0;
i += seg - 1;
s += dat[i];
while (i) {
i = (i - 1) / 2;
s += dat[i];
}
return s;
}
};
signed main() {
int n, q, x[100000], d[100000], l[100000];
cin >> n >> q;
while (seg < n)
seg *= 2;
vector<RAQ> ps(2);
for (int i = 0; i < n; i++) {
ps[0].add(i, i + 1, i);
ps[1].add(i, i + 1, n - i - 1);
}
for (int i = 0; i < q; i++)
cin >> x[i] >> d[i] >> l[i];
for (int i = q - 1; i >= 0; i--) {
int low = -1, up = n;
while (up - low > 1) {
int mid = (up + low) / 2;
if (d[i] == 1) {
if (ps[0].get(mid) < x[i])
low = mid;
else
up = mid;
} else {
if (ps[1].get(mid) < n - x[i])
up = mid;
else
low = mid;
}
}
if (d[i] == 1)
ps[1].add(0, up, l[i] * 2);
else
ps[0].add(up, seg, l[i] * 2);
}
for (int i = 0; i < n; i++)
cout << (ps[0].get(i) + ps[1].get(i) - n + 1) / 2 << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
int seg = 1;
class RAQ {
vector<int> dat;
public:
RAQ() : dat(seg * 2 - 1) {}
void add(int a, int b, int x, int k = 0, int l = 0, int r = seg) {
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
dat[k] += x;
return;
}
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
int get(int i) {
int s = 0;
i += seg - 1;
s += dat[i];
while (i) {
i = (i - 1) / 2;
s += dat[i];
}
return s;
}
};
signed main() {
int n, q, x[200000], d[200000], l[200000];
cin >> n >> q;
while (seg < n)
seg *= 2;
vector<RAQ> ps(2);
for (int i = 0; i < n; i++) {
ps[0].add(i, i + 1, i);
ps[1].add(i, i + 1, n - i - 1);
}
for (int i = 0; i < q; i++)
cin >> x[i] >> d[i] >> l[i];
for (int i = q - 1; i >= 0; i--) {
int low = -1, up = n;
while (up - low > 1) {
int mid = (up + low) / 2;
if (d[i] == 1) {
if (ps[0].get(mid) < x[i])
low = mid;
else
up = mid;
} else {
if (ps[1].get(mid) < n - x[i])
up = mid;
else
low = mid;
}
}
if (d[i] == 1)
ps[1].add(0, up, l[i] * 2);
else
ps[0].add(up, seg, l[i] * 2);
}
for (int i = 0; i < n; i++)
cout << (ps[0].get(i) + ps[1].get(i) - n + 1) / 2 << endl;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p00554 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n, m, a[100], b[100];
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (a[i] > a[j])
swap(a[i], a[j]);
}
}
int ans = 0;
for (int i = 0; i < m - 1; i++) {
if (a[i] <= n)
ans += n - a[i];
}
cout << ans << endl;
} | #include <iostream>
using namespace std;
int main() {
int n, m, a[1001], b[1001];
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (a[i] > a[j])
swap(a[i], a[j]);
}
}
int ans = 0;
for (int i = 0; i < m - 1; i++) {
if (a[i] <= n)
ans += n - a[i];
}
cout << ans << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00554 | C++ | Runtime Error | // q2.cpp
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 10000
int main() {
int n, m, a, b, s[SIZE];
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
s[i] = max(n - a, 0);
}
sort(s, s + m);
int ans = 0;
for (int i = 0; i < m - 1; i++) {
ans += s[i];
debug(s[i]);
}
cout << ans << endl;
return 0;
} | // q2.cpp
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 10000
int main() {
int n, m, a, b, s[SIZE];
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
s[i] = max(n - a, 0);
}
sort(s, s + m);
int ans = 0;
for (int i = 0; i < m - 1; i++) {
ans += s[i];
}
cout << ans << endl;
return 0;
} | delete | 46 | 47 | 46 | 46 | 0 | s[i] = 0
s[i] = 0
s[i] = 1
s[i] = 3
|
p00555 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for (i = 0; i < n; ++i)
#define rep1(i, n) for (i = 1; i < n; ++i)
#define per(i, n) for (i = n - 1; i > -1; --i)
#define int(x) \
int x; \
scanf("%d", &x)
#define int2(x, y) \
int x, y; \
scanf("%d%d", &x, &y)
#define int3(x, y, z) \
int x, y, z; \
scanf("%d%d%d", &x, &y, &z)
#define int4(v, x, y, z) \
int v, x, y, z; \
scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) \
int v, w, x, y, z; \
scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) \
cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)
string s[100];
int f[101][101] = {0};
int getsum(int t, int l, int b, int r) {
return f[b][r] - f[b][l] - f[t][r] + f[t][l];
}
signed main(void) {
int i, j;
for (int testcase = 0; testcase >= 0; testcase++) {
int3(n, m, d);
rep(i, n) cin >> s[i];
rep(i, n) rep(j, m) if (s[i][j] == '#') f[i + 1][j + 1]++;
rep(i, n + 1) rep(j, m) f[i + 1][j + 1] += f[i + 1][j];
rep(j, m + 1) rep(i, n) f[i + 1][j + 1] += f[i][j + 1];
int res = 0;
rep(i, n) rep(j, m - d + 1) if (getsum(i, j, i + 1, j + d) == 0)++ res;
rep(j, m) rep(i, n - d + 1) if (getsum(i, j, i + d, j + 1) == 0)++ res;
pri(res);
/*/
//*/
break;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for (i = 0; i < n; ++i)
#define rep1(i, n) for (i = 1; i < n; ++i)
#define per(i, n) for (i = n - 1; i > -1; --i)
#define int(x) \
int x; \
scanf("%d", &x)
#define int2(x, y) \
int x, y; \
scanf("%d%d", &x, &y)
#define int3(x, y, z) \
int x, y, z; \
scanf("%d%d%d", &x, &y, &z)
#define int4(v, x, y, z) \
int v, x, y, z; \
scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) \
int v, w, x, y, z; \
scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) \
cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)
string s[100];
int f[101][101] = {0};
int getsum(int t, int l, int b, int r) {
return f[b][r] - f[b][l] - f[t][r] + f[t][l];
}
signed main(void) {
int i, j;
for (int testcase = 0; testcase >= 0; testcase++) {
int3(n, m, d);
rep(i, n) cin >> s[i];
rep(i, n) rep(j, m) if (s[i][j] == '#') f[i + 1][j + 1]++;
rep(i, n + 1) rep(j, m) f[i][j + 1] += f[i][j];
rep(j, m + 1) rep(i, n) f[i + 1][j] += f[i][j];
int res = 0;
rep(i, n) rep(j, m - d + 1) if (getsum(i, j, i + 1, j + d) == 0)++ res;
rep(j, m) rep(i, n - d + 1) if (getsum(i, j, i + d, j + 1) == 0)++ res;
pri(res);
/*/
//*/
break;
}
return 0;
} | replace | 73 | 75 | 73 | 75 | 0 | |
p00555 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool b[110][110];
int main() {
int n, m, d;
cin >> n >> m >> d;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
b[i][j] = (c == '.');
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
bool f = true;
for (int k = 0; k < d; k++) {
f &= b[i + k][j];
}
ans += f;
f = true;
for (int k = 0; k < d; k++) {
f &= b[i][j + k];
}
ans += f;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
bool b[256][256];
int main() {
int n, m, d;
cin >> n >> m >> d;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
b[i][j] = (c == '.');
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
bool f = true;
for (int k = 0; k < d; k++) {
f &= b[i + k][j];
}
ans += f;
f = true;
for (int k = 0; k < d; k++) {
f &= b[i][j + k];
}
ans += f;
}
}
cout << ans << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00556 | C++ | Runtime Error | #include <iostream>
#define INF 1e+9
using namespace std;
int main() {
int n, m, a[100000], cnt[20] = {}, imos[100001][20] = {};
int dp[1 << 20] = {};
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
cnt[a[i]]++;
for (int j = 0; j < m; j++)
imos[i + 1][j] = imos[i][j];
imos[i + 1][a[i]]++;
}
for (int i = 0; i < (1 << 20); i++) {
dp[i] = INF;
}
dp[0] = 0;
for (int i = 1; i < (1 << n); i++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if ((i >> j) & 1)
sum += cnt[j];
}
for (int j = 0; j < m; j++) {
if ((i >> j) & 1) {
dp[i] = min(dp[i], dp[i & ~(1 << j)] + cnt[j] -
(imos[sum][j] - imos[sum - cnt[j]][j]));
}
}
}
cout << dp[(1 << m) - 1] << endl;
return 0;
} | #include <iostream>
#define INF 1e+9
using namespace std;
int main() {
int n, m, a[100000], cnt[20] = {}, imos[100001][20] = {};
int dp[1 << 20] = {};
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
cnt[a[i]]++;
for (int j = 0; j < m; j++)
imos[i + 1][j] = imos[i][j];
imos[i + 1][a[i]]++;
}
for (int i = 0; i < (1 << 20); i++) {
dp[i] = INF;
}
dp[0] = 0;
for (int i = 1; i < (1 << m); i++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if ((i >> j) & 1)
sum += cnt[j];
}
for (int j = 0; j < m; j++) {
if ((i >> j) & 1) {
dp[i] = min(dp[i], dp[i & ~(1 << j)] + cnt[j] -
(imos[sum][j] - imos[sum - cnt[j]][j]));
}
}
}
cout << dp[(1 << m) - 1] << endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | -11 | |
p00557 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int H, W;
int M[1000][1000];
int reach[1000][1000];
int x[100000], y[100000];
const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};
int main() {
scanf("%d %d", &H, &W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf("%d", &M[i][j]);
--M[i][j];
x[M[i][j]] = j;
y[M[i][j]] = i;
}
}
int ret = 0;
for (int i = 0; i < H * W; i++) {
int proc = i;
for (int j = 0; j < 4; j++) {
int nx = x[i] + vx[j], ny = y[i] + vy[j];
if (nx < 0 || ny < 0 || nx >= W || ny >= H)
continue;
if (M[ny][nx] < i) {
if (proc == i)
proc = reach[ny][nx];
else if (proc != reach[ny][nx])
proc = -1;
}
}
reach[y[i]][x[i]] = proc;
ret += proc == -1;
}
printf("%d\n", ret);
} | #include <bits/stdc++.h>
using namespace std;
int H, W;
int M[1000][1000];
int reach[1000][1000];
int x[1000000], y[1000000];
const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};
int main() {
scanf("%d %d", &H, &W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf("%d", &M[i][j]);
--M[i][j];
x[M[i][j]] = j;
y[M[i][j]] = i;
}
}
int ret = 0;
for (int i = 0; i < H * W; i++) {
int proc = i;
for (int j = 0; j < 4; j++) {
int nx = x[i] + vx[j], ny = y[i] + vy[j];
if (nx < 0 || ny < 0 || nx >= W || ny >= H)
continue;
if (M[ny][nx] < i) {
if (proc == i)
proc = reach[ny][nx];
else if (proc != reach[ny][nx])
proc = -1;
}
}
reach[y[i]][x[i]] = proc;
ret += proc == -1;
}
printf("%d\n", ret);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p00557 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
int dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
int a[1001][1001];
pint p[100002];
int b[100001], c[100001];
int main() {
int h, w;
cin >> h >> w;
rep(i, h) rep(j, w) {
cin >> a[i][j];
p[a[i][j]] = {j, i};
}
int ans = 0;
rep(l, h * w) {
int j = p[l + 1].first, i = p[l + 1].second;
int cnt = 0;
rep(k, 4) {
int ty = i + dy[k], tx = j + dx[k];
if (ty >= 0 && tx >= 0 && ty < h && tx < w && a[ty][tx] < a[i][j]) {
if (b[a[ty][tx]] == -1) {
if (b[l + 1] == 0)
c[l + 1] = a[ty][tx], b[l + 1] = 1;
else if (b[l + 1] == 1 && c[l + 1] != a[ty][tx]) {
++ans, b[l + 1] = 2;
cnt = 4;
break;
}
} else if (b[a[ty][tx]] == 1) {
if (b[l + 1] == 0) {
c[l + 1] = c[a[ty][tx]];
b[l + 1] = 1;
} else {
if (c[l + 1] != c[a[ty][tx]]) {
b[l + 1] = 2;
++ans;
cnt = 4;
break;
}
}
} else if (b[a[ty][tx]] == 2) {
b[l + 1] = 2;
++ans;
cnt = 4;
break;
}
}
if (ty >= 0 && tx >= 0 && ty < h && tx < w && a[ty][tx] < a[i][j])
++cnt;
}
if (cnt == 0)
b[l + 1] = -1;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
int dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
int a[1001][1001];
pint p[1000002];
int b[1000002], c[1000002];
int main() {
int h, w;
cin >> h >> w;
rep(i, h) rep(j, w) {
cin >> a[i][j];
p[a[i][j]] = {j, i};
}
int ans = 0;
rep(l, h * w) {
int j = p[l + 1].first, i = p[l + 1].second;
int cnt = 0;
rep(k, 4) {
int ty = i + dy[k], tx = j + dx[k];
if (ty >= 0 && tx >= 0 && ty < h && tx < w && a[ty][tx] < a[i][j]) {
if (b[a[ty][tx]] == -1) {
if (b[l + 1] == 0)
c[l + 1] = a[ty][tx], b[l + 1] = 1;
else if (b[l + 1] == 1 && c[l + 1] != a[ty][tx]) {
++ans, b[l + 1] = 2;
cnt = 4;
break;
}
} else if (b[a[ty][tx]] == 1) {
if (b[l + 1] == 0) {
c[l + 1] = c[a[ty][tx]];
b[l + 1] = 1;
} else {
if (c[l + 1] != c[a[ty][tx]]) {
b[l + 1] = 2;
++ans;
cnt = 4;
break;
}
}
} else if (b[a[ty][tx]] == 2) {
b[l + 1] = 2;
++ans;
cnt = 4;
break;
}
}
if (ty >= 0 && tx >= 0 && ty < h && tx < w && a[ty][tx] < a[i][j])
++cnt;
}
if (cnt == 0)
b[l + 1] = -1;
}
cout << ans << endl;
return 0;
}
| replace | 10 | 12 | 10 | 12 | 0 | |
p00557 | C++ | Time Limit Exceeded | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
int H, W, M[1234][1234];
vector<vector<int>> water;
vector<set<int>> water_to;
vector<bool> isOne;
int index(int w, int h) {
if (w < 0 || h < 0 || w >= W || h >= H)
return -1;
return h * W + w;
}
void GetWaterTo(int i) {
if (water_to[i].size() > 0)
return;
if (water[i].size() == 0)
water_to[i].insert(i);
rep(j, water[i].size()) {
GetWaterTo(water[i][j]);
if (isOne[water[i][j]] || water_to[water[i][j]].size() >= 2) {
isOne[i] = true;
break;
}
water_to[i].insert(water_to[water[i][j]].begin(),
water_to[water[i][j]].end());
}
return;
}
int main() {
scanf("%d %d", &H, &W);
water.resize(H * W);
water_to.resize(H * W);
isOne.resize(H * W, false);
vector<pair<int, int>> order;
int IndexCount = 0;
rep(i, H) rep(j, W) {
scanf("%d", &M[i][j]);
order.push_back(make_pair(M[i][j], IndexCount));
IndexCount++;
}
rep(i, H) rep(j, W) {
rep(d, 4) {
if (index(j + dx[d], i + dy[d]) != -1 &&
M[i][j] > M[i + dy[d]][j + dx[d]]) {
water[index(j, i)].push_back(index(j + dx[d], i + dy[d]));
}
}
}
sort(order.begin(), order.end());
rep(i, order.size()) GetWaterTo(order[i].second);
// rep(i, H*W) GetWaterTo(i);
int c = 0;
rep(i, H * W) if (isOne[i] || water_to[i].size() >= 2) c++;
printf("%d\n", c);
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
int H, W, M[1234][1234];
vector<vector<int>> water;
vector<set<int>> water_to;
vector<bool> isOne;
int index(int w, int h) {
if (w < 0 || h < 0 || w >= W || h >= H)
return -1;
return h * W + w;
}
void GetWaterTo(int i) {
if (water_to[i].size() > 0 || isOne[i])
return;
if (water[i].size() == 0)
water_to[i].insert(i);
rep(j, water[i].size()) {
GetWaterTo(water[i][j]);
if (isOne[water[i][j]] || water_to[water[i][j]].size() >= 2) {
isOne[i] = true;
break;
}
water_to[i].insert(water_to[water[i][j]].begin(),
water_to[water[i][j]].end());
}
return;
}
int main() {
scanf("%d %d", &H, &W);
water.resize(H * W);
water_to.resize(H * W);
isOne.resize(H * W, false);
vector<pair<int, int>> order;
int IndexCount = 0;
rep(i, H) rep(j, W) {
scanf("%d", &M[i][j]);
order.push_back(make_pair(M[i][j], IndexCount));
IndexCount++;
}
rep(i, H) rep(j, W) {
rep(d, 4) {
if (index(j + dx[d], i + dy[d]) != -1 &&
M[i][j] > M[i + dy[d]][j + dx[d]]) {
water[index(j, i)].push_back(index(j + dx[d], i + dy[d]));
}
}
}
sort(order.begin(), order.end());
rep(i, order.size()) GetWaterTo(order[i].second);
// rep(i, H*W) GetWaterTo(i);
int c = 0;
rep(i, H * W) if (isOne[i] || water_to[i].size() >= 2) c++;
printf("%d\n", c);
return 0;
} | replace | 30 | 31 | 30 | 31 | TLE | |
p00558 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct st {
int p, d, c, h;
st() {}
st(int p, int d, int c, int h) : p(p), d(d), c(c), h(h) {}
bool operator<(const st &a) const { return d > a.d; }
};
struct edge {
int to, cost;
edge() {}
edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> G[10001];
int dp[10001][201][201];
int main() {
int n, m, x;
cin >> n >> m >> x;
int s[n];
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < m; i++) {
int a, b, d;
cin >> a >> b >> d;
a--;
b--;
G[a].push_back(edge(b, d));
G[b].push_back(edge(a, d));
}
memset(dp, -1, sizeof(dp));
priority_queue<st> q;
q.push(st(0, 0, x, 0));
int ans = 0;
while (!q.empty()) {
st t = q.top();
q.pop();
if (~dp[t.p][t.c][t.h] && dp[t.p][t.c][t.h] <= t.d)
continue;
dp[t.p][t.c][t.h] = t.d;
if (t.p == n - 1) {
ans = t.d;
break;
}
for (int i = 0; i < (int)G[t.p].size(); i++) {
int v = G[t.p][i].to, u = G[t.p][i].cost;
int c = max(0, t.c - u), h = max(0, t.h - u);
if (~dp[v][c][h] && dp[v][c][h] <= t.d + u)
continue;
if (s[v] == 0) {
if (h > 0)
continue;
q.push(st(v, t.d + u, x, h));
}
if (s[v] == 1) {
q.push(st(v, t.d + u, c, h));
}
if (s[v] == 2) {
if (c > 0)
continue;
q.push(st(v, t.d + u, c, x));
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct st {
int p, d, c, h;
st() {}
st(int p, int d, int c, int h) : p(p), d(d), c(c), h(h) {}
bool operator<(const st &a) const { return d > a.d; }
};
struct edge {
int to, cost;
edge() {}
edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> G[10001];
short dp[10001][201][201];
int main() {
int n, m, x;
cin >> n >> m >> x;
int s[n];
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < m; i++) {
int a, b, d;
cin >> a >> b >> d;
a--;
b--;
G[a].push_back(edge(b, d));
G[b].push_back(edge(a, d));
}
memset(dp, -1, sizeof(dp));
priority_queue<st> q;
q.push(st(0, 0, x, 0));
int ans = 0;
while (!q.empty()) {
st t = q.top();
q.pop();
if (~dp[t.p][t.c][t.h] && dp[t.p][t.c][t.h] <= t.d)
continue;
dp[t.p][t.c][t.h] = t.d;
if (t.p == n - 1) {
ans = t.d;
break;
}
for (int i = 0; i < (int)G[t.p].size(); i++) {
int v = G[t.p][i].to, u = G[t.p][i].cost;
int c = max(0, t.c - u), h = max(0, t.h - u);
if (~dp[v][c][h] && dp[v][c][h] <= t.d + u)
continue;
if (s[v] == 0) {
if (h > 0)
continue;
q.push(st(v, t.d + u, x, h));
}
if (s[v] == 1) {
q.push(st(v, t.d + u, c, h));
}
if (s[v] == 2) {
if (c > 0)
continue;
q.push(st(v, t.d + u, c, x));
}
}
}
cout << ans << endl;
return 0;
} | replace | 14 | 15 | 14 | 15 | MLE | |
p00558 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const int inf = 1 << 25; // 1LL << 55;
const int mod = 1e9 + 7;
struct edge {
int to, cost;
edge() {}
edge(int to, int cost) : to(to), cost(cost) {}
};
struct state {
int v, cost, rt, te;
state() {}
state(int v, int cost, int rt, int te) : v(v), cost(cost), rt(rt), te(te) {}
bool operator<(const state &r) const { return cost > r.cost; }
};
int N, M, X;
int T[10010];
vector<edge> G[10010];
int mincost[2][202][10010];
int dijkstra() {
rep(i, 2) rep(j, 202) rep(k, 10010) mincost[i][j][k] = inf;
priority_queue<state> que;
que.emplace(0, 0, 0, 0);
mincost[0][0][0] = 0;
while (!que.empty()) {
state s = que.top();
que.pop();
if (s.v == N - 1)
return s.cost;
if (s.cost > mincost[s.rt / 2][s.te][s.v])
continue;
for (edge &e : G[s.v]) {
if (abs(s.rt - T[e.to]) == 2 && s.te + e.cost < X)
continue;
int nrt = s.rt, nte = max(s.te + e.cost, X);
if (T[e.to] != 1)
nrt = T[e.to], nte = 0;
if (s.cost + e.cost < mincost[nrt / 2][nte][e.to]) {
mincost[nrt / 2][nte][e.to] = s.cost + e.cost;
que.emplace(e.to, s.cost + e.cost, nrt, nte);
}
}
}
return -1;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
cin >> N >> M >> X;
rep(i, N) cin >> T[i];
rep(i, M) {
int A, B, D;
cin >> A >> B >> D;
A--, B--;
G[A].emplace_back(B, D);
G[B].emplace_back(A, D);
}
cout << dijkstra() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const int inf = 1 << 25; // 1LL << 55;
const int mod = 1e9 + 7;
struct edge {
int to, cost;
edge() {}
edge(int to, int cost) : to(to), cost(cost) {}
};
struct state {
int v, cost, rt, te;
state() {}
state(int v, int cost, int rt, int te) : v(v), cost(cost), rt(rt), te(te) {}
bool operator<(const state &r) const { return cost > r.cost; }
};
int N, M, X;
int T[10010];
vector<edge> G[10010];
int mincost[2][202][10010];
int dijkstra() {
rep(i, 2) rep(j, 202) rep(k, 10010) mincost[i][j][k] = inf;
priority_queue<state> que;
que.emplace(0, 0, 0, 0);
mincost[0][0][0] = 0;
while (!que.empty()) {
state s = que.top();
que.pop();
if (s.v == N - 1)
return s.cost;
if (s.cost > mincost[s.rt / 2][s.te][s.v])
continue;
for (edge &e : G[s.v]) {
if (abs(s.rt - T[e.to]) == 2 && s.te + e.cost < X)
continue;
int nrt = s.rt, nte = min(s.te + e.cost, X);
if (T[e.to] != 1)
nrt = T[e.to], nte = 0;
if (s.cost + e.cost < mincost[nrt / 2][nte][e.to]) {
mincost[nrt / 2][nte][e.to] = s.cost + e.cost;
que.emplace(e.to, s.cost + e.cost, nrt, nte);
}
}
}
return -1;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
cin >> N >> M >> X;
rep(i, N) cin >> T[i];
rep(i, M) {
int A, B, D;
cin >> A >> B >> D;
A--, B--;
G[A].emplace_back(B, D);
G[B].emplace_back(A, D);
}
cout << dijkstra() << endl;
return 0;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p00559 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
ll N, Q, S, T;
cin >> N >> Q >> S >> T;
vector<ll> A(N + 1);
vector<ll> B(N);
for (ll i = 0; i <= N; i++) {
cin >> A[i];
}
for (ll i = 1; i <= N; i++) {
B[i - 1] = A[i] - A[i - 1];
}
ll ans = 0;
for (int i = 0; i < N; i++) {
if (B[i] > 0) {
ans -= B[i] * S;
} else {
ans -= B[i] * T;
}
}
for (int i = 0; i < Q; i++) {
ll l, r, x;
cin >> l >> r >> x;
l--;
if (B[l] > 0)
ans += B[l] * S;
else
ans += B[l] * T;
if (r != N) {
if (B[r] > 0)
ans += B[r] * S;
else
ans += B[r] * T;
}
B[l] += x;
B[r] -= x;
if (B[l] > 0) {
ans -= B[l] * S;
} else {
ans -= B[l] * T;
}
if (r != N) {
if (B[r] > 0) {
ans -= B[r] * S;
} else {
ans -= B[r] * T;
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
ll N, Q, S, T;
cin >> N >> Q >> S >> T;
vector<ll> A(N + 1);
vector<ll> B(N);
for (ll i = 0; i <= N; i++) {
cin >> A[i];
}
for (ll i = 1; i <= N; i++) {
B[i - 1] = A[i] - A[i - 1];
}
ll ans = 0;
for (int i = 0; i < N; i++) {
if (B[i] > 0) {
ans -= B[i] * S;
} else {
ans -= B[i] * T;
}
}
for (int i = 0; i < Q; i++) {
ll l, r, x;
cin >> l >> r >> x;
l--;
if (B[l] > 0)
ans += B[l] * S;
else
ans += B[l] * T;
if (r != N) {
if (B[r] > 0)
ans += B[r] * S;
else
ans += B[r] * T;
}
B[l] += x;
if (r != N)
B[r] -= x;
if (B[l] > 0) {
ans -= B[l] * S;
} else {
ans -= B[l] * T;
}
if (r != N) {
if (B[r] > 0) {
ans -= B[r] * S;
} else {
ans -= B[r] * T;
}
}
cout << ans << endl;
}
return 0;
} | replace | 44 | 45 | 44 | 46 | 0 | |
p00562 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#define PAIR pair<int, int>
using namespace std;
class point {
public:
vector<long long> dp;
long long fast;
point() {
dp.resize(5, ((long long)1 << 63) - 1);
fast = 10000000;
}
};
int H, W;
long long A, B, C, N;
vector<PAIR> mv;
class num {
public:
long long time;
PAIR pos;
int dir;
};
bool operator<(const num &A, const num &B) { return A.time < B.time; }
bool operator>(const num &A, const num &B) { return A.time > B.time; }
bool operator==(const num &A, const num &B) { return A.time == B.time; }
PAIR operator+(const PAIR &A, const PAIR &B) {
PAIR res;
res.first = A.first + B.first;
res.second = A.second + B.second;
return res;
}
point &getpa(vector<vector<point>> &map, PAIR d) {
int x = d.first;
int y = d.second;
return map[x][y];
}
void getfast(vector<vector<point>> &, vector<PAIR> &);
bool isin(int, int);
int main() {
mv.resize(5);
mv[0] = PAIR(1, 0);
mv[1] = PAIR(0, -1);
mv[2] = PAIR(-1, 0);
mv[3] = PAIR(0, 1);
mv[4] = PAIR(0, 0);
cin >> H >> W >> A >> B >> C >> N;
vector<vector<point>> map(W + 1, vector<point>(H + 1));
vector<PAIR> player(N);
for (int i = 0; i < N; ++i) {
cin >> player[i].second >> player[i].first;
}
getfast(map, player);
priority_queue<num, vector<num>, greater<num>> que;
getpa(map, player[0]).dp[4] = 0;
num start;
start.time = 0;
start.pos = player[0];
start.dir = 4;
/*
for(int y=0;y<map.front().size();++y){
for(int x=0;x<map.size();++x){
cout<<map[x][y].dp[4]<<" ";
}
cout<<endl;
}
*/
que.push(start);
while (!que.empty()) {
num d = que.top();
que.pop();
if (d.time != getpa(map, d.pos).dp[d.dir]) {
continue;
}
if (d.dir < 4) {
PAIR np = d.pos + mv[d.dir];
if (isin(np.first, np.second)) {
long long ntime = d.time + A;
if (ntime < getpa(map, np).dp[d.dir]) {
getpa(map, np).dp[d.dir] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = np;
dnum.dir = d.dir;
que.push(dnum);
}
}
long long ntime = d.time + getpa(map, d.pos).fast;
if (ntime < getpa(map, d.pos).dp[4]) {
getpa(map, d.pos).dp[4] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = d.pos;
dnum.dir = 4;
que.push(dnum);
}
} else {
for (int i = 0; i < 4; ++i) {
long long ntime = d.time + B;
if (ntime < getpa(map, d.pos).dp[i]) {
getpa(map, d.pos).dp[i] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = d.pos;
dnum.dir = i;
que.push(dnum);
}
ntime = d.time + C;
PAIR np = d.pos + mv[i];
if (!isin(np.first, np.second)) {
continue;
}
if (ntime < getpa(map, np).dp[4]) {
getpa(map, np).dp[4] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = np;
dnum.dir = 4;
que.push(dnum);
}
}
}
}
cout << getpa(map, player.back()).dp[4] << endl;
/*
for(int y=0;y<map.front().size();++y){
for(int x=0;x<map.size();++x){
cout<<map[x][y].dp[4]<<" ";
}
cout<<endl;
}
*/
return 0;
}
void getfast(vector<vector<point>> &map, vector<PAIR> &player) {
queue<PAIR> que;
for (int i = 0; i < player.size(); ++i) {
int x = player[i].first;
int y = player[i].second;
que.push(player[i]);
getpa(map, player[i]).fast = 0;
}
while (!que.empty()) {
PAIR d = que.front();
que.pop();
for (int i = 0; i < 4; ++i) {
PAIR np = d + mv[i];
if (!isin(np.first, np.second)) {
continue;
}
if (getpa(map, np).fast > getpa(map, d).fast) {
getpa(map, np).fast = getpa(map, d).fast + 1;
que.push(np);
}
}
}
for (int x = 0; x < map.size(); ++x) {
for (int y = 0; y < map.front().size(); ++y) {
getpa(map, PAIR(x, y)).fast *= C;
}
}
}
bool isin(int x, int y) { return x >= 0 && x <= W && y >= 0 && y <= H; }
| #include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#define PAIR pair<int, int>
using namespace std;
class point {
public:
vector<long long> dp;
long long fast;
point() {
dp.resize(5, ((long long)1 << 63) - 1);
fast = 10000000;
}
};
int H, W;
long long A, B, C, N;
vector<PAIR> mv;
class num {
public:
long long time;
PAIR pos;
int dir;
};
bool operator<(const num &A, const num &B) { return A.time < B.time; }
bool operator>(const num &A, const num &B) { return A.time > B.time; }
bool operator==(const num &A, const num &B) { return A.time == B.time; }
PAIR operator+(const PAIR &A, const PAIR &B) {
PAIR res;
res.first = A.first + B.first;
res.second = A.second + B.second;
return res;
}
point &getpa(vector<vector<point>> &map, PAIR d) {
int x = d.first;
int y = d.second;
return map[x][y];
}
void getfast(vector<vector<point>> &, vector<PAIR> &);
bool isin(int, int);
int main() {
mv.resize(5);
mv[0] = PAIR(1, 0);
mv[1] = PAIR(0, -1);
mv[2] = PAIR(-1, 0);
mv[3] = PAIR(0, 1);
mv[4] = PAIR(0, 0);
cin >> H >> W >> A >> B >> C >> N;
vector<vector<point>> map(W + 1, vector<point>(H + 1));
vector<PAIR> player(N);
for (int i = 0; i < N; ++i) {
cin >> player[i].second >> player[i].first;
}
getfast(map, player);
priority_queue<num, vector<num>, greater<num>> que;
getpa(map, player[0]).dp[4] = 0;
num start;
start.time = 0;
start.pos = player[0];
start.dir = 4;
/*
for(int y=0;y<map.front().size();++y){
for(int x=0;x<map.size();++x){
cout<<map[x][y].dp[4]<<" ";
}
cout<<endl;
}
*/
que.push(start);
while (!que.empty()) {
num d = que.top();
que.pop();
if (d.time != getpa(map, d.pos).dp[d.dir]) {
continue;
}
if (d.dir < 4) {
PAIR np = d.pos + mv[d.dir];
if (isin(np.first, np.second)) {
long long ntime = d.time + A;
if (ntime < getpa(map, np).dp[d.dir]) {
getpa(map, np).dp[d.dir] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = np;
dnum.dir = d.dir;
que.push(dnum);
}
}
long long ntime = d.time + getpa(map, d.pos).fast;
if (ntime < getpa(map, d.pos).dp[4]) {
getpa(map, d.pos).dp[4] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = d.pos;
dnum.dir = 4;
que.push(dnum);
}
} else {
for (int i = 0; i < 4; ++i) {
long long ntime = d.time + B;
if (ntime < getpa(map, d.pos).dp[i]) {
getpa(map, d.pos).dp[i] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = d.pos;
dnum.dir = i;
que.push(dnum);
}
ntime = d.time + C;
PAIR np = d.pos + mv[i];
if (!isin(np.first, np.second)) {
continue;
}
if (ntime < getpa(map, np).dp[4]) {
getpa(map, np).dp[4] = ntime;
num dnum;
dnum.time = ntime;
dnum.pos = np;
dnum.dir = 4;
que.push(dnum);
}
}
}
}
cout << getpa(map, player.back()).dp[4] << endl;
/*
for(int y=0;y<map.front().size();++y){
for(int x=0;x<map.size();++x){
cout<<map[x][y].dp[4]<<" ";
}
cout<<endl;
}
*/
return 0;
}
void getfast(vector<vector<point>> &map, vector<PAIR> &player) {
queue<PAIR> que;
for (int i = 0; i < player.size(); ++i) {
int x = player[i].first;
int y = player[i].second;
que.push(player[i]);
getpa(map, player[i]).fast = 0;
}
while (!que.empty()) {
PAIR d = que.front();
que.pop();
for (int i = 0; i < 4; ++i) {
PAIR np = d + mv[i];
if (!isin(np.first, np.second)) {
continue;
}
if (getpa(map, np).fast > getpa(map, d).fast + 1) {
getpa(map, np).fast = getpa(map, d).fast + 1;
que.push(np);
}
}
}
for (int x = 0; x < map.size(); ++x) {
for (int y = 0; y < map.front().size(); ++y) {
getpa(map, PAIR(x, y)).fast *= C;
}
}
}
bool isin(int x, int y) { return x >= 0 && x <= W && y >= 0 && y <= H; }
| replace | 158 | 159 | 158 | 159 | MLE | |
p00562 | C++ | Memory Limit Exceeded | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
struct edge {
int to;
ll cost;
};
struct state {
int pos;
ll cost;
};
bool operator<(const state &s1, const state &s2) { return s1.cost > s2.cost; }
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int H, W, A, B, C, N, x[100009], y[100009], xl[100009], xr[100009], yl[100009],
yr[100009], ds[509][509];
vector<vector<edge>> g;
void add_edge(int v1, int v2, ll c) { g[v1].push_back(edge{v2, c}); }
void add_edge2(int v1, int v2, ll c) {
add_edge(v1, v2, c);
add_edge(v2, v1, c);
}
ll shortest_path(int start, int goal) {
vector<ll> dist(g.size(), 1LL << 60);
dist[start] = 0;
priority_queue<state> que;
que.push(state{start, 0});
while (!que.empty()) {
int u = que.top().pos;
que.pop();
for (edge e : g[u]) {
ll nd = dist[u] + e.cost;
if (dist[e.to] > nd) {
dist[e.to] = nd;
que.push(state{e.to, e.cost});
}
}
}
return dist[goal];
}
int main() {
ios::sync_with_stdio(false);
cin >> H >> W >> A >> B >> C >> N;
H++;
W++;
g.resize(3 * H * W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (j >= 1) {
add_edge2(i * W + j, i * W + j - 1, C);
add_edge2(H * W + i * W + j, H * W + i * W + j - 1, A);
}
if (i >= 1) {
add_edge2(i * W + j, i * W + j - W, C);
add_edge2(2 * H * W + i * W + j, 2 * H * W + i * W + j - W, A);
}
add_edge(i * W + j, H * W + i * W + j, B);
add_edge(i * W + j, 2 * H * W + i * W + j, B);
ds[i][j] = -1;
}
}
fill(xl, xl + H, W + 1);
fill(xr, xr + H, -1);
fill(yl, yl + W, H + 1);
fill(yr, yr + W, -1);
queue<pair<int, int>> qs;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
xl[x[i]] = min(xl[x[i]], y[i]);
xr[x[i]] = max(xr[x[i]], y[i]);
yl[y[i]] = min(yl[y[i]], x[i]);
yr[y[i]] = max(yr[y[i]], x[i]);
ds[x[i]][y[i]] = 0;
add_edge(H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
add_edge(2 * H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
qs.push(make_pair(x[i], y[i]));
}
while (!qs.empty()) {
pair<int, int> u = qs.front();
qs.pop();
for (int i = 0; i < 4; i++) {
int px = u.first + dx[i], py = u.second + dy[i];
if (0 <= px && px < H && 0 <= py && py < W && ds[px][py] == -1) {
ds[px][py] = ds[u.first][u.second] + 1;
add_edge(H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
add_edge(2 * H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
qs.push(make_pair(px, py));
}
}
}
cout << shortest_path(x[0] * W + y[0], x[N - 1] * W + y[N - 1]) << '\n';
return 0;
} | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
struct edge {
int to;
ll cost;
};
struct state {
int pos;
ll cost;
};
bool operator<(const state &s1, const state &s2) { return s1.cost > s2.cost; }
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int H, W, A, B, C, N, x[100009], y[100009], xl[100009], xr[100009], yl[100009],
yr[100009], ds[509][509];
vector<vector<edge>> g;
void add_edge(int v1, int v2, ll c) { g[v1].push_back(edge{v2, c}); }
void add_edge2(int v1, int v2, ll c) {
add_edge(v1, v2, c);
add_edge(v2, v1, c);
}
ll shortest_path(int start, int goal) {
vector<ll> dist(g.size(), 1LL << 60);
dist[start] = 0;
priority_queue<state> que;
que.push(state{start, 0});
while (!que.empty()) {
int u = que.top().pos;
que.pop();
for (edge e : g[u]) {
ll nd = dist[u] + e.cost;
if (dist[e.to] > nd) {
dist[e.to] = nd;
que.push(state{e.to, nd});
}
}
}
return dist[goal];
}
int main() {
ios::sync_with_stdio(false);
cin >> H >> W >> A >> B >> C >> N;
H++;
W++;
g.resize(3 * H * W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (j >= 1) {
add_edge2(i * W + j, i * W + j - 1, C);
add_edge2(H * W + i * W + j, H * W + i * W + j - 1, A);
}
if (i >= 1) {
add_edge2(i * W + j, i * W + j - W, C);
add_edge2(2 * H * W + i * W + j, 2 * H * W + i * W + j - W, A);
}
add_edge(i * W + j, H * W + i * W + j, B);
add_edge(i * W + j, 2 * H * W + i * W + j, B);
ds[i][j] = -1;
}
}
fill(xl, xl + H, W + 1);
fill(xr, xr + H, -1);
fill(yl, yl + W, H + 1);
fill(yr, yr + W, -1);
queue<pair<int, int>> qs;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
xl[x[i]] = min(xl[x[i]], y[i]);
xr[x[i]] = max(xr[x[i]], y[i]);
yl[y[i]] = min(yl[y[i]], x[i]);
yr[y[i]] = max(yr[y[i]], x[i]);
ds[x[i]][y[i]] = 0;
add_edge(H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
add_edge(2 * H * W + x[i] * W + y[i], x[i] * W + y[i], 0);
qs.push(make_pair(x[i], y[i]));
}
while (!qs.empty()) {
pair<int, int> u = qs.front();
qs.pop();
for (int i = 0; i < 4; i++) {
int px = u.first + dx[i], py = u.second + dy[i];
if (0 <= px && px < H && 0 <= py && py < W && ds[px][py] == -1) {
ds[px][py] = ds[u.first][u.second] + 1;
add_edge(H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
add_edge(2 * H * W + px * W + py, px * W + py, 1LL * ds[px][py] * C);
qs.push(make_pair(px, py));
}
}
}
cout << shortest_path(x[0] * W + y[0], x[N - 1] * W + y[N - 1]) << '\n';
return 0;
} | replace | 36 | 37 | 36 | 37 | MLE | |
p00570 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
vector<ll> v;
int main(void) {
vector<ll> v;
int n, k;
ll t[10000];
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t[i];
if (i != 0) {
v.push_back(t[i] - t[i - 1] - 1);
}
}
sort(v.begin(), v.end());
ll ans = n;
for (int i = 0; i < n - k; i++) {
ans += v[i];
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
vector<ll> v;
int main(void) {
vector<ll> v;
int n, k;
ll t[1000000];
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t[i];
if (i != 0) {
v.push_back(t[i] - t[i - 1] - 1);
}
}
sort(v.begin(), v.end());
ll ans = n;
for (int i = 0; i < n - k; i++) {
ans += v[i];
}
cout << ans << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p00570 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
vector<ll> v;
int main(void) {
vector<ll> v;
int n, k;
ll t[10000];
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t[i];
if (i != 0) {
v.push_back(t[i] - t[i - 1] - 1);
}
}
sort(v.begin(), v.end());
ll ans = n;
for (int i = 0; i < n - k; i++) {
ans += v[i];
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
vector<ll> v;
int main(void) {
vector<ll> v;
int n, k;
ll t[100000];
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t[i];
if (i != 0) {
v.push_back(t[i] - t[i - 1] - 1);
}
}
sort(v.begin(), v.end());
ll ans = n;
for (int i = 0; i < n - k; i++) {
ans += v[i];
}
cout << ans << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p00570 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int temp, n, k, t[100000], m, s[100000];
cin >> n >> k;
m = n;
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < n - 1; i++) {
s[i] = t[i + 1] - t[i] - 1;
}
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] > s[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
for (int i = 0; i < n - k; i++) {
m += s[i];
}
cout << m << endl;
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int temp, n, k, t[100000], m, s[100000];
cin >> n >> k;
m = n;
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < n - 1; i++) {
s[i] = t[i + 1] - t[i] - 1;
}
sort(s, s + n - 1);
for (int i = 0; i < n - k; i++) {
m += s[i];
}
cout << m << endl;
return 0;
}
| replace | 15 | 24 | 15 | 18 | TLE | |
p00571 | C++ | Runtime Error | #include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
struct Info {
Info(ll arg_size, ll arg_value) {
size = arg_size;
value = arg_value;
}
ll size, value;
bool operator<(const struct Info &arg) const { return size < arg.size; }
};
vector<Info> info;
ll ruisekiwa[100001], minus_value[100001];
int main() {
int N;
scanf("%d", &N);
info.push_back(Info(0, 0));
ll size, value;
for (int i = 1; i <= N; i++) {
scanf("%lld %lld", &size, &value);
info.push_back(Info(size, value));
}
sort(info.begin(), info.end());
ruisekiwa[0] = 0;
minus_value[0] = 0;
for (int i = 1; i <= N; i++) {
ruisekiwa[i] = info[i].value;
ruisekiwa[i] += ruisekiwa[i - 1];
minus_value[i] = ruisekiwa[i - 1] - info[i].size;
}
for (int i = 2; i <= N; i++) {
minus_value[i] = min(minus_value[i], minus_value[i - 1]);
}
ll ans = -99999999999999999;
for (int i = N; i >= 1; i--) {
ans = max(ans, ruisekiwa[i] - info[i].size - minus_value[i]);
}
printf("%lld\n", ans);
return 0;
}
| #include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
struct Info {
Info(ll arg_size, ll arg_value) {
size = arg_size;
value = arg_value;
}
ll size, value;
bool operator<(const struct Info &arg) const { return size < arg.size; }
};
vector<Info> info;
ll ruisekiwa[500001], minus_value[500001];
int main() {
int N;
scanf("%d", &N);
info.push_back(Info(0, 0));
ll size, value;
for (int i = 1; i <= N; i++) {
scanf("%lld %lld", &size, &value);
info.push_back(Info(size, value));
}
sort(info.begin(), info.end());
ruisekiwa[0] = 0;
minus_value[0] = 0;
for (int i = 1; i <= N; i++) {
ruisekiwa[i] = info[i].value;
ruisekiwa[i] += ruisekiwa[i - 1];
minus_value[i] = ruisekiwa[i - 1] - info[i].size;
}
for (int i = 2; i <= N; i++) {
minus_value[i] = min(minus_value[i], minus_value[i - 1]);
}
ll ans = -99999999999999999;
for (int i = N; i >= 1; i--) {
ans = max(ans, ruisekiwa[i] - info[i].size - minus_value[i]);
}
printf("%lld\n", ans);
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p00572 | C++ | Runtime Error | #include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 3000
enum Type {
TATE,
YOKO,
NONE,
};
int H, W;
int dp[3][NUM + 1];
char base_map[NUM][NUM + 1];
bool rangeCheck(int row, int col) {
if (row >= 0 && row <= H - 1 && col >= 0 && col <= W - 1)
return true;
else {
return false;
}
}
int calc(int start_row, int start_col) {
int ret = 0;
for (int col = start_col; col <= W - 1; col++) {
dp[TATE][col] = 0;
dp[YOKO][col] = 0;
dp[NONE][col] = 0;
}
int row = start_row;
for (int col = start_col; col <= W - 1; col++) {
if (base_map[row][col] != 'G') {
if (col == start_col) {
// Do nothing
} else {
dp[NONE][col] =
max(dp[NONE][col - 1], max(dp[TATE][col - 1], dp[YOKO][col - 1]));
}
} else { // base_map[row][col] == 'G'
if (rangeCheck(row - 1, col) == true && base_map[row - 1][col] == 'R' &&
rangeCheck(row + 1, col) == true &&
base_map[row + 1][col] == 'W') { // 縦に作れる
if (col == start_col) {
dp[TATE][col] = 1;
} else {
dp[TATE][col] = max(dp[TATE][col - 1], dp[NONE][col - 1]) + 1;
}
ret = max(ret, dp[TATE][col]);
}
if (rangeCheck(row, col - 1) == true && base_map[row][col - 1] == 'R' &&
rangeCheck(row, col + 1) == true &&
base_map[row][col + 1] == 'W') { // 横に作れる
if (col == start_col) {
dp[YOKO][col] = 1;
} else {
dp[YOKO][col] = max(dp[YOKO][col - 1], dp[NONE][col - 1]) + 1;
}
ret = max(ret, dp[YOKO][col]);
}
// どちらも作らない
if (col == start_col) {
// Do nothing
} else {
dp[NONE][col] =
max(dp[NONE][col - 1], max(dp[TATE][col - 1], dp[YOKO][col - 1]));
}
}
row--;
}
return ret;
}
int main() {
scanf("%d %d", &H, &W);
for (int row = 0; row < H; row++) {
scanf("%s", base_map[row]);
}
int ans = 0;
for (int row = 1; row <= H - 1; row++) {
ans += calc(row, 0);
}
for (int col = 1; col <= W - 1; col++) {
ans += calc(H - 1, col);
}
printf("%d\n", ans);
return 0;
}
| #include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 3000
enum Type {
TATE,
YOKO,
NONE,
};
int H, W;
int dp[3][NUM + 1];
char base_map[NUM][NUM + 1];
bool rangeCheck(int row, int col) {
if (row >= 0 && row <= H - 1 && col >= 0 && col <= W - 1)
return true;
else {
return false;
}
}
int calc(int start_row, int start_col) {
int ret = 0;
for (int col = start_col; col <= W - 1; col++) {
dp[TATE][col] = 0;
dp[YOKO][col] = 0;
dp[NONE][col] = 0;
}
int row = start_row;
for (int col = start_col; col <= W - 1 && row >= 0; col++) {
if (base_map[row][col] != 'G') {
if (col == start_col) {
// Do nothing
} else {
dp[NONE][col] =
max(dp[NONE][col - 1], max(dp[TATE][col - 1], dp[YOKO][col - 1]));
}
} else { // base_map[row][col] == 'G'
if (rangeCheck(row - 1, col) == true && base_map[row - 1][col] == 'R' &&
rangeCheck(row + 1, col) == true &&
base_map[row + 1][col] == 'W') { // 縦に作れる
if (col == start_col) {
dp[TATE][col] = 1;
} else {
dp[TATE][col] = max(dp[TATE][col - 1], dp[NONE][col - 1]) + 1;
}
ret = max(ret, dp[TATE][col]);
}
if (rangeCheck(row, col - 1) == true && base_map[row][col - 1] == 'R' &&
rangeCheck(row, col + 1) == true &&
base_map[row][col + 1] == 'W') { // 横に作れる
if (col == start_col) {
dp[YOKO][col] = 1;
} else {
dp[YOKO][col] = max(dp[YOKO][col - 1], dp[NONE][col - 1]) + 1;
}
ret = max(ret, dp[YOKO][col]);
}
// どちらも作らない
if (col == start_col) {
// Do nothing
} else {
dp[NONE][col] =
max(dp[NONE][col - 1], max(dp[TATE][col - 1], dp[YOKO][col - 1]));
}
}
row--;
}
return ret;
}
int main() {
scanf("%d %d", &H, &W);
for (int row = 0; row < H; row++) {
scanf("%s", base_map[row]);
}
int ans = 0;
for (int row = 1; row <= H - 1; row++) {
ans += calc(row, 0);
}
for (int col = 1; col <= W - 1; col++) {
ans += calc(H - 1, col);
}
printf("%d\n", ans);
return 0;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p00586 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int a, b;
while (1) {
cin >> a >> b;
cout << a + b << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
cout << a + b << endl;
}
return 0;
} | replace | 5 | 7 | 5 | 6 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <cstdio>
using namespace std;
int main(int argc, const char *argv[]) {
// insert code here...
int a, b;
while (scanf("%d %d", &a, &b) != 0) {
printf("%d\n", a + b);
}
return 0;
} | #include <cstdio>
using namespace std;
int main(int argc, const char *argv[]) {
// insert code here...
int a, b;
while (scanf("%d %d", &a, &b) != EOF) {
printf("%d\n", a + b);
}
return 0;
} | replace | 6 | 7 | 6 | 7 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main(void) {
int a, b;
while (cin >> a >> b, a + b)
cout << a + b << endl;
} | #include <iostream>
using namespace std;
int main(void) {
int a, b;
while (cin >> a >> b)
cout << a + b << endl;
} | replace | 4 | 5 | 4 | 5 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <stdio.h>
int main() {
int a, b;
while (scanf("%d %d", &a, &b)) {
printf("%d\n", a + b);
}
return 0;
} | #include <stdio.h>
int main() {
int a, b;
while (scanf("%d %d", &a, &b) != EOF) {
printf("%d\n", a + b);
}
return 0;
} | replace | 4 | 5 | 4 | 5 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int a, b;
while (true) {
cin >> a >> b;
cout << a + b << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
cout << a + b << endl;
}
return 0;
} | replace | 5 | 7 | 5 | 6 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a, b;
while (scanf("%d %d", &a, &b)) {
for (int i = 0; i < b; i++)
a++;
cout << a << endl;
}
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
while (scanf("%d %d", &a, &b) == 2) {
cout << a + b << endl;
}
return 0;
} | replace | 6 | 11 | 6 | 9 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
while (1) {
int a, b;
std::cin >> a >> b;
std::cout << a + b << '\n';
}
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
int a, b;
while (std::cin >> a >> b) {
std::cout << a + b << '\n';
}
}
| replace | 6 | 9 | 6 | 8 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int a, b;
int main() {
while (cin >> a >> b) {
int c = 0;
while (c < 100000000 && c + c / 2 != 2)
c++;
cout << a + b + c % 9 - 1 << endl;
}
} | #include <cmath>
#include <iostream>
using namespace std;
int a, b;
int main() {
while (cin >> a >> b) {
int c = 0;
while (c < 10000000 && c + c / 2 != 2)
c++;
cout << a + b + c % 9 - 1 << endl;
}
} | replace | 9 | 10 | 9 | 10 | TLE | |
p00586 | C++ | Time Limit Exceeded | #include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
stack<int> st; // スタックを宣言+初期化
int a, b, c, d, e, num;
int i, j, k;
int arr[100];
int arr2[100][100];
char crr[100];
char crr2[100][100];
string str;
stack<int> istk; // 整数値を格納するスタックを宣言
stack<string> sstk; // 文字列を格納するスタックを宣言
queue<int> ique; // 整数値を格納するキューを宣言
queue<string> sque; // 文字列を格納するキューを宣言
while (1) {
cin >> num;
cin >> a;
if (a == EOF || num == EOF)
break;
cout << a + num << endl;
}
return 0;
} | #include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
stack<int> st; // スタックを宣言+初期化
int a, b, c, d, e, num;
int i, j, k;
int arr[100];
int arr2[100][100];
char crr[100];
char crr2[100][100];
string str;
stack<int> istk; // 整数値を格納するスタックを宣言
stack<string> sstk; // 文字列を格納するスタックを宣言
queue<int> ique; // 整数値を格納するキューを宣言
queue<string> sque; // 文字列を格納するキューを宣言
while (scanf("%d %d", &a, &num) == 2) {
cout << a + num << endl;
}
return 0;
} | replace | 27 | 35 | 27 | 28 | TLE | |
p00586 | Python | Time Limit Exceeded | x = input()
while x:
a, b = x.split(" ")
print(int(a) + int(b))
| import sys
for line in sys.stdin:
if line == None or line == "/n":
break
a, b = line.split(" ")
print(int(a) + int(b))
| replace | 0 | 3 | 0 | 6 | TLE | |
p00587 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
struct Node {
Node *ch[2];
Node() { ch[0] = ch[1] = NULL; }
};
void build(Node *node, const string &s, int &i) {
if (s[i] == '(') {
i++; // (
node->ch[0] = new Node();
build(node->ch[0], s, i);
i++; // ,
node->ch[1] = new Node();
build(node->ch[1], s, i);
i++; // )
}
}
void print(Node *node) {
if (node == NULL || (node->ch[0] == NULL && node->ch[1] == NULL))
return;
cout << "(";
print(node->ch[0]);
cout << ",";
print(node->ch[1]);
cout << ")";
}
void erase(Node *node) {
for (int i = 0; i < 2; i++)
if (node->ch[i])
erase(node->ch[i]);
delete node;
}
void Intersection(Node *res, Node *a, Node *b) {
for (int i = 0; i < 2; i++)
if (a && a->ch[i] && b && b->ch[i]) {
res->ch[i] = new Node();
Intersection(res->ch[i], a->ch[i], b->ch[i]);
}
}
void Union(Node *res, Node *a, Node *b) {
for (int i = 0; i < 2; i++)
if ((a && a->ch[i]) || (b && b->ch[i])) {
res->ch[i] = new Node();
Union(res->ch[i], a->ch[i], b->ch[i]);
}
}
int main() {
for (string cmd, A, B; cin >> cmd >> A >> B;) {
Node *roota = new Node();
Node *rootb = new Node();
Node *rootc = new Node();
int i = 0;
build(roota, A, i);
i = 0;
build(rootb, B, i);
if (cmd[0] == 'i')
Intersection(rootc, roota, rootb);
else
Union(rootc, roota, rootb);
print(rootc);
cout << endl;
erase(roota);
erase(rootb);
erase(rootc);
}
} | #include <iostream>
#include <vector>
using namespace std;
struct Node {
Node *ch[2];
Node() { ch[0] = ch[1] = NULL; }
};
void build(Node *node, const string &s, int &i) {
if (s[i] == '(') {
i++; // (
node->ch[0] = new Node();
build(node->ch[0], s, i);
i++; // ,
node->ch[1] = new Node();
build(node->ch[1], s, i);
i++; // )
}
}
void print(Node *node) {
if (node == NULL || (node->ch[0] == NULL && node->ch[1] == NULL))
return;
cout << "(";
print(node->ch[0]);
cout << ",";
print(node->ch[1]);
cout << ")";
}
void erase(Node *node) {
for (int i = 0; i < 2; i++)
if (node->ch[i])
erase(node->ch[i]);
delete node;
}
void Intersection(Node *res, Node *a, Node *b) {
for (int i = 0; i < 2; i++)
if (a && a->ch[i] && b && b->ch[i]) {
res->ch[i] = new Node();
Intersection(res->ch[i], a->ch[i], b->ch[i]);
}
}
void Union(Node *res, Node *a, Node *b) {
for (int i = 0; i < 2; i++)
if ((a && a->ch[i]) || (b && b->ch[i])) {
res->ch[i] = new Node();
Union(res->ch[i], (a ? a->ch[i] : NULL), (b ? b->ch[i] : NULL));
}
}
int main() {
for (string cmd, A, B; cin >> cmd >> A >> B;) {
Node *roota = new Node();
Node *rootb = new Node();
Node *rootc = new Node();
int i = 0;
build(roota, A, i);
i = 0;
build(rootb, B, i);
if (cmd[0] == 'i')
Intersection(rootc, roota, rootb);
else
Union(rootc, roota, rootb);
print(rootc);
cout << endl;
erase(roota);
erase(rootb);
erase(rootc);
}
} | replace | 50 | 51 | 50 | 51 | 0 | |
p00587 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <limits.h>
#include <queue>
#include <string>
// typedef pair<int,int> P;
using namespace std;
const int INF = INT_MAX / 3;
const int N = 1000;
int heap[N];
string output;
void parse(string &s, int id) {
// cout<<s<<":"<<id<<endl;
if (s.empty())
return;
heap[id]++;
if (s == ",")
return;
int cnt = 0;
for (int i = 1; i < s.length() - 1; i++) {
if (s[i] == '(')
cnt++;
if (s[i] == ')')
cnt--;
if (s[i] == ',' && cnt == 0) {
string sub1 = s.substr(1, i - 1);
string sub2 = s.substr(i + 1, s.length() - i - 2);
if (i - 1 >= 0)
parse(sub1, 2 * id + 1);
if (s.length() - i - 2 >= 0)
parse(sub2, 2 * id + 2);
break;
}
}
return;
}
void out(int th, int id) {
output.push_back('(');
int ch1 = 0, ch2 = 0; // n of string of each child
if (heap[id] > th && heap[2 * id + 1] > th) {
out(th, 2 * id + 1);
}
output.push_back(',');
if (heap[id] > th && heap[2 * id + 2] > th) {
out(th, 2 * id + 2);
}
output.push_back(')');
return;
}
void print() {
for (int i = 0; i < N; i++)
cout << "[" << i << "]" << heap[i] << endl;
}
void solve(string cmd, string &s1, string &s2) {
fill(heap, heap + N, 0);
output.clear();
// cout<<output<<endl;
parse(s1, 0);
parse(s2, 0);
int th = -1;
if (cmd == "u")
th = 0;
if (cmd == "i")
th = 1;
out(th, 0);
cout << output << endl;
}
int main() {
string cmd, s1, s2;
int i = 0;
while (cin >> cmd >> s1 >> s2) {
solve(cmd, s1, s2);
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <limits.h>
#include <queue>
#include <string>
// typedef pair<int,int> P;
using namespace std;
const int INF = INT_MAX / 3;
const int N = 1000;
int heap[N];
string output;
void parse(string &s, int id) {
// cout<<s<<":"<<id<<endl;
if (s.empty())
return;
heap[id]++;
if (s == "(,)")
return;
if (id >= N)
return;
int cnt = 0;
for (int i = 1; i < s.length() - 1; i++) {
if (s[i] == '(')
cnt++;
if (s[i] == ')')
cnt--;
if (s[i] == ',' && cnt == 0) {
string sub1 = s.substr(1, i - 1);
string sub2 = s.substr(i + 1, s.length() - i - 2);
if (i - 1 >= 0)
parse(sub1, 2 * id + 1);
if (s.length() - i - 2 >= 0)
parse(sub2, 2 * id + 2);
break;
}
}
return;
}
void out(int th, int id) {
output.push_back('(');
int ch1 = 0, ch2 = 0; // n of string of each child
if (heap[id] > th && heap[2 * id + 1] > th) {
out(th, 2 * id + 1);
}
output.push_back(',');
if (heap[id] > th && heap[2 * id + 2] > th) {
out(th, 2 * id + 2);
}
output.push_back(')');
return;
}
void print() {
for (int i = 0; i < N; i++)
cout << "[" << i << "]" << heap[i] << endl;
}
void solve(string cmd, string &s1, string &s2) {
fill(heap, heap + N, 0);
output.clear();
// cout<<output<<endl;
parse(s1, 0);
parse(s2, 0);
int th = -1;
if (cmd == "u")
th = 0;
if (cmd == "i")
th = 1;
out(th, 0);
cout << output << endl;
}
int main() {
string cmd, s1, s2;
int i = 0;
while (cin >> cmd >> s1 >> s2) {
solve(cmd, s1, s2);
}
return 0;
} | replace | 23 | 24 | 23 | 26 | 0 | |
p00588 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int T, N;
cin >> T;
while (T--) {
cin >> N;
int book[128] = {0};
for (int k = 0; k < 2; k++) {
string str;
char c;
for (int i = 0; i < 2 * N; i++) {
cin >> c;
str += c;
}
str = "N" + str + "N";
for (int i = 0; i < N + 1; i++) {
if (str[i * 2] == 'Y' || str[i * 2 + 1] == 'Y') {
book[i] |= (1 << k);
}
}
}
int a = 0, b = 1, na, nb;
for (int i = 0; i < N + 1; i++) {
switch (book[i]) {
case 0:
na = a;
nb = b;
break;
case 1:
na = min(a + 1, b + 1);
nb = min(b + 1, a + 1);
break;
case 2:
na = min(a + 3, b + 2);
nb = min(b + 1, a + 2);
break;
case 3:
na = min(a + 3, b + 2);
nb = min(b + 2, a + 2);
break;
}
a = na + 1;
b = nb + 1;
}
cout << a - 1 << endl;
}
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int T, N;
cin >> T;
while (T--) {
cin >> N;
int book[10005] = {0};
for (int k = 0; k < 2; k++) {
string str;
char c;
for (int i = 0; i < 2 * N; i++) {
cin >> c;
str += c;
}
str = "N" + str + "N";
for (int i = 0; i < N + 1; i++) {
if (str[i * 2] == 'Y' || str[i * 2 + 1] == 'Y') {
book[i] |= (1 << k);
}
}
}
int a = 0, b = 1, na, nb;
for (int i = 0; i < N + 1; i++) {
switch (book[i]) {
case 0:
na = a;
nb = b;
break;
case 1:
na = min(a + 1, b + 1);
nb = min(b + 1, a + 1);
break;
case 2:
na = min(a + 3, b + 2);
nb = min(b + 1, a + 2);
break;
case 3:
na = min(a + 3, b + 2);
nb = min(b + 2, a + 2);
break;
}
a = na + 1;
b = nb + 1;
}
cout << a - 1 << endl;
}
} | replace | 9 | 10 | 9 | 10 | 0 | |
p00590 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
#define MAX 10001
using namespace std;
bool prime[MAX];
void isPrime() {}
int main(void) {
// isPrime();
fill(prime, prime + MAX, true);
prime[0] = prime[1] = false;
for (int i = 0; i < MAX; i++)
if (prime[i])
for (int j = i + i; j < MAX; j += i)
prime[j] = false;
int n;
while (1) {
cin >> n;
int cnt = 0;
for (int i = 1; i <= n; i++)
if (prime[i] * prime[n - i + 1])
cnt++;
cout << cnt << endl;
}
} | #include <iostream>
#include <vector>
#define MAX 10001
using namespace std;
bool prime[MAX];
void isPrime() {}
int main(void) {
// isPrime();
fill(prime, prime + MAX, true);
prime[0] = prime[1] = false;
for (int i = 0; i < MAX; i++)
if (prime[i])
for (int j = i + i; j < MAX; j += i)
prime[j] = false;
int n;
while (1) {
cin >> n;
if (cin.eof())
break;
int cnt = 0;
for (int i = 1; i <= n; i++)
if (prime[i] * prime[n - i + 1])
cnt++;
cout << cnt << endl;
}
} | insert | 19 | 19 | 19 | 21 | TLE | |
p00590 | C++ | Runtime Error | #include <iostream>
#define LEN 10000
using namespace std;
int prime_pair(int N);
int is_prime(int p);
int prime_list(int MAX);
int prime[LEN];
int main(void) {
int input;
int j = 0;
prime_list(LEN);
while (cin >> input) {
cout << prime_pair(input) << endl;
}
return 0;
}
int prime_list(int MAX) {
int i = 0;
int j = 0;
int flag = 1;
prime[0] = 2;
for (i = 2; i < MAX; i++) {
while (prime[j] != 0) {
if (i % prime[j] == 0) {
flag = 0;
}
j++;
}
if (flag) {
prime[j] = i;
}
flag = 1;
j = 0;
}
return 0;
}
int prime_pair(int N) {
int count = 0;
int i = 1;
if (is_prime(2) && is_prime(N - 2 + 1))
count++;
while (prime[i] < N) {
if (is_prime(N - prime[i] + 1))
count++;
i++;
}
return count;
}
int is_prime(int p) {
int flag = 0;
int i = 0;
while ((prime[i] != 0) && (i < p)) {
if (p == prime[i]) {
flag = 1;
break;
}
i++;
}
return flag;
} | #include <iostream>
#define LEN 10000
using namespace std;
int prime_pair(int N);
int is_prime(int p);
int prime_list(int MAX);
int prime[LEN];
int main(void) {
int input;
int j = 0;
prime_list(LEN);
while (cin >> input) {
cout << prime_pair(input) << endl;
}
return 0;
}
int prime_list(int MAX) {
int i = 0;
int j = 0;
int flag = 1;
prime[0] = 2;
for (i = 2; i < MAX; i++) {
while (prime[j] != 0) {
if (i % prime[j] == 0) {
flag = 0;
}
j++;
}
if (flag) {
prime[j] = i;
}
flag = 1;
j = 0;
}
return 0;
}
int prime_pair(int N) {
int count = 0;
int i = 0;
while ((prime[i] < N) && (prime[i] != 0)) {
if (is_prime(N - prime[i] + 1))
count++;
i++;
}
return count;
}
int is_prime(int p) {
int flag = 0;
int i = 0;
while ((prime[i] != 0) && (i < p)) {
if (p == prime[i]) {
flag = 1;
break;
}
i++;
}
return flag;
} | replace | 42 | 46 | 42 | 44 | 0 | |
p00590 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool is_prime(int p) {
if (p <= 1)
return false;
if (p == 2)
return true;
if (!(p & 1))
return false;
for (int x = 3; x <= sqrt(p); ++x)
if (!(p % x))
return false;
return true;
}
int main() {
bool primes[10002];
memset(primes, 0, sizeof(primes));
for (int x = 2; x <= 10000; ++x)
if (is_prime(x))
primes[x] = true;
int n;
while (scanf("%d", &n) == 1, n) {
int c = 0;
int l = n / 2;
if (n % 2 == 1) {
++l;
if (primes[l])
--c;
}
for (int x = 1; x <= l; ++x) {
if (primes[x] && primes[n - x + 1])
c += 2;
}
cout << c << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool is_prime(int p) {
if (p <= 1)
return false;
if (p == 2)
return true;
if (!(p & 1))
return false;
for (int x = 3; x <= sqrt(p); ++x)
if (!(p % x))
return false;
return true;
}
int main() {
bool primes[10002];
memset(primes, 0, sizeof(primes));
for (int x = 2; x <= 10000; ++x)
if (is_prime(x))
primes[x] = true;
int n;
while (scanf("%d", &n) == 1) {
int c = 0;
int l = n / 2;
if (n % 2 == 1) {
++l;
if (primes[l])
--c;
}
for (int x = 1; x <= l; ++x) {
if (primes[x] && primes[n - x + 1])
c += 2;
}
cout << c << endl;
}
return 0;
} | replace | 39 | 40 | 39 | 40 | TLE | |
p00590 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x) {
ll i;
if (x < 2)
return 0;
else if (x == 2)
return 1;
if (x % 2 == 0)
return 0;
for (i = 3; i * i <= x; i += 2) {
if (x % i == 0)
return 0;
}
return 1;
}
int main() {
int N;
while (cin >> N, N) {
int cnt = 0;
for (int i = 1; i <= N; i++) {
if (prime(i) && prime(N - i + 1))
cnt++;
}
cout << cnt << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x) {
ll i;
if (x < 2)
return 0;
else if (x == 2)
return 1;
if (x % 2 == 0)
return 0;
for (i = 3; i * i <= x; i += 2) {
if (x % i == 0)
return 0;
}
return 1;
}
int main() {
int N;
while (cin >> N) {
int cnt = 0;
for (int i = 1; i <= N; i++) {
if (prime(i) && prime(N - i + 1))
cnt++;
}
cout << cnt << endl;
}
}
| replace | 19 | 20 | 19 | 20 | TLE | |
p00591 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
// #define int long long
#define DEBUG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o) \
if (DEBUG) { \
cerr << #o << " " << o << endl; \
}
#define dumpc(o) \
if (DEBUG) { \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
signed main() {
int a[110][110] = {};
int r[110], c[110];
for (int n; cin >> n && n;) {
rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
memset(r, 0x3f, sizeof(r));
memset(c, 0, sizeof(c));
dumpc(r);
dumpc(c);
rep(i, 0, n) rep(j, 0, n) {
r[i] = min(r[i], a[i][j]);
c[j] = max(c[j], a[i][j]);
}
bool f = true;
rep(i, 0, n) rep(j, 0, n) {
if (f && r[i] == a[i][j] && c[j] == a[i][j]) {
cout << a[i][j] << endl;
f = false;
}
}
if (f)
cout << 0 << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
// #define int long long
#define DEBUG 0
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o) \
if (DEBUG) { \
cerr << #o << " " << o << endl; \
}
#define dumpc(o) \
if (DEBUG) { \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
signed main() {
int a[110][110] = {};
int r[110], c[110];
for (int n; cin >> n && n;) {
rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
memset(r, 0x3f, sizeof(r));
memset(c, 0, sizeof(c));
dumpc(r);
dumpc(c);
rep(i, 0, n) rep(j, 0, n) {
r[i] = min(r[i], a[i][j]);
c[j] = max(c[j], a[i][j]);
}
bool f = true;
rep(i, 0, n) rep(j, 0, n) {
if (f && r[i] == a[i][j] && c[j] == a[i][j]) {
cout << a[i][j] << endl;
f = false;
}
}
if (f)
cout << 0 << endl;
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | r 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567
c 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
r 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567
c 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
p00594 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int getInt() {
int ret = 0, c;
c = getchar();
while (!isdigit(c))
c = getchar();
while (isdigit(c)) {
ret *= 10;
ret += c - '0';
c = getchar();
}
return ret;
}
const int mod = 109;
int cnt[mod];
int main() {
while (int n = getInt()) {
int ans = -1;
const int n2 = n / 2;
for (int i = 0; i < mod; i++) {
cnt[i] = 0;
}
for (int i = 0; i < n; i++) {
int a = getInt();
int m = a % mod;
if (++cnt[m] > n2) {
ans = a;
if (i != n - 1)
while (getchar() != '\n')
;
}
}
if (ans == -1)
puts("NO COLOR");
else
printf("%d\n", ans);
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int getInt() {
int ret = 0, c;
c = getchar();
while (!isdigit(c))
c = getchar();
while (isdigit(c)) {
ret *= 10;
ret += c - '0';
c = getchar();
}
return ret;
}
const int mod = 109;
int cnt[mod];
int main() {
while (int n = getInt()) {
int ans = -1;
const int n2 = n / 2;
for (int i = 0; i < mod; i++) {
cnt[i] = 0;
}
for (int i = 0; i < n; i++) {
int a = getInt();
int m = a % mod;
if (++cnt[m] > n2) {
ans = a;
for (++i; i < n; i++)
getInt();
}
}
if (ans == -1)
puts("NO COLOR");
else
printf("%d\n", ans);
}
return 0;
} | replace | 36 | 39 | 36 | 38 | TLE | |
p00594 | C++ | Time Limit Exceeded | #include <stdio.h>
int main() {
int n, now, last, a[1000000];
while (1) {
scanf("%d%d", &n, &a[0]);
now = 1;
last = a[0];
for (int i = 1; i < n; i++) {
scanf("%d", &a[i]);
if (now == 0) {
last = a[i];
now++;
} else if (last != a[i]) {
now--;
} else
now++;
}
now = 0;
for (int i = 0; i < n; i++) {
if (a[i] == last)
now++;
}
if (now > n / 2)
printf("%d\n", last);
else
printf("NO COLOR\n");
}
} | #include <stdio.h>
int main() {
int n, now, last, a[1000000];
while (1) {
scanf("%d%d", &n, &a[0]);
if (n == 0)
return 0;
now = 1;
last = a[0];
for (int i = 1; i < n; i++) {
scanf("%d", &a[i]);
if (now == 0) {
last = a[i];
now++;
} else if (last != a[i]) {
now--;
} else
now++;
}
now = 0;
for (int i = 0; i < n; i++) {
if (a[i] == last)
now++;
}
if (now > n / 2)
printf("%d\n", last);
else
printf("NO COLOR\n");
}
} | insert | 5 | 5 | 5 | 7 | TLE | |
p00594 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
while (1) {
cin >> a;
map<int, int> mp;
int ans = -1;
for (int i = 0; i < a; i++) {
cin >> b;
mp[b]++;
if (mp[b] > (a / 2))
ans = b;
}
if (ans == -1)
cout << "NO COLOR" << endl;
else
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
while (1) {
cin >> a;
if (a == 0)
break;
map<int, int> mp;
int ans = -1;
for (int i = 0; i < a; i++) {
cin >> b;
mp[b]++;
if (mp[b] > (a / 2))
ans = b;
}
if (ans == -1)
cout << "NO COLOR" << endl;
else
cout << ans << endl;
}
return 0;
} | insert | 8 | 8 | 8 | 10 | TLE | |
p00595 | C++ | Runtime Error | #include <iostream>
using namespace std;
int gcm(int a, int b) {
if (a > b) {
int tmp = a;
a = b;
b = tmp;
cerr << 'a' << endl;
}
for (int i = 1;; ++i) {
if (a % i == 0 and b % (a / i) == 0) {
return a / i;
}
}
}
int main(void) {
int a, b;
while (cin >> a >> b) {
cout << gcm(a, b) << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int gcm(int a, int b) {
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
for (int i = 1;; ++i) {
if (a % i == 0 and b % (a / i) == 0) {
return a / i;
}
}
}
int main(void) {
int a, b;
while (cin >> a >> b) {
cout << gcm(a, b) << endl;
}
return 0;
} | delete | 8 | 9 | 8 | 8 | 0 | a
|
p00595 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int pgcd(int a, int b) { return b == 0 ? a : pgcd(b % a, a); }
int main() {
int a, b;
while (cin >> a >> b) {
cout << pgcd(a, b) << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int pgcd(int a, int b) { return a == 0 ? b : pgcd(b % a, a); }
int main() {
int a, b;
while (cin >> a >> b) {
cout << pgcd(a, b) << endl;
}
return 0;
} | replace | 7 | 8 | 7 | 8 | -8 | |
p00595 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
using namespace std;
unsigned int euclid(unsigned int a, unsigned int b) {
if (b == 0)
return a;
return euclid(b, a % b);
}
int main(void) {
unsigned int a, b;
while (scanf("%u %u", &a, &b) != 0)
cout << euclid(a, b) << endl;
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
unsigned int euclid(unsigned int a, unsigned int b) {
if (b == 0)
return a;
return euclid(b, a % b);
}
int main(void) {
unsigned int a, b;
while (fscanf(stdin, "%u %u", &a, &b) != EOF)
cout << euclid(a, b) << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p00595 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long long int n, m, a, b, c;
while (cin >> n >> m) {
a = max(n, m);
b = min(n, m);
c = a % b;
a = b;
b = c;
while (a % b != 0) {
c = a % b;
a = b;
b = c;
}
cout << b << endl;
}
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long long int n, m, a, b, c;
while (cin >> n >> m) {
a = max(n, m);
b = min(n, m);
while (b != 0 && a % b != 0) {
c = a % b;
a = b;
b = c;
}
cout << b << endl;
}
} | replace | 11 | 15 | 11 | 13 | 0 | |
p00595 | C++ | Time Limit Exceeded | #include <iostream>
int eucgcd(int m, int n) {
int p = m % n;
while (p > 0) {
m = n;
n = p;
p = m % n;
}
return n;
}
int main() {
int m, n;
while (std::cin >> m >> n, (m != EOF && n != EOF)) {
if (m >= n)
std::cout << eucgcd(m, n) << std::endl;
else
std::cout << eucgcd(n, m) << std::endl;
}
return 0;
} | #include <iostream>
int eucgcd(int m, int n) {
int p = m % n;
while (p > 0) {
m = n;
n = p;
p = m % n;
}
return n;
}
int main() {
int m, n;
while (std::cin >> m >> n && m && n) {
if (m >= n)
std::cout << eucgcd(m, n) << std::endl;
else
std::cout << eucgcd(n, m) << std::endl;
}
return 0;
} | replace | 17 | 18 | 17 | 18 | TLE | |
p00595 | C++ | Time Limit Exceeded | #include <stdio.h>
int gcd(int x, int y) { return x < y ? gcd(y, x) : y ? gcd(y, x - y) : x; }
int main(void) {
int x, y;
while (scanf("%d", &x), x != EOF) {
scanf("%d", &y);
printf("%d\n", gcd(x, y));
}
return 0;
} | #include <stdio.h>
int gcd(int x, int y) { return x < y ? gcd(y, x) : y ? gcd(y, x - y) : x; }
int main(void) {
int x, y;
while (scanf("%d%d", &x, &y) != EOF) {
printf("%d\n", gcd(x, y));
}
return 0;
} | replace | 7 | 9 | 7 | 8 | TLE | |
p00595 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
using namespace std;
void change(int *, int *);
int main(void) {
int x, y;
while (1) {
scanf("%d %d", &x, &y);
if (x == 0 && y == 0)
break;
if (x < y)
change(&x, &y);
while (y) {
x %= y;
change(&x, &y);
}
cout << x << endl;
}
return 0;
}
void change(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
} | #include <cstdio>
#include <iostream>
using namespace std;
void change(int *, int *);
int main(void) {
int x, y;
while (scanf("%d %d", &x, &y) != EOF) {
if (x == 0 && y == 0)
break;
if (x < y)
change(&x, &y);
while (y) {
x %= y;
change(&x, &y);
}
cout << x << endl;
}
return 0;
}
void change(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
} | replace | 10 | 12 | 10 | 11 | TLE | |
p00596 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> void debug(T begin, T end) {
for (T i = begin; i != end; ++i)
cerr << *i << " ";
cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int V = 7;
typedef vector<int> node;
bool judge(vector<node> &G) {
bool exist[V] = {};
REP(i, V) exist[i] = (G[i].size() > 0);
int s = -1;
REP(i, V) if (exist[i]) s = i;
assert(s != -1);
queue<int> que;
bool used[V] = {};
que.push(s);
used[s] = true;
while (!que.empty()) {
int u = que.front();
que.pop();
REP(i, G[u].size()) {
int v = G[u][i];
if (used[v])
continue;
used[v] = true;
que.push(v);
}
}
REP(i, V) if (exist[i] && !used[i]) return false;
int odd = 0;
REP(i, V) if (G[i].size() % 2 == 1) odd++;
return (odd == 2 || odd == 0);
}
int main() {
int N;
while (cin >> N && N) {
vector<node> G(6);
REP(i, N) {
string s;
cin >> s;
int u = s[0] - '0';
int v = s[1] - '0';
G[u].push_back(v);
G[v].push_back(u);
}
if (judge(G))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> void debug(T begin, T end) {
for (T i = begin; i != end; ++i)
cerr << *i << " ";
cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
return (x >= 0 && y >= 0 && x < W && y < H);
}
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int V = 7;
typedef vector<int> node;
bool judge(vector<node> &G) {
bool exist[V] = {};
REP(i, V) exist[i] = (G[i].size() > 0);
int s = -1;
REP(i, V) if (exist[i]) s = i;
assert(s != -1);
queue<int> que;
bool used[V] = {};
que.push(s);
used[s] = true;
while (!que.empty()) {
int u = que.front();
que.pop();
REP(i, G[u].size()) {
int v = G[u][i];
if (used[v])
continue;
used[v] = true;
que.push(v);
}
}
REP(i, V) if (exist[i] && !used[i]) return false;
int odd = 0;
REP(i, V) if (G[i].size() % 2 == 1) odd++;
return (odd == 2 || odd == 0);
}
int main() {
int N;
while (cin >> N && N) {
vector<node> G(7);
REP(i, N) {
string s;
cin >> s;
int u = s[0] - '0';
int v = s[1] - '0';
G[u].push_back(v);
G[v].push_back(u);
}
if (judge(G))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 71 | 72 | 71 | 72 | -11 | |
p00597 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
int out[40] = {1, 2, 5, 8};
loop(i, 4, 40) out[i] = out[i - 2] + (out[i - 2] - out[i - 4]) * 3;
int n;
while (cin >> n, n)
cout << out[n - 1] << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
int out[40] = {1, 2, 5, 8};
loop(i, 4, 40) out[i] = out[i - 2] + (out[i - 2] - out[i - 4]) * 3;
int n;
while (cin >> n)
cout << out[n - 1] << endl;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p00597 | C++ | Runtime Error | #include <iostream>
using namespace std;
int n, f[33];
int main() {
f[1] = 1, f[2] = 2, f[3] = 5;
for (int i = 4; i <= 30; i++) {
if (i & 1) {
f[i] = 4;
for (int j = 1; j < i / 2; j++)
f[i] *= 3;
f[i] += f[i - 2];
} else {
f[i] = 1;
for (int j = 1; j < i / 2; i++)
f[i] *= 3;
f[i] += f[i - 1];
}
}
while (cin >> n) {
cout << f[n] << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int n, f[33];
int main() {
f[1] = 1, f[2] = 2, f[3] = 5;
for (int i = 4; i <= 30; i++) {
if (i & 1) {
f[i] = 4;
for (int j = 1; j < i / 2; j++)
f[i] *= 3;
f[i] += f[i - 2];
} else {
f[i] = 1;
for (int j = 1; j < i / 2; j++)
f[i] *= 3;
f[i] += f[i - 1];
}
}
while (cin >> n) {
cout << f[n] << endl;
}
return 0;
} | replace | 13 | 14 | 13 | 14 | -11 | |
p00598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> V;
V A[10], U;
string S;
V Union(V a, V b) {
for (int i = 0; i < (int)b.size(); i++)
a.push_back(b[i]);
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
return a;
}
V Inter(V a, V b) {
V res;
int n = a.size(), m = b.size();
for (int i = 0; i < n; i++) {
int flg = 0;
for (int j = 0; j < m; j++)
flg |= a[i] == b[j];
if (flg)
res.push_back(a[i]);
}
sort(res.begin(), res.end());
return res;
}
V Diff(V a, V b) {
V res;
int n = a.size();
int m = b.size();
for (int i = 0; i < n; i++) {
int flg = 1;
for (int j = 0; j < m; j++)
flg &= a[i] != b[j];
if (flg)
res.push_back(a[i]);
}
sort(res.begin(), res.end());
return res;
}
V Sdiff(V a, V b) { return Union(Diff(a, b), Diff(b, a)); }
V Comp(V a) {
V res;
int n = U.size(), m = a.size();
for (int i = 0; i < n; i++) {
int flg = 1;
for (int j = 0; j < m; j++)
flg &= U[i] != a[j];
if (flg)
res.push_back(U[i]);
}
sort(res.begin(), res.end());
return res;
}
int p;
V bnf();
V getV() {
char ch = S[p];
V res;
if (ch == '(')
p++, res = bnf(), p++;
else if (isupper(ch))
p++, res = A[ch - 'A'];
else if (ch == 'c')
p++, res = Comp(getV());
else
assert(isupper(ch));
return res;
}
V bnf() {
V res = getV();
while (1) {
char ch = S[p];
if (ch == '(')
p++, res = bnf(), p++;
else if (ch == 'c')
p++, res = Comp(getV());
else if (ch == 'u')
p++, res = Union(res, getV());
else if (ch == 'i')
p++, res = Inter(res, getV());
else if (ch == 'd')
p++, res = Diff(res, getV());
else if (ch == 's')
p++, res = Sdiff(res, getV());
else if (p < S.size() && ch != ')')
assert(ch == ')');
else
break;
}
return res;
}
int main() {
while (1) {
U.clear();
while (1) {
char ch;
assert('A' <= ch && ch <= 'E');
int n;
if (!(cin >> ch >> n))
exit(0);
if (ch == 'R' && n == 0)
break;
int idx = ch - 'A';
A[idx].resize(n);
for (int i = 0; i < n; i++)
cin >> A[idx][i], U.push_back(A[idx][i]);
sort(A[idx].begin(), A[idx].end());
A[idx].erase(unique(A[idx].begin(), A[idx].end()), A[idx].end());
}
sort(U.begin(), U.end());
U.erase(unique(U.begin(), U.end()), U.end());
cin >> S;
p = 0;
V ans = bnf();
for (int i = 0; i < ans.size(); i++) {
if (i)
cout << " ";
cout << ans[i];
}
if (ans.size() == 0)
cout << "NULL";
cout << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> V;
V A[10], U;
string S;
V Union(V a, V b) {
for (int i = 0; i < (int)b.size(); i++)
a.push_back(b[i]);
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
return a;
}
V Inter(V a, V b) {
V res;
int n = a.size(), m = b.size();
for (int i = 0; i < n; i++) {
int flg = 0;
for (int j = 0; j < m; j++)
flg |= a[i] == b[j];
if (flg)
res.push_back(a[i]);
}
sort(res.begin(), res.end());
return res;
}
V Diff(V a, V b) {
V res;
int n = a.size();
int m = b.size();
for (int i = 0; i < n; i++) {
int flg = 1;
for (int j = 0; j < m; j++)
flg &= a[i] != b[j];
if (flg)
res.push_back(a[i]);
}
sort(res.begin(), res.end());
return res;
}
V Sdiff(V a, V b) { return Union(Diff(a, b), Diff(b, a)); }
V Comp(V a) {
V res;
int n = U.size(), m = a.size();
for (int i = 0; i < n; i++) {
int flg = 1;
for (int j = 0; j < m; j++)
flg &= U[i] != a[j];
if (flg)
res.push_back(U[i]);
}
sort(res.begin(), res.end());
return res;
}
int p;
V bnf();
V getV() {
char ch = S[p];
V res;
if (ch == '(')
p++, res = bnf(), p++;
else if (isupper(ch))
p++, res = A[ch - 'A'];
else if (ch == 'c')
p++, res = Comp(getV());
else
assert(isupper(ch));
return res;
}
V bnf() {
V res = getV();
while (1) {
char ch = S[p];
if (ch == '(')
p++, res = bnf(), p++;
else if (ch == 'c')
p++, res = Comp(getV());
else if (ch == 'u')
p++, res = Union(res, getV());
else if (ch == 'i')
p++, res = Inter(res, getV());
else if (ch == 'd')
p++, res = Diff(res, getV());
else if (ch == 's')
p++, res = Sdiff(res, getV());
else if (p < S.size() && ch != ')')
assert(ch == ')');
else
break;
}
return res;
}
int main() {
while (1) {
U.clear();
while (1) {
char ch;
int n;
if (!(cin >> ch >> n))
exit(0);
if (ch == 'R' && n == 0)
break;
int idx = ch - 'A';
A[idx].resize(n);
for (int i = 0; i < n; i++)
cin >> A[idx][i], U.push_back(A[idx][i]);
sort(A[idx].begin(), A[idx].end());
A[idx].erase(unique(A[idx].begin(), A[idx].end()), A[idx].end());
}
sort(U.begin(), U.end());
U.erase(unique(U.begin(), U.end()), U.end());
cin >> S;
p = 0;
V ans = bnf();
for (int i = 0; i < ans.size(); i++) {
if (i)
cout << " ";
cout << ans[i];
}
if (ans.size() == 0)
cout << "NULL";
cout << endl;
}
return 0;
} | delete | 107 | 108 | 107 | 107 | -6 | a7fec1d8-f7f0-4f97-a6c4-7d85e2638645.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00598/C++/s320133090.cpp:89: int main(): Assertion `'A'<=ch&&ch<='E'' failed.
|
p00600 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define foreach(itr, c) \
for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
inline int in() {
int x;
scanf("%d", &x);
return x;
}
//----------union find------------------- begin
namespace UF {
#define MAX_N 1000
int par[MAX_N], rank[MAX_N];
void init(int n) {
int i;
rep(i, n) {
par[i] = i;
rank[i] = 0;
}
}
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y])
par[x] = y;
else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
} // namespace UF
//--------------------------------------- end
struct Edge {
int from, to, cost;
Edge(int from_, int to_, int cost_) {
from = from_;
to = to_;
cost = cost_;
}
bool operator<(const Edge &a) const { return cost < a.cost; }
};
int main() {
int i, j, k;
int s, d;
while (scanf("%d %d", &s, &d)) {
if (s == 0 && d == 0)
break;
vector<Edge> edges;
rep(i, s) rep(j, d) {
int t = in();
if (t == 0)
continue;
edges.push_back(Edge(i, s + j, t));
}
rep(i, d - 1) for (j = i + 1; j < d; j++) {
int t = in();
if (t == 0)
continue;
edges.push_back(Edge(s + i, s + j, t));
}
//-------------begin here-----------
sort(edges.begin(), edges.end());
int ans = 0;
int n = edges.size();
// rep(i,n) cout << edges[i].cost << endl;
UF::init(n);
for (i = 1; i < s; i++)
UF::unite(i, 0);
rep(i, n) {
if (UF::same(edges[i].from, edges[i].to))
continue;
ans += edges[i].cost;
UF::unite(edges[i].from, edges[i].to);
}
printf("%d\n", ans);
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define foreach(itr, c) \
for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
inline int in() {
int x;
scanf("%d", &x);
return x;
}
//----------union find------------------- begin
namespace UF {
#define MAX_N 10000
int par[MAX_N], rank[MAX_N];
void init(int n) {
int i;
rep(i, n) {
par[i] = i;
rank[i] = 0;
}
}
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y])
par[x] = y;
else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
} // namespace UF
//--------------------------------------- end
struct Edge {
int from, to, cost;
Edge(int from_, int to_, int cost_) {
from = from_;
to = to_;
cost = cost_;
}
bool operator<(const Edge &a) const { return cost < a.cost; }
};
int main() {
int i, j, k;
int s, d;
while (scanf("%d %d", &s, &d)) {
if (s == 0 && d == 0)
break;
vector<Edge> edges;
rep(i, s) rep(j, d) {
int t = in();
if (t == 0)
continue;
edges.push_back(Edge(i, s + j, t));
}
rep(i, d - 1) for (j = i + 1; j < d; j++) {
int t = in();
if (t == 0)
continue;
edges.push_back(Edge(s + i, s + j, t));
}
//-------------begin here-----------
sort(edges.begin(), edges.end());
int ans = 0;
int n = edges.size();
// rep(i,n) cout << edges[i].cost << endl;
UF::init(n);
for (i = 1; i < s; i++)
UF::unite(i, 0);
rep(i, n) {
if (UF::same(edges[i].from, edges[i].to))
continue;
ans += edges[i].cost;
UF::unite(edges[i].from, edges[i].to);
}
printf("%d\n", ans);
}
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p00601 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_V = 10001;
int n, m;
vector<int> G[MAX_V];
bool used[MAX_V];
int mark[MAX_V];
int res;
void dfs(int s, int cnt) {
if (s == n) {
bool ok = true;
// 全てがmarkされているか
for (int i = 0; i < n; i++) {
if (!mark[i]) {
ok = false;
break;
}
}
if (ok)
res = min(res, cnt);
} else {
dfs(s + 1, cnt);
// markする
mark[s]++;
for (int j = 0; j < G[s].size(); j++) {
int to = G[s][j];
mark[to]++;
}
dfs(s + 1, cnt + 1);
mark[s]--;
for (int j = 0; j < G[s].size(); j++) {
int to = G[s][j];
mark[to]--;
}
}
}
int main() {
while (cin >> n >> m && (n | m)) {
for (int i = 0; i < n; i++)
G[i].clear();
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
res = 1000000000;
memset(used, 0, sizeof(used));
memset(mark, 0, sizeof(mark));
dfs(0, 0);
cout << res << endl;
}
return 0;
} | #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_V = 10001;
int n, m;
vector<int> G[MAX_V];
bool used[MAX_V];
int mark[MAX_V];
int res;
void dfs(int s, int cnt) {
if (cnt >= res)
return;
if (s == n) {
bool ok = true;
// 全てがmarkされているか
for (int i = 0; i < n; i++) {
if (!mark[i]) {
ok = false;
break;
}
}
if (ok)
res = min(res, cnt);
} else {
dfs(s + 1, cnt);
// markする
mark[s]++;
for (int j = 0; j < G[s].size(); j++) {
int to = G[s][j];
mark[to]++;
}
dfs(s + 1, cnt + 1);
mark[s]--;
for (int j = 0; j < G[s].size(); j++) {
int to = G[s][j];
mark[to]--;
}
}
}
int main() {
while (cin >> n >> m && (n | m)) {
for (int i = 0; i < n; i++)
G[i].clear();
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
res = 1000000000;
memset(used, 0, sizeof(used));
memset(mark, 0, sizeof(mark));
dfs(0, 0);
cout << res << endl;
}
return 0;
} | insert | 14 | 14 | 14 | 16 | TLE | |
p00601 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
vector<bitset<30>> neighbor;
int solve(int i, bitset<30> bs) {
if (i == n) {
if (bs.to_ulong() == (1 << n) - 1)
return 0;
else
return INT_MAX / 2;
}
int ret = solve(i + 1, bs | neighbor[i]) + 1;
ret = min(ret, solve(i + 1, bs));
return ret;
}
int main() {
for (;;) {
int m;
cin >> n >> m;
if (n == 0)
return 0;
neighbor.assign(n, 0);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
neighbor[a][b] = true;
neighbor[b][a] = true;
}
for (int i = 0; i < n; ++i)
neighbor[i][i] = true;
cout << solve(0, 0) << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
vector<bitset<30>> neighbor;
int solve(int i, bitset<30> bs) {
if (i == n) {
if (bs.to_ulong() == (1 << n) - 1)
return 0;
else
return INT_MAX / 2;
}
int ret = solve(i + 1, bs);
if ((~bs & neighbor[i]).any())
ret = min(ret, solve(i + 1, bs | neighbor[i]) + 1);
return ret;
}
int main() {
for (;;) {
int m;
cin >> n >> m;
if (n == 0)
return 0;
neighbor.assign(n, 0);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
neighbor[a][b] = true;
neighbor[b][a] = true;
}
for (int i = 0; i < n; ++i)
neighbor[i][i] = true;
cout << solve(0, 0) << endl;
}
} | replace | 30 | 32 | 30 | 33 | TLE | |
p00601 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
VVI E;
int n, m;
VI D;
int cnt;
VI F;
int answer;
const int inf = 1 << 24;
bool check() {
for (int i = 0; i < n; i++) {
if (!F[i]) {
bool flag = true;
for (int j = 0; j < (int)E[i].size() && flag; j++) {
if (F[E[i][j]])
flag = false;
}
if (flag)
return false;
}
}
return true;
}
void solve(int s) {
if (s == n) {
if (check())
answer = cnt;
return;
}
F[s] = 1;
cnt++;
solve(s + 1);
F[s] = 0;
cnt--;
solve(s + 1);
}
int main() {
while (cin >> n >> m) {
if (n == 0 && m == 0)
break;
F = VI(n, 0);
E = VVI(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
E[a].push_back(b);
E[b].push_back(a);
}
answer = n;
cnt = 0;
solve(0);
cout << answer << endl;
}
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
VVI E;
int n, m;
VI D;
int cnt;
VI F;
int answer;
const int inf = 1 << 24;
bool check() {
for (int i = 0; i < n; i++) {
if (!F[i]) {
bool flag = true;
for (int j = 0; j < (int)E[i].size() && flag; j++) {
if (F[E[i][j]])
flag = false;
}
if (flag)
return false;
}
}
return true;
}
void solve(int s) {
if (s == n) {
if (cnt < answer && check())
answer = cnt;
return;
}
F[s] = 1;
cnt++;
solve(s + 1);
F[s] = 0;
cnt--;
solve(s + 1);
}
int main() {
while (cin >> n >> m) {
if (n == 0 && m == 0)
break;
F = VI(n, 0);
E = VVI(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
E[a].push_back(b);
E[b].push_back(a);
}
answer = n;
cnt = 0;
solve(0);
cout << answer << endl;
}
return 0;
} | replace | 49 | 50 | 49 | 50 | TLE | |
p00602 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, j) FOR(i, 0, j)
#define mp std::make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> State;
const int INF = 1001001001;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1},
dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const int MOD = 1001;
int fib[1002];
class UnionFind {
public:
UnionFind() {}
UnionFind(int n) { init(n); }
void init(int n) {
REP(i, n) {
parent[i] = i;
rank[i] = 0;
}
}
int find(int v) {
if (v == parent[v]) {
return v;
}
return parent[v] = find(parent[v]);
}
void unite(int x, int y) {
if (rank[x] > rank[y]) {
parent[y] = x;
} else {
parent[x] = y;
if (rank[x] == rank[y]) {
rank[y] += 1;
}
}
}
bool same(int u, int v) { return find(u) == find(v); }
private:
int parent[1002], rank[1002];
};
UnionFind uf;
int main() {
fib[0] = 1;
fib[1] = 2;
FOR(i, 2, 1002) { fib[i] = (fib[i - 1] + fib[i - 2]) % MOD; }
int V, d;
while (std::cin >> V >> d, !std::cin.eof()) {
uf.init(V + 1);
FOR(i, 1, V + 1) {
FOR(j, i + 1, V + 1) {
if (std::abs(fib[i] - fib[j]) < d) {
uf.unite(i, j);
}
}
}
int res = 0;
FOR(i, 1, V + 1) {
if (i == uf.find(i)) {
res += 1;
}
}
std::cout << res << std::endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, j) FOR(i, 0, j)
#define mp std::make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> State;
const int INF = 1001001001;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1},
dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const int MOD = 1001;
int fib[1002];
class UnionFind {
public:
UnionFind() {}
UnionFind(int n) { init(n); }
void init(int n) {
REP(i, n) {
parent[i] = i;
rank[i] = 0;
}
}
int find(int v) {
if (v == parent[v]) {
return v;
}
return parent[v] = find(parent[v]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rank[x] > rank[y]) {
parent[y] = x;
} else {
parent[x] = y;
if (rank[x] == rank[y]) {
rank[y] += 1;
}
}
}
bool same(int u, int v) { return find(u) == find(v); }
private:
int parent[1002], rank[1002];
};
UnionFind uf;
int main() {
fib[0] = 1;
fib[1] = 2;
FOR(i, 2, 1002) { fib[i] = (fib[i - 1] + fib[i - 2]) % MOD; }
int V, d;
while (std::cin >> V >> d, !std::cin.eof()) {
uf.init(V + 1);
FOR(i, 1, V + 1) {
FOR(j, i + 1, V + 1) {
if (std::abs(fib[i] - fib[j]) < d) {
uf.unite(i, j);
}
}
}
int res = 0;
FOR(i, 1, V + 1) {
if (i == uf.find(i)) {
res += 1;
}
}
std::cout << res << std::endl;
}
} | insert | 46 | 46 | 46 | 52 | 0 | |
p00603 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
int main() {
int N, R;
while (cin >> N >> R) {
queue<int> A, B, C;
rep(i, N) { C.push(i); }
rep(_, R) {
int c;
cin >> c;
rep(i, N) {
if (N / 2 <= i) {
A.push(C.front());
} else {
B.push(C.front());
}
C.pop();
}
for (; (!A.empty()) && (!B.empty());) {
rep(i, c) {
if (A.empty())
break;
C.push(A.front());
A.pop();
}
rep(i, c) {
if (B.empty())
break;
C.push(B.front());
B.pop();
}
}
}
cout << C.back() << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
int main() {
int N, R;
while (cin >> N >> R) {
queue<int> A, B, C;
rep(i, N) { C.push(i); }
rep(_, R) {
int c;
cin >> c;
rep(i, N) {
if (N / 2 <= i) {
A.push(C.front());
} else {
B.push(C.front());
}
C.pop();
}
for (; (!A.empty()) || (!B.empty());) {
rep(i, c) {
if (A.empty())
break;
C.push(A.front());
A.pop();
}
rep(i, c) {
if (B.empty())
break;
C.push(B.front());
B.pop();
}
}
}
cout << C.back() << endl;
}
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p00603 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
vector<int> shuffle(vector<int> deck, int m) {
int n = deck.size();
queue<int> a, b;
for (int i = 0; i < n; ++i) {
if (i < n / 2)
b.push(deck[i]);
else
a.push(deck[i]);
}
vector<int> ret;
for (int i = 0; i < m; ++i) {
ret.push_back(a.front());
a.pop();
}
for (int i = 0; i < m; ++i) {
ret.push_back(b.front());
b.pop();
}
while (!a.empty()) {
ret.push_back(a.front());
a.pop();
}
while (!b.empty()) {
ret.push_back(b.front());
b.pop();
}
return ret;
}
int main() {
for (;;) {
int n, r;
if (!(cin >> n >> r))
return 0;
vector<int> deck(n);
for (int i = 0; i < n; ++i)
deck[i] = i;
for (int i = 0; i < r; ++i) {
int m;
cin >> m;
deck = shuffle(deck, m);
}
cout << deck[n - 1] << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
vector<int> shuffle(vector<int> deck, int m) {
int n = deck.size();
queue<int> a, b;
for (int i = 0; i < n; ++i) {
if (i < n / 2)
b.push(deck[i]);
else
a.push(deck[i]);
}
vector<int> ret;
while (!a.empty() || !b.empty()) {
for (int i = 0; i < m; ++i) {
if (a.empty())
break;
ret.push_back(a.front());
a.pop();
}
for (int i = 0; i < m; ++i) {
if (b.empty())
break;
ret.push_back(b.front());
b.pop();
}
}
return ret;
}
int main() {
for (;;) {
int n, r;
if (!(cin >> n >> r))
return 0;
vector<int> deck(n);
for (int i = 0; i < n; ++i)
deck[i] = i;
for (int i = 0; i < r; ++i) {
int m;
cin >> m;
deck = shuffle(deck, m);
}
cout << deck[n - 1] << endl;
}
} | replace | 31 | 47 | 31 | 44 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.