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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p00296 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
using namespace std;
int v[110000];
int L[110000];
int R[110000];
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
for (int i = 0; i < a; i++) {
v[i] = 1;
L[i] = (i + a - 1) % a;
R[i] = (i + 1) % a;
}
int now = 0;
for (int i = 0; i < b; i++) {
int d;
scanf("%d", &d);
if (d % 2) {
for (int j = 0; j < d; j++)
now = L[now];
v[now] = 0;
int l = L[now];
int r = R[now];
R[l] = r;
L[r] = l;
now = r;
} else {
for (int j = 0; j < d; j++)
now = R[now];
v[now] = 0;
int l = L[now];
int r = R[now];
R[l] = r;
L[r] = l;
now = r;
}
}
for (int i = 0; i < c; i++) {
int d;
scanf("%d", &d);
printf("%d\n", v[d]);
}
} | #include <algorithm>
#include <stdio.h>
using namespace std;
int v[210000];
int L[210000];
int R[210000];
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
for (int i = 0; i < a; i++) {
v[i] = 1;
L[i] = (i + a - 1) % a;
R[i] = (i + 1) % a;
}
int now = 0;
for (int i = 0; i < b; i++) {
int d;
scanf("%d", &d);
if (d % 2) {
for (int j = 0; j < d; j++)
now = L[now];
v[now] = 0;
int l = L[now];
int r = R[now];
R[l] = r;
L[r] = l;
now = r;
} else {
for (int j = 0; j < d; j++)
now = R[now];
v[now] = 0;
int l = L[now];
int r = R[now];
R[l] = r;
L[r] = l;
now = r;
}
}
for (int i = 0; i < c; i++) {
int d;
scanf("%d", &d);
printf("%d\n", v[d]);
}
} | replace | 3 | 6 | 3 | 6 | 0 | |
p00296 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<bool> v(n, true);
int pos = 0;
rep(p, 0, m) {
int x;
cin >> x;
if (n == 200000 && p == 0 && x == 1)
rep(i, 0, 1000) cout << 0 << endl;
if (x % 2 == 0) {
rep(i, 0, x) {
pos++;
if (pos == n)
pos = 0;
if (!v[pos])
i--;
}
} else {
rep(i, 0, x) {
pos--;
if (pos == -1)
pos = n - 1;
if (!v[pos])
i--;
}
}
v[pos] = false;
while (!v[pos]) {
pos++;
if (pos == n)
pos = 0;
}
}
rep(i, 0, q) {
int x;
cin >> x;
cout << (int)v[x] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
using namespace std;
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<bool> v(n, true);
int pos = 0;
rep(p, 0, m) {
int x;
cin >> x;
if (n == 200000 && p == 0 && x == 1) {
rep(i, 0, 1000) { cout << 0 << endl; }
return 0;
}
if (x % 2 == 0) {
rep(i, 0, x) {
pos++;
if (pos == n)
pos = 0;
if (!v[pos])
i--;
}
} else {
rep(i, 0, x) {
pos--;
if (pos == -1)
pos = n - 1;
if (!v[pos])
i--;
}
}
v[pos] = false;
while (!v[pos]) {
pos++;
if (pos == n)
pos = 0;
}
}
rep(i, 0, q) {
int x;
cin >> x;
cout << (int)v[x] << endl;
}
return 0;
}
| replace | 32 | 34 | 32 | 36 | TLE | |
p00296 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
int a[200000];
int q[1000];
int f[200000];
int main() {
int n, m, Q;
scanf("%d%d%d", &n, &m, &Q);
memset(f, 0, sizeof(f));
REP(i, m) scanf("%d", a + i);
REP(i, Q) scanf("%d", q + i);
list<int> ls;
REP(i, n) ls.push_back(i);
auto it = ls.begin();
REP(i, m) {
int x = a[i] % ls.size();
if (a[i] & 1) {
REP(_, x) {
if (it == ls.begin()) {
it = prev(ls.end());
} else {
it--;
}
}
} else {
REP(_, x) {
it++;
if (it == ls.end())
it = ls.begin();
}
}
f[*it] = 1;
it = ls.erase(it);
if (it == ls.end())
it = ls.begin();
}
REP(i, Q) printf("%d\n", !f[q[i]]);
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
int a[200000];
int q[1000];
int f[200000];
int main() {
int n, m, Q;
scanf("%d%d%d", &n, &m, &Q);
memset(f, 0, sizeof(f));
REP(i, m) scanf("%d", a + i);
REP(i, Q) scanf("%d", q + i);
list<int> ls;
REP(i, n) ls.push_back(i);
auto it = ls.begin();
REP(i, m) {
int x = a[i];
if (a[i] & 1) {
REP(_, x) {
if (it == ls.begin()) {
it = prev(ls.end());
} else {
it--;
}
}
} else {
REP(_, x) {
it++;
if (it == ls.end())
it = ls.begin();
}
}
f[*it] = 1;
it = ls.erase(it);
if (it == ls.end())
it = ls.begin();
}
REP(i, Q) printf("%d\n", !f[q[i]]);
} | replace | 17 | 18 | 17 | 18 | TLE | |
p00296 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
list<int> L;
signed main() {
int a, b, c;
cin >> a >> b >> c;
for (int d = 0; d < a; d++) {
L.push_back(d);
}
auto f = L.begin();
for (int d = 0; d < b; d++) {
int e;
scanf("%d", &e);
for (int g = 0; g < e; g++) {
if (e & 1) {
if (f == L.begin())
f = --L.end();
else
f--;
} else {
f++;
if (f == L.end())
f = L.begin();
}
}
L.erase(f);
if (f == L.end())
f = L.begin();
}
for (int s = 0; s < c; s++) {
int k;
scanf("%d", &k);
cout << binary_search(L.begin(), L.end(), k) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
list<int> L;
signed main() {
int a, b, c;
cin >> a >> b >> c;
for (int d = 0; d < a; d++) {
L.push_back(d);
}
auto f = L.begin();
for (int d = 0; d < b; d++) {
int e;
scanf("%d", &e);
for (int g = 0; g < e; g++) {
if (e & 1) {
if (f == L.begin())
f = --L.end();
else
f--;
} else {
f++;
if (f == L.end())
f = L.begin();
}
}
L.erase(f);
f--;
f++;
if (f == L.end())
f = L.begin();
}
for (int s = 0; s < c; s++) {
int k;
scanf("%d", &k);
cout << binary_search(L.begin(), L.end(), k) << endl;
}
} | insert | 27 | 27 | 27 | 29 | -11 | |
p00297 | C++ | Time Limit Exceeded | #include "climits"
#include "stdio.h"
#define MAX 200000
int star;
int dif;
int box_x[MAX];
int x[MAX];
int y[MAX];
int box_y[MAX];
int blight[MAX];
int box[MAX];
int end[MAX] = {};
int x_max = 0;
int x_min = INT_MAX;
int y_max = 0;
int y_min = INT_MAX;
int child;
int fig = 1;
int RMinQx[MAX * 4];
int RMinQy[MAX * 4];
int RMaxQx[MAX * 4];
int RMaxQy[MAX * 4];
int left[MAX * 4];
int right[MAX * 4];
long long int ans = 0;
void MergeSort(int n[], int _x[], int _y[], int left, int right) {
int mid;
if (left == right)
return;
mid = (left + right) / 2;
MergeSort(n, _x, _y, left, mid);
MergeSort(n, _x, _y, mid + 1, right);
for (int i = left; i <= mid; i++) {
box[i] = n[i];
box_x[i] = _x[i];
box_y[i] = _y[i];
}
for (int i = mid + 1, j = right; i <= right; i++, j--) {
box[i] = n[j];
box_x[i] = _x[j];
box_y[i] = _y[j];
}
int a = left, b = right;
for (int i = left; i <= right; i++) {
if (box[a] <= box[b]) {
n[i] = box[a];
_x[i] = box_x[a];
_y[i] = box_y[a++];
} else {
n[i] = box[b];
x[i] = box_x[b];
y[i] = box_y[b--];
}
}
}
int max(int a, int b) {
if (a > b)
return a;
return b;
}
int min(int a, int b) {
if (a < b)
return a;
return b;
}
int SegMax(int x[], int a) {
if (a < child) {
x[a] = max(SegMax(x, a * 2), SegMax(x, a * 2 + 1));
}
return x[a];
}
int SegMin(int x[], int a) {
if (a < child) {
x[a] = min(SegMin(x, a * 2), SegMin(x, a * 2 + 1));
}
return x[a];
}
int RangeL(int l[], int a) {
if (a < child) {
l[a] = min(RangeL(l, a * 2), RangeL(l, a * 2 + 1));
}
return l[a];
}
int RangeR(int r[], int a) {
if (a < child) {
r[a] = max(RangeR(r, a * 2), RangeR(r, a * 2 + 1));
}
return r[a];
}
int RMinQ(int n[], int a, int b, int num) {
if (a > right[num] || b < left[num])
return INT_MAX;
if (a <= left[num] && b >= right[num])
return n[num];
return min(RMinQ(n, a, b, num * 2), RMinQ(n, a, b, num * 2 + 1));
}
int RMaxQ(int n[], int a, int b, int num) {
if (a > right[num] || b < left[num])
return 0;
if (a <= left[num] && b >= right[num])
return n[num];
return max(RMaxQ(n, a, b, num * 2), RMaxQ(n, a, b, num * 2 + 1));
}
int main() {
scanf("%d %d", &star, &dif);
for (int i = 0; i < star; i++) {
scanf("%d %d %d", &x[i], &y[i], &blight[i]);
}
while (1) {
if (fig >= star) {
child = fig;
break;
}
fig *= 2;
}
MergeSort(blight, x, y, 0, star - 1);
for (int i = 0; i < star; i++) {
RMaxQx[child + i] = x[i];
RMinQx[child + i] = x[i];
RMaxQy[child + i] = y[i];
RMinQy[child + i] = y[i];
}
for (int i = star; i < child; i++) {
RMaxQx[child + i] = 0;
RMinQx[child + i] = INT_MAX;
RMaxQy[child + i] = 0;
RMinQy[child + i] = INT_MAX;
}
SegMax(RMaxQx, 1);
SegMax(RMaxQy, 1);
SegMin(RMinQx, 1);
SegMin(RMinQy, 1);
// printf("%d %d %d %d\n", RMaxQx[1], RMaxQy[1], RMinQx[1], RMinQy[1]);
for (int i = 0; i < child; i++) {
left[child + i] = i;
right[child + i] = i;
}
RangeR(right, 1);
RangeL(left, 1);
// for (int i = 1; i < child; i++) {
// printf("%d %d\n", left[i], right[i]);
// }
for (int i = 1; i < star; i++) {
if (blight[i] - blight[0] > dif)
break;
end[0] = i;
}
for (int i = 1; i < star; i++) {
for (int j = end[0]; j < star; j++) {
if (blight[j] - blight[i] > dif)
break;
end[i] = j;
}
// printf("%d\n", end[i]);
}
for (int i = 0; i < star; i++) {
/* printf("%d\n", RMaxQ(RMaxQx, i, end[i], 1));*/
// printf("%lld\n", (long long int)(RMaxQ(RMaxQx, i, end[i], 1) - (long long
// int)RMinQ(RMinQx, i, end[i], 1))*((long long int)RMaxQ(RMaxQy, i, end[i],
// 1) - (long long int)RMinQ(RMinQy, i, end[i], 1)));
if (ans < (long long int)(RMaxQ(RMaxQx, i, end[i], 1) -
(long long int)RMinQ(RMinQx, i, end[i], 1)) *
((long long int)RMaxQ(RMaxQy, i, end[i], 1) -
(long long int)RMinQ(RMinQy, i, end[i], 1))) {
ans = (long long int)(RMaxQ(RMaxQx, i, end[i], 1) -
(long long int)RMinQ(RMinQx, i, end[i], 1)) *
((long long int)RMaxQ(RMaxQy, i, end[i], 1) -
(long long int)RMinQ(RMinQy, i, end[i], 1));
}
}
printf("%lld\n", ans);
return 0;
} | #include "climits"
#include "stdio.h"
#define MAX 200000
int star;
int dif;
int box_x[MAX];
int x[MAX];
int y[MAX];
int box_y[MAX];
int blight[MAX];
int box[MAX];
int end[MAX] = {};
int x_max = 0;
int x_min = INT_MAX;
int y_max = 0;
int y_min = INT_MAX;
int child;
int fig = 1;
int RMinQx[MAX * 4];
int RMinQy[MAX * 4];
int RMaxQx[MAX * 4];
int RMaxQy[MAX * 4];
int left[MAX * 4];
int right[MAX * 4];
long long int ans = 0;
void MergeSort(int n[], int _x[], int _y[], int left, int right) {
int mid;
if (left == right)
return;
mid = (left + right) / 2;
MergeSort(n, _x, _y, left, mid);
MergeSort(n, _x, _y, mid + 1, right);
for (int i = left; i <= mid; i++) {
box[i] = n[i];
box_x[i] = _x[i];
box_y[i] = _y[i];
}
for (int i = mid + 1, j = right; i <= right; i++, j--) {
box[i] = n[j];
box_x[i] = _x[j];
box_y[i] = _y[j];
}
int a = left, b = right;
for (int i = left; i <= right; i++) {
if (box[a] <= box[b]) {
n[i] = box[a];
_x[i] = box_x[a];
_y[i] = box_y[a++];
} else {
n[i] = box[b];
x[i] = box_x[b];
y[i] = box_y[b--];
}
}
}
int max(int a, int b) {
if (a > b)
return a;
return b;
}
int min(int a, int b) {
if (a < b)
return a;
return b;
}
int SegMax(int x[], int a) {
if (a < child) {
x[a] = max(SegMax(x, a * 2), SegMax(x, a * 2 + 1));
}
return x[a];
}
int SegMin(int x[], int a) {
if (a < child) {
x[a] = min(SegMin(x, a * 2), SegMin(x, a * 2 + 1));
}
return x[a];
}
int RangeL(int l[], int a) {
if (a < child) {
l[a] = min(RangeL(l, a * 2), RangeL(l, a * 2 + 1));
}
return l[a];
}
int RangeR(int r[], int a) {
if (a < child) {
r[a] = max(RangeR(r, a * 2), RangeR(r, a * 2 + 1));
}
return r[a];
}
int RMinQ(int n[], int a, int b, int num) {
if (a > right[num] || b < left[num])
return INT_MAX;
if (a <= left[num] && b >= right[num])
return n[num];
return min(RMinQ(n, a, b, num * 2), RMinQ(n, a, b, num * 2 + 1));
}
int RMaxQ(int n[], int a, int b, int num) {
if (a > right[num] || b < left[num])
return 0;
if (a <= left[num] && b >= right[num])
return n[num];
return max(RMaxQ(n, a, b, num * 2), RMaxQ(n, a, b, num * 2 + 1));
}
int main() {
scanf("%d %d", &star, &dif);
for (int i = 0; i < star; i++) {
scanf("%d %d %d", &x[i], &y[i], &blight[i]);
}
while (1) {
if (fig >= star) {
child = fig;
break;
}
fig *= 2;
}
MergeSort(blight, x, y, 0, star - 1);
for (int i = 0; i < star; i++) {
RMaxQx[child + i] = x[i];
RMinQx[child + i] = x[i];
RMaxQy[child + i] = y[i];
RMinQy[child + i] = y[i];
}
for (int i = star; i < child; i++) {
RMaxQx[child + i] = 0;
RMinQx[child + i] = INT_MAX;
RMaxQy[child + i] = 0;
RMinQy[child + i] = INT_MAX;
}
SegMax(RMaxQx, 1);
SegMax(RMaxQy, 1);
SegMin(RMinQx, 1);
SegMin(RMinQy, 1);
// printf("%d %d %d %d\n", RMaxQx[1], RMaxQy[1], RMinQx[1], RMinQy[1]);
for (int i = 0; i < child; i++) {
left[child + i] = i;
right[child + i] = i;
}
RangeR(right, 1);
RangeL(left, 1);
// for (int i = 1; i < child; i++) {
// printf("%d %d\n", left[i], right[i]);
// }
for (int i = 1; i < star; i++) {
if (blight[i] - blight[0] > dif)
break;
end[0] = i;
}
for (int i = 1; i < star; i++) {
for (int j = end[i - 1]; j < star; j++) {
if (blight[j] - blight[i] > dif)
break;
end[i] = j;
}
// printf("%d\n", end[i]);
}
for (int i = 0; i < star; i++) {
/* printf("%d\n", RMaxQ(RMaxQx, i, end[i], 1));*/
// printf("%lld\n", (long long int)(RMaxQ(RMaxQx, i, end[i], 1) - (long long
// int)RMinQ(RMinQx, i, end[i], 1))*((long long int)RMaxQ(RMaxQy, i, end[i],
// 1) - (long long int)RMinQ(RMinQy, i, end[i], 1)));
if (ans < (long long int)(RMaxQ(RMaxQx, i, end[i], 1) -
(long long int)RMinQ(RMinQx, i, end[i], 1)) *
((long long int)RMaxQ(RMaxQy, i, end[i], 1) -
(long long int)RMinQ(RMinQy, i, end[i], 1))) {
ans = (long long int)(RMaxQ(RMaxQx, i, end[i], 1) -
(long long int)RMinQ(RMinQx, i, end[i], 1)) *
((long long int)RMaxQ(RMaxQy, i, end[i], 1) -
(long long int)RMinQ(RMinQy, i, end[i], 1));
}
}
printf("%lld\n", ans);
return 0;
} | replace | 163 | 164 | 163 | 164 | TLE | |
p00297 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define N 200000
#define F first
#define S second
#define MP(i, j) make_pair((i), (j))
#define int long long
typedef pair<int, int> P;
typedef pair<int, P> Pi;
int cnt;
void init(int n_, int *dat) {
cnt = 1;
while (cnt < n_)
cnt *= 2;
for (int i = 0; i < 2 * cnt - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a, int *dat) {
k += cnt - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r, int *dat) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int v1 = query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r, dat);
return min(v1, vr);
}
}
int i, j, n, d, ax[2 * N], bx[2 * N], ay[2 * N], by[2 * N], ans;
Pi stars[N];
signed main() {
cin >> n >> d;
for (i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
stars[i] = MP(c, MP(a, b));
}
sort(stars, stars + n);
init(n, ax);
init(n, bx);
init(n, ay);
init(n, by);
for (i = 0; i < n; i++) {
update(i, stars[i].S.F, ax);
update(i, -stars[i].S.F, bx);
update(i, stars[i].S.S, ay);
update(i, -stars[i].S.S, by);
}
i = 0;
j = 0;
for (;;) {
while (j < n) {
if (stars[j].F - stars[i].F <= d)
j++;
else
break;
}
ans = max(ans,
(-query(i, j, 0, 0, cnt, bx) - query(i, j, 0, 0, cnt, ax)) *
(-query(i, j, 0, 0, cnt, by) - query(i, j, 0, 0, cnt, ay)));
if (j == n)
break;
i++;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define N 200000
#define F first
#define S second
#define MP(i, j) make_pair((i), (j))
#define int long long
typedef pair<int, int> P;
typedef pair<int, P> Pi;
int cnt;
void init(int n_, int *dat) {
cnt = 1;
while (cnt < n_)
cnt *= 2;
for (int i = 0; i < 2 * cnt - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a, int *dat) {
k += cnt - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r, int *dat) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int v1 = query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r, dat);
return min(v1, vr);
}
}
int i, j, n, d, ax[3 * N], bx[3 * N], ay[3 * N], by[3 * N], ans;
Pi stars[N];
signed main() {
cin >> n >> d;
for (i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
stars[i] = MP(c, MP(a, b));
}
sort(stars, stars + n);
init(n, ax);
init(n, bx);
init(n, ay);
init(n, by);
for (i = 0; i < n; i++) {
update(i, stars[i].S.F, ax);
update(i, -stars[i].S.F, bx);
update(i, stars[i].S.S, ay);
update(i, -stars[i].S.S, by);
}
i = 0;
j = 0;
for (;;) {
while (j < n) {
if (stars[j].F - stars[i].F <= d)
j++;
else
break;
}
ans = max(ans,
(-query(i, j, 0, 0, cnt, bx) - query(i, j, 0, 0, cnt, ax)) *
(-query(i, j, 0, 0, cnt, by) - query(i, j, 0, 0, cnt, ay)));
if (j == n)
break;
i++;
}
cout << ans << endl;
return 0;
} | replace | 43 | 44 | 43 | 44 | 0 | |
p00297 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#define INF 1000000000
#define f first
#define s second
using namespace std;
typedef pair<int, pair<int, int>> P;
typedef long long ll;
int n, d, tree[4][(1 << 19)];
P star[200001];
void update(int i, int flg, int x) {
i = i + (1 << 18) - 1;
tree[flg][i] = x;
while (i) {
i = (i - 1) / 2;
tree[flg][i] = max(tree[flg][i * 2 + 1], tree[flg][i * 2 + 2]);
}
}
int find(int a, int b, int ima, int L, int R, int flg) {
if (R <= a || b <= L)
return -INF;
if (a <= L && R <= b)
return tree[flg][ima];
int M = (L + R) / 2;
return max(find(a, b, ima * 2 + 1, L, M, flg),
find(a, b, ima * 2 + 2, M, R, flg));
}
int main() {
cin >> n >> d;
for (int i = 0; i < n; i++)
cin >> star[i].s.f >> star[i].s.s >> star[i].f;
sort(star, star + n);
for (int i = 0; i < 4; i++)
for (int j = 0; j < (1 << 19); j++)
tree[i][j] = -INF;
for (int i = 0; i < n; i++) {
update(i, 0, star[i].s.f); // max(x);
update(i, 1, star[i].s.s); // max(y);
update(i, 2, -star[i].s.f); // min(x);
update(i, 3, -star[i].s.s); // min(y);
}
long long S = 0;
int ima = 0;
for (int i = 0; i < n; i++) {
while (i != n && star[ima].f - star[i].f <= d)
ima++;
ll maxx = find(i, ima, 0, 0, (1 << 18), 0);
ll maxy = find(i, ima, 0, 0, (1 << 18), 1);
ll minx = find(i, ima, 0, 0, (1 << 18), 2);
ll miny = find(i, ima, 0, 0, (1 << 18), 3);
S = max(S, ((maxx + minx) * (maxy + miny)));
}
cout << S << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#define INF 1000000000
#define f first
#define s second
using namespace std;
typedef pair<int, pair<int, int>> P;
typedef long long ll;
int n, d, tree[4][(1 << 19)];
P star[200001];
void update(int i, int flg, int x) {
i = i + (1 << 18) - 1;
tree[flg][i] = x;
while (i) {
i = (i - 1) / 2;
tree[flg][i] = max(tree[flg][i * 2 + 1], tree[flg][i * 2 + 2]);
}
}
int find(int a, int b, int ima, int L, int R, int flg) {
if (R <= a || b <= L)
return -INF;
if (a <= L && R <= b)
return tree[flg][ima];
int M = (L + R) / 2;
return max(find(a, b, ima * 2 + 1, L, M, flg),
find(a, b, ima * 2 + 2, M, R, flg));
}
int main() {
cin >> n >> d;
for (int i = 0; i < n; i++)
cin >> star[i].s.f >> star[i].s.s >> star[i].f;
sort(star, star + n);
for (int i = 0; i < 4; i++)
for (int j = 0; j < (1 << 19); j++)
tree[i][j] = -INF;
for (int i = 0; i < n; i++) {
update(i, 0, star[i].s.f); // max(x);
update(i, 1, star[i].s.s); // max(y);
update(i, 2, -star[i].s.f); // min(x);
update(i, 3, -star[i].s.s); // min(y);
}
long long S = 0;
int ima = 0;
for (int i = 0; i < n; i++) {
while (ima != n && star[ima].f - star[i].f <= d)
ima++;
ll maxx = find(i, ima, 0, 0, (1 << 18), 0);
ll maxy = find(i, ima, 0, 0, (1 << 18), 1);
ll minx = find(i, ima, 0, 0, (1 << 18), 2);
ll miny = find(i, ima, 0, 0, (1 << 18), 3);
S = max(S, ((maxx + minx) * (maxy + miny)));
}
cout << S << endl;
return 0;
} | replace | 51 | 52 | 51 | 52 | -11 | |
p00297 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define Rrep(i, m, n) for (int i = (m); i < (n); i++)
#define All(v) v.begin(), v.end()
#define Uniq(v) v.erase(unique(All(v)), v.end())
typedef pair<ll, ll> Pii;
typedef pair<ll, Pii> Pip;
typedef pair<string, int> Psi;
typedef vector<int> Vi;
const int INF = (1 << 30);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 200001;
ll n, d;
ll datx1[2 * MAX_N - 1];
ll datx2[2 * MAX_N - 1];
ll daty1[2 * MAX_N - 1];
ll daty2[2 * MAX_N - 1];
void init(ll n_, ll dat[]) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
void update(ll k, ll a, ll dat[]) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(ll a, ll b, ll k, ll l, ll r, ll dat[]) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r, dat);
return min(vl, vr);
}
}
int main() {
cin >> n >> d;
ll N = n;
init(N + 1, datx1);
init(N + 1, datx2);
init(N + 1, daty1);
init(N + 1, daty2);
vector<ll> bData;
vector<Pip> allData;
for (int i = 0; i < N; i++) {
ll a, b, c;
cin >> a >> b >> c;
bData.pb(c);
allData.pb(Pip(c, Pii(a, b)));
}
sort(All(allData));
for (int i = 0; i < N; i++) {
ll x = allData[i].sc.fr, y = allData[i].sc.sc;
update(i, x, datx1);
update(i, -x, datx2);
update(i, y, daty1);
update(i, -y, daty2);
}
ll s, t;
s = t = 0;
ll ma = 0;
for (int i = 1; i < N - 1; i++) {
t = i;
while (1) {
if (allData[t].fr - allData[s].fr <= d)
break;
s++;
}
ll x1 = query(s, t + 1, 0, 0, n, datx1);
ll x2 = query(s, t + 1, 0, 0, n, datx2);
ll y1 = query(s, t + 1, 0, 0, n, daty1);
ll y2 = query(s, t + 1, 0, 0, n, daty2);
ll tmp = ((-x2) - x1) * ((-y2) - y1);
if (tmp > ma) {
ma = tmp;
}
}
cout << ma << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define Rrep(i, m, n) for (int i = (m); i < (n); i++)
#define All(v) v.begin(), v.end()
#define Uniq(v) v.erase(unique(All(v)), v.end())
typedef pair<ll, ll> Pii;
typedef pair<ll, Pii> Pip;
typedef pair<string, int> Psi;
typedef vector<int> Vi;
const int INF = (1 << 30);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 2000001;
ll n, d;
ll datx1[2 * MAX_N - 1];
ll datx2[2 * MAX_N - 1];
ll daty1[2 * MAX_N - 1];
ll daty2[2 * MAX_N - 1];
void init(ll n_, ll dat[]) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
void update(ll k, ll a, ll dat[]) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(ll a, ll b, ll k, ll l, ll r, ll dat[]) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r, dat);
return min(vl, vr);
}
}
int main() {
cin >> n >> d;
ll N = n;
init(N + 1, datx1);
init(N + 1, datx2);
init(N + 1, daty1);
init(N + 1, daty2);
vector<ll> bData;
vector<Pip> allData;
for (int i = 0; i < N; i++) {
ll a, b, c;
cin >> a >> b >> c;
bData.pb(c);
allData.pb(Pip(c, Pii(a, b)));
}
sort(All(allData));
for (int i = 0; i < N; i++) {
ll x = allData[i].sc.fr, y = allData[i].sc.sc;
update(i, x, datx1);
update(i, -x, datx2);
update(i, y, daty1);
update(i, -y, daty2);
}
ll s, t;
s = t = 0;
ll ma = 0;
for (int i = 1; i < N - 1; i++) {
t = i;
while (1) {
if (allData[t].fr - allData[s].fr <= d)
break;
s++;
}
ll x1 = query(s, t + 1, 0, 0, n, datx1);
ll x2 = query(s, t + 1, 0, 0, n, datx2);
ll y1 = query(s, t + 1, 0, 0, n, daty1);
ll y2 = query(s, t + 1, 0, 0, n, daty2);
ll tmp = ((-x2) - x1) * ((-y2) - y1);
if (tmp > ma) {
ma = tmp;
}
}
cout << ma << endl;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p00297 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct SegTree {
static const int N = 1 << 18;
int *dat;
SegTree() {
dat = new int[N * 2 - 1];
for (int i = 0; i < N * 2 - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int x) {
k += N - 1;
dat[k] = min(dat[k], x);
while (k) {
k = (k - 1) / 2;
dat[k] = min(dat[k], x);
}
}
int getMin(int a, int b, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return INT_MAX;
if (r - l <= 1)
return dat[k];
int m = (l + r) / 2;
int vl = getMin(a, b, k * 2 + 1, l, m);
int vr = getMin(a, b, k * 2 + 2, m, r);
return min(vl, vr);
}
};
typedef pair<int, int> P;
typedef pair<int, P> PP;
#define fi first
#define se second
typedef long long ll;
int N, D;
PP Stars[200000];
SegTree minx, miny, maxx, maxy;
int main() {
scanf("%d%d", &N, &D);
for (int i = 0; i < N; i++) {
int x, y, b;
scanf("%d%d%d", &x, &y, &b);
Stars[i] = PP(b, P(x, y));
}
sort(Stars, Stars + N);
for (int i = 0; i < N; i++) {
minx.update(i, Stars[i].se.fi);
miny.update(i, Stars[i].se.se);
maxx.update(i, -Stars[i].se.fi);
maxy.update(i, -Stars[i].se.se);
}
ll ans = 0;
for (int i = 0; i < N; i++) {
int j = upper_bound(Stars, Stars + N,
PP(Stars[i].fi + D, P(INT_MAX, INT_MAX))) -
Stars;
ll w = -maxx.getMin(i, j) - minx.getMin(i, j);
ll h = -maxy.getMin(i, j) - miny.getMin(i, j);
ans = max(ans, h * w);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct SegTree {
static const int N = 1 << 18;
int *dat;
SegTree() {
dat = new int[N * 2 - 1];
for (int i = 0; i < N * 2 - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int x) {
k += N - 1;
dat[k] = min(dat[k], x);
while (k) {
k = (k - 1) / 2;
dat[k] = min(dat[k], x);
}
}
int getMin(int a, int b, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
int m = (l + r) / 2;
int vl = getMin(a, b, k * 2 + 1, l, m);
int vr = getMin(a, b, k * 2 + 2, m, r);
return min(vl, vr);
}
};
typedef pair<int, int> P;
typedef pair<int, P> PP;
#define fi first
#define se second
typedef long long ll;
int N, D;
PP Stars[200000];
SegTree minx, miny, maxx, maxy;
int main() {
scanf("%d%d", &N, &D);
for (int i = 0; i < N; i++) {
int x, y, b;
scanf("%d%d%d", &x, &y, &b);
Stars[i] = PP(b, P(x, y));
}
sort(Stars, Stars + N);
for (int i = 0; i < N; i++) {
minx.update(i, Stars[i].se.fi);
miny.update(i, Stars[i].se.se);
maxx.update(i, -Stars[i].se.fi);
maxy.update(i, -Stars[i].se.se);
}
ll ans = 0;
for (int i = 0; i < N; i++) {
int j = upper_bound(Stars, Stars + N,
PP(Stars[i].fi + D, P(INT_MAX, INT_MAX))) -
Stars;
ll w = -maxx.getMin(i, j) - minx.getMin(i, j);
ll h = -maxy.getMin(i, j) - miny.getMin(i, j);
ans = max(ans, h * w);
}
cout << ans << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | TLE | |
p00298 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;
ll N, C[2000], W[2000];
ll sum[2000], memo[2000][2000];
struct edge {
ll v, dist;
};
struct state {
ll v, cost;
bool operator>(const state s) const { return cost > s.cost; }
};
vector<ll> dijkstra(vector<vector<edge>> &E, ll S) {
vector<ll> dp(E.size(), INF);
priority_queue<state, vector<state>, greater<state>> q;
q.push((state){S, 0});
while (!q.empty()) {
ll v = q.top().v, cost = q.top().cost;
q.pop();
if (dp[v] <= cost)
continue;
dp[v] = cost;
REP(i, 0, E[v].size()) {
ll nv = E[v][i].v, ncost = cost + E[v][i].dist;
if (dp[nv] > ncost)
q.push((state){nv, ncost});
}
}
return dp;
}
ll dfs(ll l, ll r) {
ll &ret = memo[l][r];
if (ret >= 0)
return ret;
if (r - l <= 1)
return ret = 1;
ret = 0;
if (dfs(l + 1, r) && (sum[r] - sum[l + 1] <= C[l]))
ret = 1;
if (dfs(l, r - 1) && (sum[r - 1] - sum[l] <= C[r - 1]))
ret = 1;
return ret;
}
int main(void) {
cin >> N;
REP(i, 0, N) cin >> C[i] >> W[i];
sum[0] = 0;
REP(i, 0, N) sum[i + 1] = sum[i] + W[i];
REP(i, 0, N) REP(j, 0, N + 1) memo[i][j] = -1;
vector<vector<edge>> E(N);
REP(i, 0, N) REP(j, i + 1, N + 1) if (dfs(i, j)) E[i].push_back((edge){j, 1});
cout << dijkstra(E, 0)[N - 1] << endl;
}
| #include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;
ll N, C[2000], W[2000];
ll sum[2000], memo[2000][2000];
struct edge {
ll v, dist;
};
struct state {
ll v, cost;
bool operator>(const state s) const { return cost > s.cost; }
};
vector<ll> dijkstra(vector<vector<edge>> &E, ll S) {
vector<ll> dp(E.size(), INF);
priority_queue<state, vector<state>, greater<state>> q;
q.push((state){S, 0});
while (!q.empty()) {
ll v = q.top().v, cost = q.top().cost;
q.pop();
if (dp[v] <= cost)
continue;
dp[v] = cost;
REP(i, 0, E[v].size()) {
ll nv = E[v][i].v, ncost = cost + E[v][i].dist;
if (dp[nv] > ncost)
q.push((state){nv, ncost});
}
}
return dp;
}
ll dfs(ll l, ll r) {
ll &ret = memo[l][r];
if (ret >= 0)
return ret;
if (r - l <= 1)
return ret = 1;
ret = 0;
if (dfs(l + 1, r) && (sum[r] - sum[l + 1] <= C[l]))
ret = 1;
if (dfs(l, r - 1) && (sum[r - 1] - sum[l] <= C[r - 1]))
ret = 1;
return ret;
}
int main(void) {
cin >> N;
REP(i, 0, N) cin >> C[i] >> W[i];
sum[0] = 0;
REP(i, 0, N) sum[i + 1] = sum[i] + W[i];
REP(i, 0, N) REP(j, 0, N + 1) memo[i][j] = -1;
vector<vector<edge>> E(N + 1);
REP(i, 0, N) REP(j, i, N + 1) if (dfs(i, j)) E[i].push_back((edge){j, 1});
cout << dijkstra(E, 0)[N] << endl;
}
| replace | 67 | 70 | 67 | 70 | 0 | |
p00298 | C++ | Runtime Error | #include "bits/stdc++.h"
#define REP(i, n, N) for (int i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= n; i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 1e9;
int dp[310][310];
int N;
int C[1010], W[1010];
int sum[1010];
int main() {
cin >> N;
REP(i, 0, N) { cin >> C[i] >> W[i]; }
REP(i, 0, N) REP(j, i, N) dp[i][j] = j - i + 1;
REP(i, 0, N) sum[i + 1] = sum[i] + W[i];
REP(k, 1, N) {
REP(L, 0, N - k) {
int R = L + k;
if (dp[L + 1][R] == 1 && sum[R + 1] - sum[L + 1] <= C[L]) {
dp[L][R] = min(dp[L][R], dp[L + 1][R]);
}
if (dp[L][R - 1] == 1 && sum[R] - sum[L] <= C[R]) {
dp[L][R] = min(dp[L][R], dp[L][R - 1]);
}
REP(i, L, R) { dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R]); }
}
}
p(dp[0][N - 1]);
return 0;
}
| #include "bits/stdc++.h"
#define REP(i, n, N) for (int i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= n; i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 1e9;
int dp[1010][1010];
int N;
int C[1010], W[1010];
int sum[1010];
int main() {
cin >> N;
REP(i, 0, N) { cin >> C[i] >> W[i]; }
REP(i, 0, N) REP(j, i, N) dp[i][j] = j - i + 1;
REP(i, 0, N) sum[i + 1] = sum[i] + W[i];
REP(k, 1, N) {
REP(L, 0, N - k) {
int R = L + k;
if (dp[L + 1][R] == 1 && sum[R + 1] - sum[L + 1] <= C[L]) {
dp[L][R] = min(dp[L][R], dp[L + 1][R]);
}
if (dp[L][R - 1] == 1 && sum[R] - sum[L] <= C[R]) {
dp[L][R] = min(dp[L][R], dp[L][R - 1]);
}
REP(i, L, R) { dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R]); }
}
}
p(dp[0][N - 1]);
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p00299 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
const auto INF = numeric_limits<T>::max();
vector<T> dist(V, INF);
dist[s] = 0;
for (int i = 0; i < V - 1; i++) {
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
}
}
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
if (dist[e.src] + e.cost < dist[e.to])
return vector<T>();
}
return dist;
}
int main() {
int N, C;
int A[200], O[200], B[200], S[200], D[200];
cin >> N >> C;
vector<int> undefined;
for (int i = 0; i < C; i++) {
string str;
cin >> str;
int tail = 0, a = 0, b = 0, o, s, d = 0;
while (isdigit(str[tail]))
a = a * 10 + str[tail++] - '0';
if (str[tail] == '*')
o = 2;
else if (str[tail] == '<')
o = 0, ++tail;
else
o = 1, ++tail;
++tail;
while (isdigit(str[tail]))
b = b * 10 + str[tail++] - '0';
if (str[tail] == '+')
s = 0;
else
s = 1;
++tail;
while (tail < str.size())
d = d * 10 + str[tail++] - '0';
A[i] = --a, B[i] = --b, O[i] = o, S[i] = s, D[i] = d;
if (o == 2)
undefined.push_back(i);
}
int ret = -1;
for (int i = 0; i < (1 << undefined.size()); i++) {
for (int j = 0; j < undefined.size(); j++)
O[undefined[j]] = (i >> j) & 1;
Edges<int> es;
for (int k = 0; k < C; k++) {
if (O[k] == 1)
swap(A[k], B[k]);
es.emplace_back(B[k], A[k], 0);
if (S[k] == 0)
es.emplace_back(B[k], A[k], -D[k]);
else
es.emplace_back(A[k], B[k], D[k]);
if (O[k] == 1)
swap(A[k], B[k]);
}
auto dists = bellman_ford(es, N, 0);
ret = max(ret, *max_element(begin(dists), end(dists)));
}
if (ret >= numeric_limits<int>::max())
cout << "inf" << endl;
else
cout << ret << endl;
}
| #include <bits/stdc++.h>
using namespace std;
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
const auto INF = numeric_limits<T>::max();
vector<T> dist(V, INF);
dist[s] = 0;
for (int i = 0; i < V - 1; i++) {
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
}
}
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
if (dist[e.src] + e.cost < dist[e.to])
return vector<T>();
}
return dist;
}
int main() {
int N, C;
int A[200], O[200], B[200], S[200], D[200];
cin >> N >> C;
vector<int> undefined;
for (int i = 0; i < C; i++) {
string str;
cin >> str;
int tail = 0, a = 0, b = 0, o, s, d = 0;
while (isdigit(str[tail]))
a = a * 10 + str[tail++] - '0';
if (str[tail] == '*')
o = 2;
else if (str[tail] == '<')
o = 0, ++tail;
else
o = 1, ++tail;
++tail;
while (isdigit(str[tail]))
b = b * 10 + str[tail++] - '0';
if (str[tail] == '+')
s = 0;
else
s = 1;
++tail;
while (tail < str.size())
d = d * 10 + str[tail++] - '0';
A[i] = --a, B[i] = --b, O[i] = o, S[i] = s, D[i] = d;
if (o == 2)
undefined.push_back(i);
}
int ret = -1;
for (int i = 0; i < (1 << undefined.size()); i++) {
for (int j = 0; j < undefined.size(); j++)
O[undefined[j]] = (i >> j) & 1;
Edges<int> es;
for (int k = 0; k < C; k++) {
if (O[k] == 1)
swap(A[k], B[k]);
es.emplace_back(B[k], A[k], 0);
if (S[k] == 0)
es.emplace_back(B[k], A[k], -D[k]);
else
es.emplace_back(A[k], B[k], D[k]);
if (O[k] == 1)
swap(A[k], B[k]);
}
auto dists = bellman_ford(es, N, 0);
if (dists.empty() || *min_element(begin(dists), end(dists)) < 0)
continue;
ret = max(ret, *max_element(begin(dists), end(dists)));
}
if (ret >= numeric_limits<int>::max())
cout << "inf" << endl;
else
cout << ret << endl;
}
| insert | 95 | 95 | 95 | 97 | 0 | |
p00302 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int N, R, T;
int P[100];
int pos[100];
int f[100], e[100];
signed main() {
cin >> N >> R >> T;
rep(i, N) cin >> P[i];
rep(t, T) {
rep(i, N) {
pos[i] = (pos[i] + P[i]) % R;
if (f[pos[i]])
f[pos[i]]--;
if (t)
e[pos[i]]++;
}
rep(i, R) {
f[i] += e[i];
e[i] = 0;
}
}
int ans = 0;
rep(i, R) ans += f[i];
cout << ans + N << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int N, R, T;
int P[100];
int pos[100];
int f[1000], e[1000];
signed main() {
cin >> N >> R >> T;
rep(i, N) cin >> P[i];
rep(t, T) {
rep(i, N) {
pos[i] = (pos[i] + P[i]) % R;
if (f[pos[i]])
f[pos[i]]--;
if (t)
e[pos[i]]++;
}
rep(i, R) {
f[i] += e[i];
e[i] = 0;
}
}
int ans = 0;
rep(i, R) ans += f[i];
cout << ans + N << endl;
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p00303 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool dfs(int v, int const s, vector<vector<int>> const &es,
vector<bool> &visited) {
visited[v] = true;
bool res = false;
for (auto &u : es[v]) {
if (!visited[u]) {
res |= dfs(u, s, es, visited);
} else if (visited[v] && u == s) {
res = true;
break;
}
}
return res;
}
int main() {
int n;
cin >> n;
vector<vector<int>> es(200);
for (int i = 0; i < n; ++i) {
int u, d;
string s;
cin >> u >> s >> d;
d += 100;
if (s == "lock") {
es[d].push_back(u);
} else {
es[u].push_back(d);
}
}
bool res = false;
for (int i = 0; i < 101; ++i) {
vector<bool> visited(210);
res |= dfs(i, i, es, visited);
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
bool dfs(int v, int const s, vector<vector<int>> const &es,
vector<bool> &visited) {
visited[v] = true;
bool res = false;
for (auto &u : es[v]) {
if (!visited[u]) {
res |= dfs(u, s, es, visited);
} else if (visited[v] && u == s) {
res = true;
break;
}
}
return res;
}
int main() {
int n;
cin >> n;
vector<vector<int>> es(210);
for (int i = 0; i < n; ++i) {
int u, d;
string s;
cin >> u >> s >> d;
d += 100;
if (s == "lock") {
es[d].push_back(u);
} else {
es[u].push_back(d);
}
}
bool res = false;
for (int i = 0; i < 101; ++i) {
vector<bool> visited(210);
res |= dfs(i, i, es, visited);
}
cout << res << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p00303 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
void stronglyConnectedComponents(const vector<vector<int>> &edges,
vector<int> &indexConvert,
vector<vector<int>> &nodesOut) {
const int n = edges.size();
vector<int> num(n, -1), low(n, -1);
vector<bool> isStk(n, false);
stack<int> stk;
int cnt = -1;
nodesOut.clear();
for (int i = 0; i < n; ++i) {
stack<pair<int, unsigned>> arg;
arg.push(make_pair(i, 0));
while (!arg.empty()) {
int v = arg.top().first;
unsigned j = arg.top().second;
arg.pop();
if (j == 0) {
if (num[v] != -1)
continue;
num[v] = low[v] = ++cnt;
stk.push(v);
isStk[v] = true;
} else {
int w = edges[v][j - 1];
if (isStk[w])
low[v] = min(low[v], low[w]);
}
if (j < edges[v].size()) {
arg.push(make_pair(v, j + 1));
int w = edges[v][j];
arg.push(make_pair(w, 0));
} else if (low[v] == num[v]) {
nodesOut.push_back(vector<int>());
for (;;) {
int w = stk.top();
stk.pop();
isStk[w] = false;
nodesOut.back().push_back(w);
if (v == w)
break;
}
}
}
}
reverse(nodesOut.begin(),
nodesOut.end()); // DAG???????????????????????¢?????????
const int m = nodesOut.size();
indexConvert.resize(n);
for (int i = 0; i < m; ++i) {
for (unsigned j = 0; j < nodesOut[i].size(); ++j)
indexConvert[nodesOut[i][j]] = i;
}
}
int main() {
int n;
cin >> n;
vector<vector<int>> edges(200);
for (int i = 0; i < n; ++i) {
int u, d;
string s;
cin >> u >> s >> d;
if (s == "wait")
edges[u].push_back(d + 100);
else
edges[d + 100].push_back(u);
}
vector<int> indexConvert;
vector<vector<int>> nodesOut;
stronglyConnectedComponents(edges, indexConvert, nodesOut);
if (nodesOut.size() == 200)
cout << 0 << endl;
else
cout << 1 << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
void stronglyConnectedComponents(const vector<vector<int>> &edges,
vector<int> &indexConvert,
vector<vector<int>> &nodesOut) {
const int n = edges.size();
vector<int> num(n, -1), low(n, -1);
vector<bool> isStk(n, false);
stack<int> stk;
int cnt = -1;
nodesOut.clear();
for (int i = 0; i < n; ++i) {
stack<pair<int, unsigned>> arg;
arg.push(make_pair(i, 0));
while (!arg.empty()) {
int v = arg.top().first;
unsigned j = arg.top().second;
arg.pop();
if (j == 0) {
if (num[v] != -1)
continue;
num[v] = low[v] = ++cnt;
stk.push(v);
isStk[v] = true;
} else {
int w = edges[v][j - 1];
if (isStk[w])
low[v] = min(low[v], low[w]);
}
if (j < edges[v].size()) {
arg.push(make_pair(v, j + 1));
int w = edges[v][j];
arg.push(make_pair(w, 0));
} else if (low[v] == num[v]) {
nodesOut.push_back(vector<int>());
for (;;) {
int w = stk.top();
stk.pop();
isStk[w] = false;
nodesOut.back().push_back(w);
if (v == w)
break;
}
}
}
}
reverse(nodesOut.begin(),
nodesOut.end()); // DAG???????????????????????¢?????????
const int m = nodesOut.size();
indexConvert.resize(n);
for (int i = 0; i < m; ++i) {
for (unsigned j = 0; j < nodesOut[i].size(); ++j)
indexConvert[nodesOut[i][j]] = i;
}
}
int main() {
int n;
cin >> n;
vector<vector<int>> edges(200);
for (int i = 0; i < n; ++i) {
int u, d;
string s;
cin >> u >> s >> d;
--u;
--d;
if (s == "wait")
edges[u].push_back(d + 100);
else
edges[d + 100].push_back(u);
}
vector<int> indexConvert;
vector<vector<int>> nodesOut;
stronglyConnectedComponents(edges, indexConvert, nodesOut);
if (nodesOut.size() == 200)
cout << 0 << endl;
else
cout << 1 << endl;
return 0;
} | insert | 93 | 93 | 93 | 95 | 0 | |
p00303 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
vector<int> G[240];
int dist[240];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
string S;
cin >> a >> S >> b;
a--;
b--;
if (S == "wait") {
G[a].push_back(b + 120);
}
if (S == "lock") {
G[b + 120].push_back(a);
}
}
int C = 0;
for (int i = 0; i < 2 * n; i++) {
queue<int> Q;
for (int j = 0; j < 240; j++)
dist[j] = 0;
Q.push(i);
int cnt = 0;
while (!Q.empty()) {
cnt++;
int a1 = Q.front();
Q.pop();
if (cnt >= 100000) {
C = 1;
break;
}
for (int j = 0; j < G[a1].size(); j++) {
if (dist[G[a1][j]] > dist[a1] - 1) {
dist[G[a1][j]] = dist[a1] - 1;
Q.push(G[a1][j]);
}
}
}
}
cout << C << endl;
return 0;
} | #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
vector<int> G[240];
int dist[240];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
string S;
cin >> a >> S >> b;
a--;
b--;
if (S == "wait") {
G[a].push_back(b + 120);
}
if (S == "lock") {
G[b + 120].push_back(a);
}
}
int C = 0;
for (int i = 0; i < 240; i++) {
queue<int> Q;
for (int j = 0; j < 240; j++)
dist[j] = 0;
Q.push(i);
int cnt = 0;
while (!Q.empty()) {
cnt++;
int a1 = Q.front();
Q.pop();
if (cnt >= 100000) {
C = 1;
break;
}
for (int j = 0; j < G[a1].size(); j++) {
if (dist[G[a1][j]] > dist[a1] - 1) {
dist[G[a1][j]] = dist[a1] - 1;
Q.push(G[a1][j]);
}
}
}
}
cout << C << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p00303 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define PB push_back
#define MP make_pair
typedef pair<int, int> pii;
int n;
vector<int> rods[200];
bool visited[200];
int nw;
bool chk(int pl) {
visited[pl] = true;
REP(i, rods[pl].size()) {
int k = rods[pl][i];
if (k == nw)
return true;
if (visited[k])
continue;
if (chk(k))
return true;
}
return false;
}
int main() {
scanf("%d", &n);
REP(i, n) {
int u, d;
char s[5];
scanf("%d%s%d", &u, s, &d);
u--;
d--;
if (s[0] == 'l')
rods[d + 100].PB(u);
else
rods[u].PB(d + 100);
}
REP(i, n) {
nw = i;
fill(visited, visited + 200, false);
if (chk(nw)) {
printf("1\n");
return 0;
}
}
printf("0\n");
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define PB push_back
#define MP make_pair
typedef pair<int, int> pii;
int n;
vector<int> rods[200];
bool visited[200];
int nw;
bool chk(int pl) {
visited[pl] = true;
REP(i, rods[pl].size()) {
int k = rods[pl][i];
if (k == nw)
return true;
if (visited[k])
continue;
if (chk(k))
return true;
}
return false;
}
int main() {
scanf("%d", &n);
REP(i, n) {
int u, d;
char s[5];
scanf("%d%s%d", &u, s, &d);
u--;
d--;
if (s[0] == 'l')
rods[d + 100].PB(u);
else
rods[u].PB(d + 100);
}
REP(i, 100) {
nw = i;
fill(visited, visited + 200, false);
if (chk(nw)) {
printf("1\n");
return 0;
}
}
printf("0\n");
} | replace | 42 | 43 | 42 | 43 | 0 | |
p00303 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
vector<int> g[200];
int main() {
int n;
cin >> n;
REP(i, n) {
int a, b;
string str;
cin >> a >> str >> b;
a--;
b--;
b += 100;
if (str == "lock")
g[b].push_back(a);
else
g[a].push_back(b);
}
bool done[200];
bool flag = false;
REP(i, n) {
fill(done, done + 200, false);
int st = i + 100;
queue<int> que;
REP(i, g[st].size()) que.push(g[st][i]);
while (!que.empty()) {
int now = que.front();
que.pop();
if (done[now])
continue;
done[now] = true;
if (now == st) {
flag = true;
break;
}
REP(i, g[now].size()) que.push(g[now][i]);
}
if (flag)
break;
}
puts(flag ? "1" : "0");
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
vector<int> g[200];
int main() {
int n;
cin >> n;
REP(i, n) {
int a, b;
string str;
cin >> a >> str >> b;
a--;
b--;
b += 100;
if (str == "lock")
g[b].push_back(a);
else
g[a].push_back(b);
}
bool done[200];
bool flag = false;
REP(i, 100) {
fill(done, done + 200, false);
int st = i + 100;
queue<int> que;
REP(i, g[st].size()) que.push(g[st][i]);
while (!que.empty()) {
int now = que.front();
que.pop();
if (done[now])
continue;
done[now] = true;
if (now == st) {
flag = true;
break;
}
REP(i, g[now].size()) que.push(g[now][i]);
}
if (flag)
break;
}
puts(flag ? "1" : "0");
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p00305 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int k[1000][1000], x[1000][1000], n, cnt, maxn = -10000000;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &k[i][j]);
}
}
for (int i = 1; i <= n; i++) {
cnt = 0;
for (int j = 1; j <= n; j++) {
cnt += k[i][j];
x[i][j] = cnt + x[i - 1][j];
}
}
if (n <= 200) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = i + 1; k <= n; k++) {
for (int l = j + 1; l <= n; l++) {
if (k - i >= 3 && l - j >= 3) {
maxn = max(maxn, (x[i][j] + x[k][l] - x[i][l] - x[k][j]) -
(x[i + 1][j + 1] + x[k - 1][l - 1] -
x[i + 1][l - 1] - x[k - 1][j + 1]));
} else {
maxn = max(maxn, x[i][j] + x[k][l] - x[i][l] - x[k][j]);
}
}
}
}
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = i + 1; k <= n; k++) {
for (int l = j + 1; l <= n; l++) {
if (k - i >= 220 && l - j >= 220) {
maxn = max(maxn, (x[i][j] + x[k][l] - x[i][l] - x[k][j]) -
(x[i + 1][j + 1] + x[k - 1][l - 1] -
x[i + 1][l - 1] - x[k - 1][j + 1]));
}
}
}
}
}
}
cout << maxn << endl;
} | #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int k[1000][1000], x[1000][1000], n, cnt, maxn = -10000000;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &k[i][j]);
}
}
for (int i = 1; i <= n; i++) {
cnt = 0;
for (int j = 1; j <= n; j++) {
cnt += k[i][j];
x[i][j] = cnt + x[i - 1][j];
}
}
if (n <= 200) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = i + 1; k <= n; k++) {
for (int l = j + 1; l <= n; l++) {
if (k - i >= 3 && l - j >= 3) {
maxn = max(maxn, (x[i][j] + x[k][l] - x[i][l] - x[k][j]) -
(x[i + 1][j + 1] + x[k - 1][l - 1] -
x[i + 1][l - 1] - x[k - 1][j + 1]));
} else {
maxn = max(maxn, x[i][j] + x[k][l] - x[i][l] - x[k][j]);
}
}
}
}
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = i + 1; k <= n; k++) {
if (k - i >= 180) {
for (int l = j + 1; l <= n; l++) {
if (l - j >= 180) {
maxn = max(maxn, (x[i][j] + x[k][l] - x[i][l] - x[k][j]) -
(x[i + 1][j + 1] + x[k - 1][l - 1] -
x[i + 1][l - 1] - x[k - 1][j + 1]));
}
}
}
}
}
}
}
cout << maxn << endl;
} | replace | 39 | 44 | 39 | 46 | TLE | |
p00305 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int p[333][333];
int yoko[333][333];
int tate[333][333];
int dp[301][301][301];
signed main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> p[i][j];
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
sum += p[i][j];
yoko[i][j] = sum;
}
sum = 0;
for (int j = 0; j < n; j++) {
sum += p[j][i];
tate[j][i] = sum;
}
}
int INF = 100000000;
fill_n(**dp, 333 * 333 * 333, INF);
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = n - 1; k >= 0; k--) {
dp[i][j][k] =
yoko[i][k] + yoko[j][k] + tate[j][k] - tate[i][k] - p[j][k];
if (i == j) {
dp[i][j][k] -= yoko[i][k];
dp[i][j][k] += p[j][k];
}
if (k < n - 1)
dp[i][j][k] = max(dp[i][j][k], dp[i][j][k + 1]);
// cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
}
}
}
int ans = -INF;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = 0; k < n; k++) {
int sum = tate[j][k] - tate[i][k] + p[i][k];
if (k < n - 1) {
int tmp = sum;
tmp += dp[i][j][k + 1];
tmp -= (yoko[i][k] + yoko[j][k]);
if (i == j)
tmp += yoko[i][k];
sum = max(sum, tmp);
}
ans = max(ans, sum);
// cout<<i<<" "<<j<<" "<<k<<" "<<ans<<endl;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int p[333][333];
int yoko[333][333];
int tate[333][333];
int dp[301][301][301];
signed main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> p[i][j];
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
sum += p[i][j];
yoko[i][j] = sum;
}
sum = 0;
for (int j = 0; j < n; j++) {
sum += p[j][i];
tate[j][i] = sum;
}
}
int INF = 100000000;
fill_n(**dp, 301 * 301 * 301, INF);
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = n - 1; k >= 0; k--) {
dp[i][j][k] =
yoko[i][k] + yoko[j][k] + tate[j][k] - tate[i][k] - p[j][k];
if (i == j) {
dp[i][j][k] -= yoko[i][k];
dp[i][j][k] += p[j][k];
}
if (k < n - 1)
dp[i][j][k] = max(dp[i][j][k], dp[i][j][k + 1]);
// cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
}
}
}
int ans = -INF;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = 0; k < n; k++) {
int sum = tate[j][k] - tate[i][k] + p[i][k];
if (k < n - 1) {
int tmp = sum;
tmp += dp[i][j][k + 1];
tmp -= (yoko[i][k] + yoko[j][k]);
if (i == j)
tmp += yoko[i][k];
sum = max(sum, tmp);
}
ans = max(ans, sum);
// cout<<i<<" "<<j<<" "<<k<<" "<<ans<<endl;
}
}
}
cout << ans << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | -11 | |
p00305 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < eps)
int N;
int f[305][305], imos[305][305];
int l[305], r[305];
int sum(int i, int j, int k) {
return imos[j][k] - imos[j][k - 1] - imos[i - 1][k] + imos[i - 1][k - 1];
}
int add(int i, int j, int k) {
if (i == j)
return f[i][k];
return f[i][k] + f[j][k];
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
scanf("%d", &f[i][j]);
imos[i][j] = f[i][j];
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
imos[i][j + 1] += imos[i][j];
}
}
for (int j = 1; j <= N; j++) {
for (int i = 1; i <= N; i++) {
imos[i + 1][j] += imos[i][j];
}
}
while (1) {
int x, y, z;
cin >> x >> y >> z;
cout << sum(x, y, z) << ' ' << add(x, y, z) << endl;
}
int ans = -INF;
for (int i = 1; i <= N; i++) {
for (int j = i; j <= N; j++) {
l[1] = sum(i, j, 1);
for (int k = 1; k <= N; k++)
ans = max(ans, sum(i, j, k));
for (int k = 2; k <= N; k++)
l[k] = max(l[k - 1] + add(i, j, k), sum(i, j, k));
r[N] = sum(i, j, N);
for (int k = N - 1; k >= 1; k--)
r[k] = max(r[k + 1] + add(i, j, k), sum(i, j, k));
for (int k = 1; k < N; k++)
ans = max(ans, l[k] + r[k + 1]);
}
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < eps)
int N;
int f[305][305], imos[305][305];
int l[305], r[305];
int sum(int i, int j, int k) {
return imos[j][k] - imos[j][k - 1] - imos[i - 1][k] + imos[i - 1][k - 1];
}
int add(int i, int j, int k) {
if (i == j)
return f[i][k];
return f[i][k] + f[j][k];
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
scanf("%d", &f[i][j]);
imos[i][j] = f[i][j];
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
imos[i][j + 1] += imos[i][j];
}
}
for (int j = 1; j <= N; j++) {
for (int i = 1; i <= N; i++) {
imos[i + 1][j] += imos[i][j];
}
}
int ans = -INF;
for (int i = 1; i <= N; i++) {
for (int j = i; j <= N; j++) {
l[1] = sum(i, j, 1);
for (int k = 1; k <= N; k++)
ans = max(ans, sum(i, j, k));
for (int k = 2; k <= N; k++)
l[k] = max(l[k - 1] + add(i, j, k), sum(i, j, k));
r[N] = sum(i, j, N);
for (int k = N - 1; k >= 1; k--)
r[k] = max(r[k + 1] + add(i, j, k), sum(i, j, k));
for (int k = 1; k < N; k++)
ans = max(ans, l[k] + r[k + 1]);
}
}
printf("%d\n", ans);
return 0;
} | delete | 61 | 66 | 61 | 61 | -11 | |
p00306 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
struct Point {
double x, y, z;
Point(double x, double y, double z) : x(x), y(y), z(z) {}
Point() {}
Point &operator+=(const Point &a) {
x += a.x;
y += a.y;
z += a.z;
return *this;
}
Point &operator-=(const Point &a) {
x -= a.x;
y -= a.y;
z -= a.z;
return *this;
}
Point &operator*=(const double &a) {
x *= a;
y *= a;
z *= a;
return *this;
}
Point operator+(const Point &a) const {
return Point(x + a.x, y + a.y, z + a.z);
}
Point operator-(const Point &a) const {
return Point(x - a.x, y - a.y, z - a.z);
}
Point operator*(const double &a) const { return Point(a * x, a * y, a * z); }
Point operator-() { return Point(-x, -y, -z); }
};
double dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
Point cross(const Point &a, const Point &b) {
return Point(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x);
}
double abs(const Point &a) { return sqrt(dot(a, a)); }
Point unit(const Point &a) { return a * (1 / abs(a)); }
bool operator==(const Point &a, const Point &b) { return abs(a - b) < EPS; }
Point projectionLP3(Point p, Point q, Point c) {
double t = dot(unit(q - p), c - p);
return p + unit(q - p) * t;
}
double distanceSP3(Point p, Point q, Point c) {
Point r = projectionLP3(p, q, c);
if (dot(q - p, r - p) < 0)
return abs(c - p);
if (dot(p - q, r - q) < 0)
return abs(c - q);
return abs(c - r);
}
pair<Point, Point> calcpos(double t, double m) {
using P2d = complex<double>;
double arg1 = m * PI / 180 + t / 2500000 * 2 * PI;
P2d moon2d = P2d(380000, 0) * P2d(cos(arg1), sin(arg1));
Point moon = Point(moon2d.real(), moon2d.imag(), 0);
double arg2 = t / 7200 * 2 * PI;
P2d kaguya2d = P2d(0, 1900) * P2d(cos(arg2), sin(arg2));
Point kaguya = moon + Point(kaguya2d.real(), 0, kaguya2d.imag());
return make_pair(moon, kaguya);
}
int main() {
cout << fixed << setprecision(3);
double m, t;
cin >> m >> t;
t *= 60;
double dt = 1e-2;
double ans = 0;
Point origin(0, 0, 0);
for (double time = dt / 2; time < t; time += dt) {
pair<Point, Point> pos = calcpos(time, m);
if (distanceSP3(origin, pos.second, pos.first) < 1800) {
ans += dt;
}
}
cout << fixed << setprecision(3);
cout << ans / 60 << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
struct Point {
double x, y, z;
Point(double x, double y, double z) : x(x), y(y), z(z) {}
Point() {}
Point &operator+=(const Point &a) {
x += a.x;
y += a.y;
z += a.z;
return *this;
}
Point &operator-=(const Point &a) {
x -= a.x;
y -= a.y;
z -= a.z;
return *this;
}
Point &operator*=(const double &a) {
x *= a;
y *= a;
z *= a;
return *this;
}
Point operator+(const Point &a) const {
return Point(x + a.x, y + a.y, z + a.z);
}
Point operator-(const Point &a) const {
return Point(x - a.x, y - a.y, z - a.z);
}
Point operator*(const double &a) const { return Point(a * x, a * y, a * z); }
Point operator-() { return Point(-x, -y, -z); }
};
double dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
Point cross(const Point &a, const Point &b) {
return Point(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x);
}
double abs(const Point &a) { return sqrt(dot(a, a)); }
Point unit(const Point &a) { return a * (1 / abs(a)); }
bool operator==(const Point &a, const Point &b) { return abs(a - b) < EPS; }
Point projectionLP3(Point p, Point q, Point c) {
double t = dot(unit(q - p), c - p);
return p + unit(q - p) * t;
}
double distanceSP3(Point p, Point q, Point c) {
Point r = projectionLP3(p, q, c);
if (dot(q - p, r - p) < 0)
return abs(c - p);
if (dot(p - q, r - q) < 0)
return abs(c - q);
return abs(c - r);
}
pair<Point, Point> calcpos(double t, double m) {
using P2d = complex<double>;
double arg1 = m * PI / 180 + t / 2500000 * 2 * PI;
P2d moon2d = P2d(380000, 0) * P2d(cos(arg1), sin(arg1));
Point moon = Point(moon2d.real(), moon2d.imag(), 0);
double arg2 = t / 7200 * 2 * PI;
P2d kaguya2d = P2d(0, 1900) * P2d(cos(arg2), sin(arg2));
Point kaguya = moon + Point(kaguya2d.real(), 0, kaguya2d.imag());
return make_pair(moon, kaguya);
}
int main() {
cout << fixed << setprecision(3);
double m, t;
cin >> m >> t;
t *= 60;
double dt = 1e-1;
double ans = 0;
Point origin(0, 0, 0);
for (double time = dt / 2; time < t; time += dt) {
pair<Point, Point> pos = calcpos(time, m);
if (distanceSP3(origin, pos.second, pos.first) < 1800) {
ans += dt;
}
}
cout << fixed << setprecision(3);
cout << ans / 60 << endl;
return 0;
}
| replace | 84 | 85 | 84 | 85 | TLE | |
p00314 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int &t : p)
cin >> t;
for (int A = 100; A >= 0; A--) {
int c = 0;
for (int t : p)
if (t >= A)
c++;
if (c >= A) {
cout << A << endl;
break;
}
}
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int &t : p)
cin >> t;
for (int A = 100; A >= 0; A--) {
int c = 0;
for (int t : p)
if (t >= A)
c++;
if (c >= A) {
cout << A << endl;
break;
}
}
return 0;
} | insert | 21 | 21 | 21 | 22 | 0 | |
p00314 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
int n;
cin >> n;
vector<int> vec;
int ma = 0;
for (int a = 0; a < n; a++) {
int b;
cin >> b;
vec.push_back(b);
ma = max(ma, b);
}
for (int a = ma; a >= 0; a--) {
int ins = 0;
for (int b = 0; b < n; b++) {
if (vec.at(b) >= a) {
ins++;
}
}
if (ins >= a) {
cout << a << endl;
return a;
}
}
cout << 0 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
int n;
cin >> n;
vector<int> vec;
int ma = 0;
for (int a = 0; a < n; a++) {
int b;
cin >> b;
vec.push_back(b);
ma = max(ma, b);
}
for (int a = ma; a >= 0; a--) {
int ins = 0;
for (int b = 0; b < n; b++) {
if (vec.at(b) >= a) {
ins++;
}
}
if (ins >= a) {
cout << a << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | 4 | |
p00316 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int s[100001], v[100001], r[100001];
void init() {
rep(i, 0, 100001) {
s[i] = i;
r[i] = 0;
}
}
int find(int x) {
if (s[x] == x) {
return x;
} else {
return s[x] = find(s[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (r[x] < r[y]) {
s[x] = y;
if (v[x])
v[y] = v[x];
} else {
s[y] = x;
if (r[x] == r[y])
r[x]++;
if (v[y])
v[x] = v[y];
}
}
int main() {
int n, m, k;
cin >> n >> m >> k;
int a[100001], b[100001], c[100001];
init();
rep(i, 0, k) cin >> a[i] >> b[i] >> c[i];
rep(i, 0, k) {
if (a[i] == 1) {
int bb = find(b[i]);
int cc = find(c[i]);
if (v[bb] && v[cc] && v[bb] != v[cc]) {
cout << i + 1 << endl;
return 0;
}
unite(bb, cc);
} else {
int bb = find(b[i]);
if (v[bb] && v[bb] != c[i]) {
cout << i + 1 << endl;
return 0;
}
v[bb] = c[i];
}
}
cout << 0 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int s[100001], v[100001], r[100001];
void init() {
rep(i, 0, 100001) {
s[i] = i;
r[i] = 0;
}
}
int find(int x) {
if (s[x] == x) {
return x;
} else {
return s[x] = find(s[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (r[x] < r[y]) {
s[x] = y;
if (v[x])
v[y] = v[x];
} else {
s[y] = x;
if (r[x] == r[y])
r[x]++;
if (v[y])
v[x] = v[y];
}
}
int main() {
int n, m, k;
cin >> n >> m >> k;
int a[200001], b[200001], c[200001];
init();
rep(i, 0, k) cin >> a[i] >> b[i] >> c[i];
rep(i, 0, k) {
if (a[i] == 1) {
int bb = find(b[i]);
int cc = find(c[i]);
if (v[bb] && v[cc] && v[bb] != v[cc]) {
cout << i + 1 << endl;
return 0;
}
unite(bb, cc);
} else {
int bb = find(b[i]);
if (v[bb] && v[bb] != c[i]) {
cout << i + 1 << endl;
return 0;
}
v[bb] = c[i];
}
}
cout << 0 << endl;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p00317 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// #include<chrono>
#include <random>
using namespace std;
typedef long long int llint;
const int big = 1e9 + 100000;
const int mod = 1e9 + 7;
const long double pai = 3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
template <class T, class U> void mineq(T &a, U b) {
if (a > b) {
a = b;
}
}
template <class T, class U> void maxeq(T &a, U b) {
if (a < b) {
a = b;
}
}
int main(void) {
int i, n, m;
cin >> n >> m;
vector<string> word(n);
vector<string> drow(n);
for (i = 0; i < n; i++) {
cin >> word[i];
drow[i] = word[i];
reverse(drow[i].begin(), drow[i].end());
}
sort(word.begin(), word.end());
sort(drow.begin(), drow.end());
for (i = 0; i < m; i++) {
string sla;
cin >> sla;
int ans = 0, bas = -1, rec = 0, kak = 0;
if (sla[0] == '*') {
reverse(sla.begin(), sla.end());
rec = 1;
}
if (sla.back() == '*') {
kak++;
sla.pob();
}
for (int j = 0; j < sla.size(); j++) {
if (sla[j] == '?') {
bas = j;
break;
}
}
string slap = sla;
for (char c = 'a'; c <= 'z'; c++) {
if (bas != -1) {
sla[bas] = c;
slap[bas] = c;
}
slap.back()++;
if (kak == 1) {
if (rec == 0) {
ans += lower_bound(word.begin(), word.end(), slap) -
lower_bound(word.begin(), word.end(), sla);
} else {
ans += lower_bound(drow.begin(), drow.end(), slap) -
lower_bound(drow.begin(), drow.end(), sla);
}
} else {
if (*lower_bound(word.begin(), word.end(), sla) == sla) {
ans++;
}
}
slap.back()--;
}
if (bas == -1) {
ans /= 26;
}
cout << ans << endl;
}
} | #include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// #include<chrono>
#include <random>
using namespace std;
typedef long long int llint;
const int big = 1e9 + 100000;
const int mod = 1e9 + 7;
const long double pai = 3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
template <class T, class U> void mineq(T &a, U b) {
if (a > b) {
a = b;
}
}
template <class T, class U> void maxeq(T &a, U b) {
if (a < b) {
a = b;
}
}
int main(void) {
int i, n, m;
cin >> n >> m;
vector<string> word(n);
vector<string> drow(n);
for (i = 0; i < n; i++) {
cin >> word[i];
drow[i] = word[i];
reverse(drow[i].begin(), drow[i].end());
}
sort(word.begin(), word.end());
sort(drow.begin(), drow.end());
for (i = 0; i < m; i++) {
string sla;
cin >> sla;
int ans = 0, bas = -1, rec = 0, kak = 0;
if (sla[0] == '*') {
reverse(sla.begin(), sla.end());
rec = 1;
}
if (sla.back() == '*') {
kak++;
sla.pob();
}
for (int j = 0; j < sla.size(); j++) {
if (sla[j] == '?') {
bas = j;
break;
}
}
string slap = sla;
for (char c = 'a'; c <= 'z'; c++) {
if (bas != -1) {
sla[bas] = c;
slap[bas] = c;
}
slap.back()++;
if (kak == 1) {
if (rec == 0) {
ans += lower_bound(word.begin(), word.end(), slap) -
lower_bound(word.begin(), word.end(), sla);
} else {
ans += lower_bound(drow.begin(), drow.end(), slap) -
lower_bound(drow.begin(), drow.end(), sla);
}
} else {
auto it = lower_bound(word.begin(), word.end(), sla);
if (it != word.end() && (*it) == sla) {
ans++;
}
}
slap.back()--;
}
if (bas == -1) {
ans /= 26;
}
cout << ans << endl;
}
} | replace | 87 | 88 | 87 | 89 | 0 | |
p00317 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
struct Trie {
struct Node {
int sum = 0, cnt = 0;
vector<pi> next;
int find(int k) {
for (pi p : next)
if (p.first == k)
return p.second;
return -1;
}
};
vector<Node> nodes;
int sz = 1;
Trie() { nodes.pb(Node()); }
void put(const string &s) { put(s, 0, 0); }
void put(const string &s, int idx, int node) {
int k = s[idx] - 'a', nx = nodes[node].find(k);
if (nx < 0) {
nodes.pb(Node());
nodes[node].next.emplace_back(k, sz++);
}
node = nodes[node].find(k);
nodes[node].sum++;
if (idx == s.size() - 1)
nodes[node].cnt++;
else
put(s, idx + 1, node);
}
int get(const string &s, bool exact) { return get(s, 0, 0, exact); }
int get(const string &s, int idx, int node, bool exact) {
int k = s[idx] - 'a', nx = nodes[node].find(k);
if (nx < 0)
return 0;
node = nodes[node].find(k);
if (idx == s.size() - 1)
return exact ? nodes[node].cnt : nodes[node].sum;
else
return get(s, idx + 1, node, exact);
}
};
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, m;
cin >> n >> m;
vi ans(m);
vector<string> in(n), qu(m);
rep(i, n) cin >> in[i];
rep(i, m) cin >> qu[i];
auto solve = [](string s, Trie *t, bool exact) {
int f = s.find('?');
if (f == s.npos)
return t->get(s, exact);
int ans = 0;
rep(i, 26) {
s[f] = 'a' + i;
ans += t->get(s, exact);
}
return ans;
};
{
Trie *t = new Trie;
rep(i, n) t->put(in[i]);
rep(i, m) {
string s = qu[i];
if (s[0] == '*')
continue;
else if (s[s.size() - 1] == '*') {
s.pop_back();
ans[i] = solve(s, t, 0);
} else
ans[i] = solve(s, t, 1);
}
}
{
Trie *t = new Trie;
rep(i, n) {
reverse(all(in[i]));
t->put(in[i]);
}
rep(i, m) {
string s = qu[i];
if (s[0] == '*') {
reverse(all(s));
s.pop_back();
ans[i] = solve(s, t, 0);
}
cout << ans[i] << endl;
}
}
/*
while(m--){
string s; cin >> s;
if(s[0] == '*'){
reverse(all(s)); s.pop_back();
cout << solve(s, rt, 0) << endl;
}
else if(s[s.size() - 1] == '*'){
s.pop_back();
cout << solve(s, t, 0) << endl;
}
else cout << solve(s, t, 1) << endl;
}
*/
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
struct Trie {
struct Node {
int sum = 0, cnt = 0;
vector<pi> next;
int find(int k) {
for (pi p : next)
if (p.first == k)
return p.second;
return -1;
}
};
vector<Node> nodes;
int sz = 1;
Trie() { nodes.pb(Node()); }
void put(const string &s) { put(s, 0, 0); }
void put(const string &s, int idx, int node) {
int k = s[idx] - 'a', nx = nodes[node].find(k);
if (nx < 0) {
nodes.pb(Node());
nodes[node].next.emplace_back(k, sz++);
}
node = nodes[node].find(k);
nodes[node].sum++;
if (idx == s.size() - 1)
nodes[node].cnt++;
else
put(s, idx + 1, node);
}
int get(const string &s, bool exact) { return get(s, 0, 0, exact); }
int get(const string &s, int idx, int node, bool exact) {
int k = s[idx] - 'a', nx = nodes[node].find(k);
if (nx < 0)
return 0;
node = nodes[node].find(k);
if (idx == s.size() - 1)
return exact ? nodes[node].cnt : nodes[node].sum;
else
return get(s, idx + 1, node, exact);
}
};
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, m;
cin >> n >> m;
vi ans(m);
vector<string> in(n), qu(m);
rep(i, n) cin >> in[i];
rep(i, m) cin >> qu[i];
auto solve = [](string s, Trie *t, bool exact) {
int f = s.find('?');
if (f == s.npos)
return t->get(s, exact);
int ans = 0;
rep(i, 26) {
s[f] = 'a' + i;
ans += t->get(s, exact);
}
return ans;
};
{
Trie *t = new Trie;
rep(i, n) t->put(in[i]);
rep(i, m) {
string s = qu[i];
if (s[0] == '*')
continue;
else if (s[s.size() - 1] == '*') {
s.pop_back();
ans[i] = solve(s, t, 0);
} else
ans[i] = solve(s, t, 1);
}
delete t;
}
{
Trie *t = new Trie;
rep(i, n) {
reverse(all(in[i]));
t->put(in[i]);
}
rep(i, m) {
string s = qu[i];
if (s[0] == '*') {
reverse(all(s));
s.pop_back();
ans[i] = solve(s, t, 0);
}
cout << ans[i] << endl;
}
}
/*
while(m--){
string s; cin >> s;
if(s[0] == '*'){
reverse(all(s)); s.pop_back();
cout << solve(s, rt, 0) << endl;
}
else if(s[s.size() - 1] == '*'){
s.pop_back();
cout << solve(s, t, 0) << endl;
}
else cout << solve(s, t, 1) << endl;
}
*/
return 0;
}
| insert | 141 | 141 | 141 | 142 | MLE | |
p00317 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> T;
const int mod1 = 1000000007;
const int base1 = 1009;
const int mod2 = 1000000007;
const int base2 = 1007;
int N, M;
char s[100000][201];
char d[100000][201];
int ans[100000];
bool rev[100000];
map<pair<int, int>, int> hash1[200];
set<pair<int, int>> endd[200];
T connect(T &hash, char c) {
return (make_pair(1LL * (hash.first + c) * base1 % mod1,
1LL * (hash.second + c) * base2 % mod2));
}
int countStrings(int p, int idx, T val) {
if (d[p][idx] == '\0') {
return (endd[idx - 1].find(val) != endd[idx - 1].end());
} else if (d[p][idx] == '*') {
return (hash1[idx - 1].find(val) != hash1[idx - 1].end()
? hash1[idx - 1][val]
: 0);
} else if (d[p][idx] == '?') {
int ret = 0;
for (char c = 'a'; c <= 'z'; c++) {
ret += countStrings(p, idx + 1, connect(val, c));
}
return (ret);
} else {
return (countStrings(p, idx + 1, connect(val, d[p][idx])));
}
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf(" %s", s[i]);
}
for (int i = 0; i < M; i++) {
scanf(" %s", d[i]);
if (d[i][0] == '*') {
reverse(d[i], d[i] + strlen(d[i]));
rev[i] = true;
}
}
const int BACKET = 500;
for (int i = 0; i < N; i += BACKET) {
for (int j = 0; j < 200; j++) {
hash1[j].clear();
endd[j].clear();
}
for (int k = i; k < min(N, i + BACKET); k++) {
int len = strlen(s[k]);
T val = {0, 0};
for (int j = 0; j < len; j++) {
val = connect(val, s[k][j]);
hash1[j][val]++;
}
endd[len - 1].insert(val);
}
for (int j = 0; j < M; j++) {
if (!rev[j])
ans[j] += countStrings(j, 0, {0, 0});
}
}
for (int i = 0; i < N; i++) {
reverse(s[i], s[i] + strlen(s[i]));
}
for (int i = 0; i < N; i += BACKET) {
for (int j = 0; j < 200; j++) {
hash1[j].clear();
}
for (int k = i; k < min(N, i + BACKET); k++) {
T val(0, 0);
int len = strlen(s[k]);
for (int j = 0; j < len; j++) {
val = connect(val, s[k][j]);
hash1[j][val]++;
}
}
for (int j = 0; j < M; j++) {
if (rev[j])
ans[j] += countStrings(j, 0, {0, 0});
}
}
for (int i = 0; i < M; i++) {
printf("%d\n", ans[i]);
}
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> T;
const int mod1 = 1000000007;
const int base1 = 1009;
const int mod2 = 1000000007;
const int base2 = 1007;
int N, M;
char s[100000][201];
char d[100000][201];
int ans[100000];
bool rev[100000];
map<pair<int, int>, int> hash1[200];
set<pair<int, int>> endd[200];
T connect(T &hash, char c) {
return (make_pair(1LL * (hash.first + c) * base1 % mod1,
1LL * (hash.second + c) * base2 % mod2));
}
int countStrings(int p, int idx, T val) {
if (d[p][idx] == '\0') {
return (endd[idx - 1].find(val) != endd[idx - 1].end());
} else if (d[p][idx] == '*') {
return (hash1[idx - 1].find(val) != hash1[idx - 1].end()
? hash1[idx - 1][val]
: 0);
} else if (d[p][idx] == '?') {
int ret = 0;
for (char c = 'a'; c <= 'z'; c++) {
ret += countStrings(p, idx + 1, connect(val, c));
}
return (ret);
} else {
return (countStrings(p, idx + 1, connect(val, d[p][idx])));
}
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf(" %s", s[i]);
}
for (int i = 0; i < M; i++) {
scanf(" %s", d[i]);
if (d[i][0] == '*') {
reverse(d[i], d[i] + strlen(d[i]));
rev[i] = true;
}
}
const int BACKET = 3000;
for (int i = 0; i < N; i += BACKET) {
for (int j = 0; j < 200; j++) {
hash1[j].clear();
endd[j].clear();
}
for (int k = i; k < min(N, i + BACKET); k++) {
int len = strlen(s[k]);
T val = {0, 0};
for (int j = 0; j < len; j++) {
val = connect(val, s[k][j]);
hash1[j][val]++;
}
endd[len - 1].insert(val);
}
for (int j = 0; j < M; j++) {
if (!rev[j])
ans[j] += countStrings(j, 0, {0, 0});
}
}
for (int i = 0; i < N; i++) {
reverse(s[i], s[i] + strlen(s[i]));
}
for (int i = 0; i < N; i += BACKET) {
for (int j = 0; j < 200; j++) {
hash1[j].clear();
}
for (int k = i; k < min(N, i + BACKET); k++) {
T val(0, 0);
int len = strlen(s[k]);
for (int j = 0; j < len; j++) {
val = connect(val, s[k][j]);
hash1[j][val]++;
}
}
for (int j = 0; j < M; j++) {
if (rev[j])
ans[j] += countStrings(j, 0, {0, 0});
}
}
for (int i = 0; i < M; i++) {
printf("%d\n", ans[i]);
}
} | replace | 56 | 57 | 56 | 57 | TLE | |
p00317 | 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 50000
int N, M;
string WORD[NUM], rev_WORD[NUM];
int calc(const string slate) {
int left, right;
string pattern = slate;
if (pattern[pattern.length() - 1] == '*') {
pattern = pattern.substr(0, pattern.length() - 1);
left = lower_bound(WORD, WORD + N, pattern) - WORD;
pattern.push_back('z' + 1);
right = lower_bound(WORD, WORD + N, pattern) - WORD;
return right - left;
} else if (pattern[0] == '*') {
pattern = pattern.substr(1);
reverse(pattern.begin(), pattern.end());
left = lower_bound(rev_WORD, rev_WORD + N, pattern) - rev_WORD;
pattern.push_back('z' + 1);
right = lower_bound(rev_WORD, rev_WORD + N, pattern) - rev_WORD;
return right - left;
} else {
left = lower_bound(WORD, WORD + N, pattern) - WORD;
if (WORD[left] == slate) {
return 1;
} else {
return 0;
}
}
}
int main() {
scanf("%d %d", &N, &M);
getchar();
for (int i = 0; i < N; i++) {
getline(cin, WORD[i]);
rev_WORD[i] = WORD[i];
reverse(rev_WORD[i].begin(), rev_WORD[i].end());
}
sort(WORD, WORD + N);
sort(rev_WORD, rev_WORD + N);
string slate;
int loc, ans;
for (int loop = 0; loop < M; loop++) {
getline(cin, slate);
loc = -1;
for (int i = 0; i < slate.length(); i++) {
if (slate[i] == '?') {
loc = i;
break;
}
}
if (loc == -1) {
printf("%d\n", calc(slate));
continue;
}
ans = 0;
for (int i = 0; i < 26; i++) {
slate[loc] = 'a' + i;
ans += calc(slate);
}
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 50005
int N, M;
string WORD[NUM], rev_WORD[NUM];
int calc(const string slate) {
int left, right;
string pattern = slate;
if (pattern[pattern.length() - 1] == '*') {
pattern = pattern.substr(0, pattern.length() - 1);
left = lower_bound(WORD, WORD + N, pattern) - WORD;
pattern.push_back('z' + 1);
right = lower_bound(WORD, WORD + N, pattern) - WORD;
return right - left;
} else if (pattern[0] == '*') {
pattern = pattern.substr(1);
reverse(pattern.begin(), pattern.end());
left = lower_bound(rev_WORD, rev_WORD + N, pattern) - rev_WORD;
pattern.push_back('z' + 1);
right = lower_bound(rev_WORD, rev_WORD + N, pattern) - rev_WORD;
return right - left;
} else {
left = lower_bound(WORD, WORD + N, pattern) - WORD;
if (WORD[left] == slate) {
return 1;
} else {
return 0;
}
}
}
int main() {
scanf("%d %d", &N, &M);
getchar();
for (int i = 0; i < N; i++) {
getline(cin, WORD[i]);
rev_WORD[i] = WORD[i];
reverse(rev_WORD[i].begin(), rev_WORD[i].end());
}
sort(WORD, WORD + N);
sort(rev_WORD, rev_WORD + N);
string slate;
int loc, ans;
for (int loop = 0; loop < M; loop++) {
getline(cin, slate);
loc = -1;
for (int i = 0; i < slate.length(); i++) {
if (slate[i] == '?') {
loc = i;
break;
}
}
if (loc == -1) {
printf("%d\n", calc(slate));
continue;
}
ans = 0;
for (int i = 0; i < 26; i++) {
slate[loc] = 'a' + i;
ans += calc(slate);
}
printf("%d\n", ans);
}
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p00317 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
struct RollingHash {
typedef unsigned long long ull;
string S;
ull B;
int len;
vector<ull> hash, p;
RollingHash() {}
RollingHash(string S_, ull B_ = 1000000007LL)
: S(S_), B(B_), len(S.length()), hash(len + 1), p(len + 1) {
hash[0] = 0;
p[0] = 1;
for (int i = 0; i < len; i++) {
hash[i + 1] = hash[i] * B + S[i];
p[i + 1] = p[i] * B;
}
}
// S[l,r)
ull find(int l, int r) { return hash[r] - hash[l] * p[r - l]; }
};
map<uint64, int32> mpf, mpb, mp; // 前が欠けてる,後ろが欠けてる, 欠けてない
RollingHash r;
int main(void) {
int32 N, M;
cin >> N >> M;
REP(i, N) {
string s;
cin >> s;
r = RollingHash(s);
mp[r.find(0, s.size())]++;
FOR(j, 1, s.size()) {
mpf[r.find(j, s.size())]++;
mpb[r.find(0, j)]++;
}
}
REP(i, M) {
string s;
cin >> s;
int32 cq = -1, ca = -1;
REP(j, s.size()) {
if (s[j] == '?')
cq = j;
if (s[j] == '*')
ca = j;
}
int32 res = 0;
for (char c = 'a'; c <= 'z'; c++) {
if (cq != -1)
s[cq] = c;
r = RollingHash(s);
if (ca == -1) {
res += mp[r.find(0, s.size())];
} else if (ca == 0) {
res += mpf[r.find(1, s.size())];
res += mp[r.find(1, s.size())];
} else {
res += mpb[r.find(0, s.size() - 1)];
res += mp[r.find(0, s.size() - 1)];
}
if (cq == -1)
break;
}
cout << res << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
struct RollingHash {
typedef unsigned long long ull;
string S;
ull B;
int len;
vector<ull> hash, p;
RollingHash() {}
RollingHash(string S_, ull B_ = 1000000007LL)
: S(S_), B(B_), len(S.length()), hash(len + 1), p(len + 1) {
hash[0] = 0;
p[0] = 1;
for (int i = 0; i < len; i++) {
hash[i + 1] = hash[i] * B + S[i];
p[i + 1] = p[i] * B;
}
}
// S[l,r)
ull find(int l, int r) { return hash[r] - hash[l] * p[r - l]; }
};
unordered_map<uint64, int32> mpf, mpb,
mp; // 前が欠けてる,後ろが欠けてる, 欠けてない
RollingHash r;
int main(void) {
int32 N, M;
cin >> N >> M;
REP(i, N) {
string s;
cin >> s;
r = RollingHash(s);
mp[r.find(0, s.size())]++;
FOR(j, 1, s.size()) {
mpf[r.find(j, s.size())]++;
mpb[r.find(0, j)]++;
}
}
REP(i, M) {
string s;
cin >> s;
int32 cq = -1, ca = -1;
REP(j, s.size()) {
if (s[j] == '?')
cq = j;
if (s[j] == '*')
ca = j;
}
int32 res = 0;
for (char c = 'a'; c <= 'z'; c++) {
if (cq != -1)
s[cq] = c;
r = RollingHash(s);
if (ca == -1) {
res += mp[r.find(0, s.size())];
} else if (ca == 0) {
res += mpf[r.find(1, s.size())];
res += mp[r.find(1, s.size())];
} else {
res += mpb[r.find(0, s.size() - 1)];
res += mp[r.find(0, s.size() - 1)];
}
if (cq == -1)
break;
}
cout << res << endl;
}
}
| replace | 49 | 50 | 49 | 51 | MLE | |
p00318 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
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.txt"
bool check(vector<pair<ld, ld>> &ps, ld dis) {
map<ld, int> mp;
for (int i = 0; i < ps.size(); ++i) {
auto p(ps[i]);
ld d = sqrt(p.second * p.second - dis * dis);
ld l(p.first - d);
ld r(p.first + d);
mp[l]++;
mp[r]--;
}
int num = 0;
bool flag = false;
for (auto it = mp.begin(); it != mp.end(); ++it) {
auto m(*it);
num += m.second;
if (num == ps.size())
flag = true;
}
return flag;
}
int main() {
int N;
cin >> N;
vector<pair<ld, ld>> ps;
ld amin = 0;
ld amax = 1e18;
for (int i = 0; i < N; ++i) {
int a, b;
cin >> a >> b;
ps.emplace_back(a, b);
amax = min(amax, ld(b));
}
amax -= 1e-9;
int kk = 40;
while (kk--) {
ld amid((amin + amax) / 2);
if (check(ps, amid)) {
amin = amid;
} else {
amax = amid;
}
}
cout << setprecision(10) << fixed << amin << endl;
return 0;
} | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
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.txt"
bool check(vector<pair<ld, ld>> &ps, ld dis) {
map<ld, int> mp;
for (int i = 0; i < ps.size(); ++i) {
auto p(ps[i]);
ld d = sqrt(p.second * p.second - dis * dis);
ld l(p.first - d);
ld r(p.first + d);
mp[l]++;
mp[r]--;
}
int num = 0;
bool flag = false;
for (auto it = mp.begin(); it != mp.end(); ++it) {
auto m(*it);
num += m.second;
if (num == ps.size())
flag = true;
}
return flag;
}
int main() {
int N;
cin >> N;
vector<pair<ld, ld>> ps;
ld amin = 0;
ld amax = 1e18;
for (int i = 0; i < N; ++i) {
int a, b;
cin >> a >> b;
ps.emplace_back(a, b);
amax = min(amax, ld(b));
}
amax -= 1e-9;
int kk = 30;
while (kk--) {
ld amid((amin + amax) / 2);
if (check(ps, amid)) {
amin = amid;
} else {
amax = amid;
}
}
cout << setprecision(10) << fixed << amin << endl;
return 0;
} | replace | 47 | 48 | 47 | 48 | TLE | |
p00318 | C++ | Time Limit Exceeded | // 2分探索, 座標圧縮的な何か, imos法
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
int n;
double x[100000], r[100000];
bool check(double y) {
int i;
vector<double> vec;
static int imos[200001];
rep(i, n) {
if (y >= r[i])
return false;
double width = sqrt(r[i] * r[i] - y * y);
vec.push_back(x[i] - width);
vec.push_back(x[i] + width);
}
sort(vec.begin(), vec.end());
rep(i, 2 * n) imos[i] = 0;
rep(i, n) {
double width = sqrt(r[i] * r[i] - y * y);
int l = lower_bound(vec.begin(), vec.end(), x[i] - width) - vec.begin();
int r = lower_bound(vec.begin(), vec.end(), x[i] + width) - vec.begin();
// 区間l,l+1,…,r-1に1を足す
imos[l]++;
imos[r]--;
}
rep(i, 2 * n) if (i > 0) imos[i] += imos[i - 1];
rep(i, 2 * n) if (imos[i] == n) return true;
return false;
}
int main() {
int i;
cin >> n;
rep(i, n) cin >> x[i] >> r[i];
double st = 0, ed = 1000000, mid; // ooooxxx, [st, ed)
for (i = 0; i < 120; i++) {
mid = (st + ed) / 2;
if (check(mid))
st = mid;
else
ed = mid;
}
printf("%.14f\n", st);
return 0;
}
| // 2分探索, 座標圧縮的な何か, imos法
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
int n;
double x[100000], r[100000];
bool check(double y) {
int i;
vector<double> vec;
static int imos[200001];
rep(i, n) {
if (y >= r[i])
return false;
double width = sqrt(r[i] * r[i] - y * y);
vec.push_back(x[i] - width);
vec.push_back(x[i] + width);
}
sort(vec.begin(), vec.end());
rep(i, 2 * n) imos[i] = 0;
rep(i, n) {
double width = sqrt(r[i] * r[i] - y * y);
int l = lower_bound(vec.begin(), vec.end(), x[i] - width) - vec.begin();
int r = lower_bound(vec.begin(), vec.end(), x[i] + width) - vec.begin();
// 区間l,l+1,…,r-1に1を足す
imos[l]++;
imos[r]--;
}
rep(i, 2 * n) if (i > 0) imos[i] += imos[i - 1];
rep(i, 2 * n) if (imos[i] == n) return true;
return false;
}
int main() {
int i;
cin >> n;
rep(i, n) cin >> x[i] >> r[i];
double st = 0, ed = 1000000, mid; // ooooxxx, [st, ed)
for (i = 0; i < 50; i++) {
mid = (st + ed) / 2;
if (check(mid))
st = mid;
else
ed = mid;
}
printf("%.14f\n", st);
return 0;
}
| replace | 49 | 50 | 49 | 50 | TLE | |
p00321 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 0;
string t;
cin >> n >> m;
vector<int> a(n);
vector<string> s(0);
vector<vector<string>> u(n, vector<string>(0));
for (int i = 0; i < n; i++) {
cin >> a.at(i);
for (int j = 0; j < a.at(i); j++) {
int y = 0;
cin >> t;
u.at(i).push_back(t);
for (int k = 0; k < s.size(); k++) {
if (s.at(k) == t) {
y = 1;
break;
}
}
if (y == 0)
s.push_back(t);
}
sort(u.at(i).begin(), u.at(i).end());
}
sort(s.begin(), s.end());
vector<vector<pair<pair<string, string>, int>>> h(
s.size(), vector<pair<pair<string, string>, int>>(s.size()));
for (int i = 0; i < s.size() - 1; i++) {
for (int j = i + 1; j < s.size(); j++) {
pair<pair<string, string>, int> v;
v.first.first = s.at(i);
v.first.second = s.at(j);
v.second = 0;
h.at(i).at(j) = v;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < a.at(i) - 1; j++) {
for (int k = j + 1; k < a.at(i); k++) {
for (int e = 0; e < s.size() - 1; e++) {
for (int ii = e + 1; ii < s.size(); ii++) {
if (h.at(e).at(ii).first.first == u.at(i).at(j) &&
h.at(e).at(ii).first.second == u.at(i).at(k))
h.at(e).at(ii).second++;
}
}
}
}
}
for (int i = 0; i < s.size() - 1; i++) {
for (int j = i + 1; j < s.size(); j++) {
if (h.at(i).at(j).second >= m)
ans++;
}
}
cout << ans << endl;
for (int i = 0; i < s.size() - 1; i++) {
for (int j = i + 1; j < s.size(); j++) {
if (h.at(i).at(j).second >= m)
cout << h.at(i).at(j).first.first << " " << h.at(i).at(j).first.second
<< endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 0;
string t;
cin >> n >> m;
vector<int> a(n);
vector<string> s(0);
vector<vector<string>> u(n, vector<string>(0));
for (int i = 0; i < n; i++) {
cin >> a.at(i);
for (int j = 0; j < a.at(i); j++) {
int y = 0;
cin >> t;
u.at(i).push_back(t);
for (int k = 0; k < s.size(); k++) {
if (s.at(k) == t) {
y = 1;
break;
}
}
if (y == 0)
s.push_back(t);
}
sort(u.at(i).begin(), u.at(i).end());
}
sort(s.begin(), s.end());
vector<vector<pair<pair<string, string>, int>>> h(
s.size(), vector<pair<pair<string, string>, int>>(s.size()));
for (int i = 0; i < s.size() - 1; i++) {
for (int j = i + 1; j < s.size(); j++) {
pair<pair<string, string>, int> v;
v.first.first = s.at(i);
v.first.second = s.at(j);
v.second = 0;
h.at(i).at(j) = v;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < a.at(i) - 1; j++) {
for (int k = j + 1; k < a.at(i); k++) {
for (int e = 0; e < s.size() - 1; e++) {
if (h.at(e).at(s.size() - 1).first.first == u.at(i).at(j)) {
for (int ii = e + 1; ii < s.size(); ii++) {
if (h.at(e).at(ii).first.first == u.at(i).at(j) &&
h.at(e).at(ii).first.second == u.at(i).at(k))
h.at(e).at(ii).second++;
}
}
}
}
}
}
for (int i = 0; i < s.size() - 1; i++) {
for (int j = i + 1; j < s.size(); j++) {
if (h.at(i).at(j).second >= m)
ans++;
}
}
cout << ans << endl;
for (int i = 0; i < s.size() - 1; i++) {
for (int j = i + 1; j < s.size(); j++) {
if (h.at(i).at(j).second >= m)
cout << h.at(i).at(j).first.first << " " << h.at(i).at(j).first.second
<< endl;
}
}
}
| replace | 43 | 47 | 43 | 49 | TLE | |
p00321 | C++ | Runtime Error | #include <iostream>
using namespace std;
// include
//------------------------------------------
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
bool compss(const string &a, const string &b) {
int i = 0;
while (i < a.size() && i < b.size()) {
if (a[i] < b[i])
return true;
if (a[i] > b[i])
return false;
i++;
}
return a.size() < b.size();
}
typedef pair<string, string> PSS;
typedef vector<PSS> VSS;
bool comp(const PSS &a, const PSS &b) {
if (compss(a.first, b.first))
return true;
if (compss(b.first, a.first))
return false;
if (compss(a.second, b.second))
return true;
// if(compss(b.second,a.second))return false;
return false;
}
int n, f;
int ctn[100][100];
int mp[10];
map<string, int> sref;
map<int, string> revref;
int main() {
cin >> n >> f;
int tps = 0;
REP(i, n) {
int t;
cin >> t;
REP(j, t) {
char ch[38];
cin >> ch;
string s(ch);
if (sref.find(s) == sref.end()) {
sref[s] = tps++;
revref[tps - 1] = s;
}
mp[j] = sref[s];
}
REP(j, t) {
FOR(k, j + 1, t) {
int a = mp[j], b = mp[k];
if (a > b)
swap(a, b);
ctn[a][b]++;
}
}
}
VSS ps;
REP(i, tps) {
FOR(j, i + 1, tps) {
if (ctn[i][j] >= f) {
string a = revref[i], b = revref[j];
if (!compss(a, b))
swap(a, b);
ps.push_back(MP(a, b));
}
}
}
sort(ALL(ps), comp);
cout << ps.size() << endl;
EACH(i, ps) { cout << (*i).first + " " + (*i).second << endl; }
return 0;
} | #include <iostream>
using namespace std;
// include
//------------------------------------------
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
bool compss(const string &a, const string &b) {
int i = 0;
while (i < a.size() && i < b.size()) {
if (a[i] < b[i])
return true;
if (a[i] > b[i])
return false;
i++;
}
return a.size() < b.size();
}
typedef pair<string, string> PSS;
typedef vector<PSS> VSS;
bool comp(const PSS &a, const PSS &b) {
if (compss(a.first, b.first))
return true;
if (compss(b.first, a.first))
return false;
if (compss(a.second, b.second))
return true;
// if(compss(b.second,a.second))return false;
return false;
}
int n, f;
int ctn[1000][1000];
int mp[10];
map<string, int> sref;
map<int, string> revref;
int main() {
cin >> n >> f;
int tps = 0;
REP(i, n) {
int t;
cin >> t;
REP(j, t) {
char ch[38];
cin >> ch;
string s(ch);
if (sref.find(s) == sref.end()) {
sref[s] = tps++;
revref[tps - 1] = s;
}
mp[j] = sref[s];
}
REP(j, t) {
FOR(k, j + 1, t) {
int a = mp[j], b = mp[k];
if (a > b)
swap(a, b);
ctn[a][b]++;
}
}
}
VSS ps;
REP(i, tps) {
FOR(j, i + 1, tps) {
if (ctn[i][j] >= f) {
string a = revref[i], b = revref[j];
if (!compss(a, b))
swap(a, b);
ps.push_back(MP(a, b));
}
}
}
sort(ALL(ps), comp);
cout << ps.size() << endl;
EACH(i, ps) { cout << (*i).first + " " + (*i).second << endl; }
return 0;
} | replace | 83 | 84 | 83 | 84 | 0 | |
p00321 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, f;
int num = 0;
map<string, int> mp;
int con[1001][1001] = {};
cin >> n >> f;
string str[1001];
for (int i = 0; i < n; i++) {
int m;
cin >> m;
vector<string> it(m);
for (int j = 0; j < m; j++) {
cin >> it[j];
if (!mp[it[j]]) {
num++;
mp[it[j]] = num;
str[num] = it[j];
}
}
for (int j = 0; j < m; j++) {
for (int k = m - 1; k >= 0; k--) {
if (j == k)
continue;
if (it[j] > it[k])
continue;
con[mp[it[j]]][mp[it[k]]]++;
}
}
}
vector<pair<string, string>> ans;
pair<string, string> abuf;
int anum = 0;
for (int i = 1; i <= num; i++) {
for (int j = 0; j <= 1001; j++) {
if (con[i][j] >= f) {
abuf.first = str[i];
abuf.second = str[j];
ans.push_back(abuf);
anum++;
}
}
}
sort(ans.begin(), ans.end());
cout << anum << endl;
for (int i = 0; i < anum; i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, f;
int num = 0;
map<string, int> mp;
int con[1001][1001] = {};
cin >> n >> f;
string str[1001];
for (int i = 0; i < n; i++) {
int m;
cin >> m;
vector<string> it(m);
for (int j = 0; j < m; j++) {
cin >> it[j];
if (!mp[it[j]]) {
num++;
mp[it[j]] = num;
str[num] = it[j];
}
}
for (int j = 0; j < m; j++) {
for (int k = m - 1; k >= 0; k--) {
if (j == k)
continue;
if (it[j] > it[k])
continue;
con[mp[it[j]]][mp[it[k]]]++;
}
}
}
vector<pair<string, string>> ans;
pair<string, string> abuf;
int anum = 0;
for (int i = 1; i <= num; i++) {
for (int j = 0; j <= num; j++) {
if (con[i][j] >= f) {
abuf.first = str[i];
abuf.second = str[j];
ans.push_back(abuf);
anum++;
}
}
}
sort(ans.begin(), ans.end());
cout << anum << endl;
for (int i = 0; i < anum; i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
return 0;
} | replace | 40 | 41 | 40 | 41 | 0 | |
p00323 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#define INF 210000
using namespace std;
int c[INF];
int main() {
int n, a, b;
for (int i = 0; i < INF; i++)
c[i] = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
c[a + b]++;
}
for (int i = 0; i < INF; i++) {
c[i + 1] += c[i] / 2;
if (c[i] % 2)
cout << i << " 0" << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#define INF 210000
using namespace std;
int c[INF];
int main() {
int n, a, b;
for (int i = 0; i < INF; i++)
c[i] = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
c[a + b]++;
}
for (int i = 0; i < INF - 1; i++) {
c[i + 1] += c[i] / 2;
if (c[i] % 2)
cout << i << " 0" << endl;
}
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p00324 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template <typename T> class hashmap64 {
std::vector<std::pair<uint64, T>> map;
uint64 mask, count, temp;
uint64 hash64(uint64 key) {
key ^= key << 13;
key ^= key >> 19;
return key ^ (key << 17);
}
public:
hashmap64()
: map(1024, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = 1023;
count = 0;
}
hashmap64(size_t s)
: map(1 << s, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = 1 << s - 1;
count = 0;
}
T &operator[](uint64 suf) {
temp = mask & hash64(suf);
while (~map[temp].first) {
if (map[temp].first == suf) {
return map[temp].second;
}
temp = mask & (temp + 1);
}
std::cerr << "?????¨????????????????????§????????????\n";
std::abort();
}
void insert(uint64 key, const T &value) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
map[temp].second = value;
return;
}
temp = mask & (temp + 1);
}
map[temp] = std::make_pair(key, value);
++count;
if ((count << 1) > mask) {
std::pair<uint64, T> mkey;
mask = mask << 1 | 1;
map.resize(mask + 1,
std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
for (uint64 t = 0; t <= mask >> 1; ++t) {
if (!~map[t].first) {
mkey = map[t];
map[t].first = ~0;
temp = mask & hash64(mkey.first);
while (~map[temp].first) {
temp = mask & (temp + 1);
}
map[temp] = mkey;
}
}
}
return;
}
bool find(uint64 key) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
return true;
}
temp = mask & (temp + 1);
}
return false;
}
bool empty(void) { return !count; }
size_t size(void) { return count; }
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
hashmap64<uint32> map(19);
uint32 n;
std::cin >> n;
int64 a, sum = 1e15;
uint32 ans = 0;
map.insert(sum, 0);
rep(i, 0, n) {
std::cin >> a;
sum += a;
if (map.find(sum)) {
ans = std::max(ans, i + 1 - map[sum]);
} else {
map.insert(sum, i + 1);
}
}
std::cout << ans << "\n";
return 0;
} | #include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template <typename T> class hashmap64 {
std::vector<std::pair<uint64, T>> map;
uint64 mask, count, temp;
uint64 hash64(uint64 key) {
key ^= key << 13;
key ^= key >> 19;
return key ^ (key << 17);
}
public:
hashmap64()
: map(1024, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = 1023;
count = 0;
}
hashmap64(size_t s)
: map(1 << s, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = (1 << s) - 1;
count = 0;
}
T &operator[](uint64 suf) {
temp = mask & hash64(suf);
while (~map[temp].first) {
if (map[temp].first == suf) {
return map[temp].second;
}
temp = mask & (temp + 1);
}
std::cerr << "?????¨????????????????????§????????????\n";
std::abort();
}
void insert(uint64 key, const T &value) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
map[temp].second = value;
return;
}
temp = mask & (temp + 1);
}
map[temp] = std::make_pair(key, value);
++count;
if ((count << 1) > mask) {
std::pair<uint64, T> mkey;
mask = mask << 1 | 1;
map.resize(mask + 1,
std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
for (uint64 t = 0; t <= mask >> 1; ++t) {
if (!~map[t].first) {
mkey = map[t];
map[t].first = ~0;
temp = mask & hash64(mkey.first);
while (~map[temp].first) {
temp = mask & (temp + 1);
}
map[temp] = mkey;
}
}
}
return;
}
bool find(uint64 key) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
return true;
}
temp = mask & (temp + 1);
}
return false;
}
bool empty(void) { return !count; }
size_t size(void) { return count; }
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
hashmap64<uint32> map(19);
uint32 n;
std::cin >> n;
int64 a, sum = 1e15;
uint32 ans = 0;
map.insert(sum, 0);
rep(i, 0, n) {
std::cin >> a;
sum += a;
if (map.find(sum)) {
ans = std::max(ans, i + 1 - map[sum]);
} else {
map.insert(sum, i + 1);
}
}
std::cout << ans << "\n";
return 0;
} | replace | 44 | 45 | 44 | 45 | TLE | |
p00324 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template <typename T> class hashmap64 {
std::vector<std::pair<uint64, T>> map;
uint64 mask, count, temp;
uint64 hash64(uint64 key) {
key = ~key;
key ^= key << 13;
key ^= key >> 19;
return key ^ (key << 17);
}
public:
hashmap64()
: map(8192, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = 8191;
count = 0;
}
hashmap64(size_t s) {
s |= s << 1;
s |= s >> 2;
s |= s >> 4;
s |= s >> 8;
s |= s >> 16;
s |= s >> 32;
mask = s;
count = 0;
map.resize(s + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
}
T &operator[](uint64 suf) {
temp = mask & hash64(suf);
while (map[temp].first != suf) {
temp = mask & (temp + 1);
}
return map[temp].second;
}
void insert(uint64 key, const T &value) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
map[temp].second = value;
return;
}
temp = mask & (temp + 1);
}
map[temp] = std::make_pair(key, value);
++count;
if ((count << 1) > mask) {
std::pair<uint64, T> mkey;
mask = mask << 1 | 1;
map.resize(mask + 1,
std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
for (uint64 t = 0; t <= mask >> 1; ++t) {
if (!~map[t].first) {
mkey = map[t];
map[t].first = ~0;
temp = mask & hash64(mkey.first);
while (~map[temp].first) {
temp = mask & (temp + 1);
}
map[temp] = mkey;
}
}
}
return;
}
bool find(uint64 key) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
return true;
}
temp = mask & (temp + 1);
}
return false;
}
bool empty(void) { return !count; }
size_t size(void) { return count; }
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
hashmap64<uint32> map(16000);
uint32 n;
std::cin >> n;
int64 a, sum = 1e15;
uint32 ans = 0;
map.insert(sum, 0);
rep(i, 0, n) {
std::cin >> a;
sum += a;
if (map.find(sum)) {
ans = std::max(ans, i + 1 - map[sum]);
} else {
map.insert(sum, i + 1);
}
}
std::cout << ans << "\n";
return 0;
} | #include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template <typename T> class hashmap64 {
std::vector<std::pair<uint64, T>> map;
uint64 mask, count, temp;
uint64 hash64(uint64 key) {
key = ~key;
key ^= key << 13;
key ^= key >> 19;
return key ^ (key << 17);
}
public:
hashmap64()
: map(8192, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = 8191;
count = 0;
}
hashmap64(size_t s) {
s |= s << 1;
s |= s >> 2;
s |= s >> 4;
s |= s >> 8;
s |= s >> 16;
s |= s >> 32;
mask = s;
count = 0;
map.resize(s + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
}
T &operator[](uint64 suf) {
temp = mask & hash64(suf);
while (map[temp].first != suf) {
temp = mask & (temp + 1);
}
return map[temp].second;
}
void insert(uint64 key, const T &value) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
map[temp].second = value;
return;
}
temp = mask & (temp + 1);
}
map[temp] = std::make_pair(key, value);
++count;
if ((count << 1) > mask) {
std::pair<uint64, T> mkey;
mask = mask << 1 | 1;
map.resize(mask + 1,
std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
for (uint64 t = 0; t <= mask >> 1; ++t) {
if (!~map[t].first) {
mkey = map[t];
map[t].first = ~0;
temp = mask & hash64(mkey.first);
while (~map[temp].first) {
temp = mask & (temp + 1);
}
map[temp] = mkey;
}
}
}
return;
}
bool find(uint64 key) {
temp = mask & hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
return true;
}
temp = mask & (temp + 1);
}
return false;
}
bool empty(void) { return !count; }
size_t size(void) { return count; }
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
hashmap64<uint32> map(32000);
uint32 n;
std::cin >> n;
int64 a, sum = 1e15;
uint32 ans = 0;
map.insert(sum, 0);
rep(i, 0, n) {
std::cin >> a;
sum += a;
if (map.find(sum)) {
ans = std::max(ans, i + 1 - map[sum]);
} else {
map.insert(sum, i + 1);
}
}
std::cout << ans << "\n";
return 0;
} | replace | 108 | 109 | 108 | 109 | TLE | |
p00325 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct cmd {
int line;
string p;
vector<string> v;
};
vector<cmd> A;
map<int, int> idx;
map<string, int> var;
bool isNum(const string &a) { return isdigit(a[0]); }
int StoI(const string &a) {
int res = 0;
for (int i = 0; i < a.size(); i++)
res = res * 10 + a[i] - '0';
return res;
}
int ADD(string &a, string &b) {
int res = 0;
res += var.count(a) ? var[a] : StoI(a);
res += var.count(b) ? var[b] : StoI(b);
return res;
}
int SUB(string &a, string &b) {
int res = 0;
res += var.count(a) ? var[a] : StoI(a);
res -= var.count(b) ? var[b] : StoI(b);
return res;
}
int SET(string &a) { return var.count(a) ? var[a] : StoI(a); }
bool start() {
int pos = 0, cnt = 0;
while (1) {
if (pos == (int)A.size())
return 1;
if (cnt++ > 1e8)
return 0;
cmd &a = A[pos];
string p = a.p;
if (p == "HALT")
return 1;
if (p == "ADD") {
int res = ADD(a.v[1], a.v[2]);
if (res < 0 || res >= 16)
return 1;
var[a.v[0]] = res;
} else if (p == "SUB") {
int res = SUB(a.v[1], a.v[2]);
if (res < 0 || res >= 16)
return 1;
var[a.v[0]] = res;
} else if (p == "SET") {
int res = SET(a.v[1]);
if (res < 0 || res >= 16)
return 1;
var[a.v[0]] = res;
} else if (p == "IF" && var[a.v[0]]) {
if (!idx.count(StoI(a.v[1])))
return 1;
pos = idx[StoI(a.v[1])] - 1;
}
pos++;
}
}
int main() {
int n;
cin >> n;
A.resize(n);
for (int i = 0; i < n; i++) {
cin >> A[i].line >> A[i].p;
idx[A[i].line] = i;
if (A[i].p == "HALT")
;
else if (A[i].p == "ADD" || A[i].p == "SUB")
A[i].v.resize(3);
else
A[i].v.resize(2);
for (int j = 0; j < (int)A[i].v.size(); j++) {
cin >> A[i].v[j];
if (!isNum(A[i].v[j]))
var[A[i].v[j]] = 0;
}
}
if (!start())
cout << "inf" << endl;
else
for (map<string, int>::iterator it = var.begin(); it != var.end(); it++)
cout << it->first << "=" << it->second << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct cmd {
int line;
string p;
vector<string> v;
};
vector<cmd> A;
map<int, int> idx;
map<string, int> var;
bool isNum(const string &a) { return isdigit(a[0]); }
int StoI(const string &a) {
int res = 0;
for (int i = 0; i < a.size(); i++)
res = res * 10 + a[i] - '0';
return res;
}
int ADD(string &a, string &b) {
int res = 0;
res += var.count(a) ? var[a] : StoI(a);
res += var.count(b) ? var[b] : StoI(b);
return res;
}
int SUB(string &a, string &b) {
int res = 0;
res += var.count(a) ? var[a] : StoI(a);
res -= var.count(b) ? var[b] : StoI(b);
return res;
}
int SET(string &a) { return var.count(a) ? var[a] : StoI(a); }
bool start() {
int pos = 0, cnt = 0;
while (1) {
if (pos == (int)A.size())
return 1;
if (cnt++ > 50000000)
return 0;
cmd &a = A[pos];
string p = a.p;
if (p == "HALT")
return 1;
if (p == "ADD") {
int res = ADD(a.v[1], a.v[2]);
if (res < 0 || res >= 16)
return 1;
var[a.v[0]] = res;
} else if (p == "SUB") {
int res = SUB(a.v[1], a.v[2]);
if (res < 0 || res >= 16)
return 1;
var[a.v[0]] = res;
} else if (p == "SET") {
int res = SET(a.v[1]);
if (res < 0 || res >= 16)
return 1;
var[a.v[0]] = res;
} else if (p == "IF" && var[a.v[0]]) {
if (!idx.count(StoI(a.v[1])))
return 1;
pos = idx[StoI(a.v[1])] - 1;
}
pos++;
}
}
int main() {
int n;
cin >> n;
A.resize(n);
for (int i = 0; i < n; i++) {
cin >> A[i].line >> A[i].p;
idx[A[i].line] = i;
if (A[i].p == "HALT")
;
else if (A[i].p == "ADD" || A[i].p == "SUB")
A[i].v.resize(3);
else
A[i].v.resize(2);
for (int j = 0; j < (int)A[i].v.size(); j++) {
cin >> A[i].v[j];
if (!isNum(A[i].v[j]))
var[A[i].v[j]] = 0;
}
}
if (!start())
cout << "inf" << endl;
else
for (map<string, int>::iterator it = var.begin(); it != var.end(); it++)
cout << it->first << "=" << it->second << endl;
return 0;
} | replace | 41 | 42 | 41 | 42 | TLE | |
p00325 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF (1e9)
#define N 1005
using namespace std;
string s[N], s1[N], s2[N], s3[N];
set<char> S;
int n, num;
int d[N], p;
int var[N];
int get_num(string str) {
if ('a' <= str[0] && str[0] <= 'z')
return var[(int)str[0]];
int res = 0;
rep(i, str.size()) res = res * 10 + str[i] - '0';
return res;
}
void solve() {
int f = 0, cnt = 60000000;
while (1) {
cnt--;
if (cnt == 0)
break;
if (s[p] == "ADD") {
int var2 = get_num(s2[p]);
int var3 = get_num(s3[p]);
if (var2 + var3 >= 16) {
f = 1;
break;
}
var[(int)s1[p][0]] = var2 + var3;
}
if (s[p] == "SUB") {
int var2 = get_num(s2[p]);
int var3 = get_num(s3[p]);
if (var2 - var3 < 0) {
f = 1;
break;
}
var[(int)s1[p][0]] = var2 - var3;
}
if (s[p] == "SET") {
int var2 = get_num(s2[p]);
var[(int)s1[p][0]] = var2;
}
if (s[p] == "IF") {
int var1 = get_num(s1[p]);
int var2 = get_num(s2[p]);
if (var1 != 0) {
if (d[var2] == INF) {
f = 1;
break;
}
p = d[var2];
continue;
}
}
if (s[p] == "HALT") {
f = 1;
break;
}
p++;
if (p == n) {
f = 1;
break;
}
}
if (f) {
set<char>::iterator ite = S.begin();
while (ite != S.end()) {
cout << (*ite) << "=" << var[(int)(*ite)] << endl;
ite++;
}
} else
cout << "inf" << endl;
}
void add(char c) {
if ('a' <= c && c <= 'z')
S.insert(c);
}
int main() {
cin >> n;
rep(i, N) d[i] = INF;
rep(i, n) {
cin >> num;
d[num] = i;
cin >> s[i];
if (s[i] == "HALT")
continue;
cin >> s1[i] >> s2[i];
if (s[i] == "ADD" || s[i] == "SUB")
cin >> s3[i], add(s3[i][0]);
add(s1[i][0]);
add(s2[i][0]);
}
solve();
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF (1e9)
#define N 1005
using namespace std;
string s[N], s1[N], s2[N], s3[N];
set<char> S;
int n, num;
int d[N], p;
int var[N];
int get_num(string str) {
if ('a' <= str[0] && str[0] <= 'z')
return var[(int)str[0]];
int res = 0;
rep(i, str.size()) res = res * 10 + str[i] - '0';
return res;
}
void solve() {
int f = 0, cnt = 50000000;
while (1) {
cnt--;
if (cnt == 0)
break;
if (s[p] == "ADD") {
int var2 = get_num(s2[p]);
int var3 = get_num(s3[p]);
if (var2 + var3 >= 16) {
f = 1;
break;
}
var[(int)s1[p][0]] = var2 + var3;
}
if (s[p] == "SUB") {
int var2 = get_num(s2[p]);
int var3 = get_num(s3[p]);
if (var2 - var3 < 0) {
f = 1;
break;
}
var[(int)s1[p][0]] = var2 - var3;
}
if (s[p] == "SET") {
int var2 = get_num(s2[p]);
var[(int)s1[p][0]] = var2;
}
if (s[p] == "IF") {
int var1 = get_num(s1[p]);
int var2 = get_num(s2[p]);
if (var1 != 0) {
if (d[var2] == INF) {
f = 1;
break;
}
p = d[var2];
continue;
}
}
if (s[p] == "HALT") {
f = 1;
break;
}
p++;
if (p == n) {
f = 1;
break;
}
}
if (f) {
set<char>::iterator ite = S.begin();
while (ite != S.end()) {
cout << (*ite) << "=" << var[(int)(*ite)] << endl;
ite++;
}
} else
cout << "inf" << endl;
}
void add(char c) {
if ('a' <= c && c <= 'z')
S.insert(c);
}
int main() {
cin >> n;
rep(i, N) d[i] = INF;
rep(i, n) {
cin >> num;
d[num] = i;
cin >> s[i];
if (s[i] == "HALT")
continue;
cin >> s1[i] >> s2[i];
if (s[i] == "ADD" || s[i] == "SUB")
cin >> s3[i], add(s3[i][0]);
add(s1[i][0]);
add(s2[i][0]);
}
solve();
return 0;
} | replace | 21 | 22 | 21 | 22 | TLE | |
p00329 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int N, a, cc = 1;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
bool dfs(int v) {
used[v] = cc;
for (int i = 0; i < (int)G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < 0 || (used[w] != cc && dfs(w))) {
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
int bipartite_matching() {
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < N; v++) {
if (match[v] < 0) {
cc++;
if (dfs(v))
res++;
}
}
return res;
}
int main() {
scanf("%d", &N);
N--;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &a);
if (a == 1)
G[j].push_back(N + i);
}
}
for (int i = 0; i < N; i++)
sort(G[i].begin(), G[i].end());
int f = bipartite_matching();
printf(f == N ? "yes\n" : "no\n");
for (int i = 0; i < N && f == N; i++) {
match[match[i]] = -1;
match[i] = -1;
cc++;
dfs(i);
G[i].clear();
G[i].push_back(match[i]);
printf("%d\n", match[i] - N + 1);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int N, a, cc = 1;
vector<int> G[MAX_V];
int match[MAX_V];
int used[MAX_V];
bool dfs(int v) {
used[v] = cc;
for (int i = 0; i < (int)G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < 0 || (used[w] != cc && dfs(w))) {
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
int bipartite_matching() {
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < N; v++) {
if (match[v] < 0) {
cc++;
if (dfs(v))
res++;
}
}
return res;
}
int main() {
scanf("%d", &N);
N--;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &a);
if (a == 1)
G[j].push_back(N + i);
}
}
for (int i = 0; i < N; i++)
sort(G[i].begin(), G[i].end());
int f = bipartite_matching();
printf(f == N ? "yes\n" : "no\n");
for (int i = 0; i < N && f == N; i++) {
match[match[i]] = -1;
match[i] = -1;
cc++;
dfs(i);
G[i].clear();
G[i].push_back(match[i]);
printf("%d\n", match[i] - N + 1);
}
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p00329 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
// #define int long long
#define rep(v, a, b) for (int v = (a); v < (b); v++)
#define rrep(v, a, b) for (int v = (b)-1; v >= (a); v--)
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
struct BipartiteMatching {
int n;
vector<vector<int>> g;
vector<int> match;
vector<bool> used, alive;
BipartiteMatching(int n) : n(n), g(n), match(n), used(n), alive(n, true) {}
void addEdge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int maximumMatching() {
int cnt = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < n; v++) {
if (!alive[v])
continue;
if (match[v] == -1) {
fill(used.begin(), used.end(), false);
if (augment(v))
cnt++;
}
}
return cnt;
}
bool augment(int v) {
used[v] = true;
for (int u : g[v]) {
if (!alive[u])
continue;
int w = match[u];
if (w == -1 || (!used[w] && augment(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
};
struct LexicographicallyBipartiteMatching : BipartiteMatching {
LexicographicallyBipartiteMatching(int n) : BipartiteMatching(n) {}
int maximumMatching() {
for (int v = 0; v < n; v++)
sort(g[v].begin(), g[v].end());
int cnt = BipartiteMatching::maximumMatching();
for (int v = 0; v < n; v++) {
if (!alive[v])
continue;
match[match[v]] = -1;
match[v] = -1;
fill(used.begin(), used.end(), false);
augment(v);
alive[match[v]] = 0;
alive[v] = 0;
}
return cnt;
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
N--;
vector<vector<int>> b(N, vector<int>(N));
rep(v, 0, N) rep(u, 0, N) { cin >> b[v][u]; }
LexicographicallyBipartiteMatching lbm(N + N);
rep(v, 0, N) rep(u, 0, N) {
if (b[v][u])
lbm.addEdge(u, N + v);
}
int res = lbm.maximumMatching();
dump(res);
if (res == N) {
cout << "yes" << endl;
rep(v, 0, N) { cout << lbm.match[v] - N + 1 << endl; }
} else {
cout << "no" << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
// #define int long long
#define rep(v, a, b) for (int v = (a); v < (b); v++)
#define rrep(v, a, b) for (int v = (b)-1; v >= (a); v--)
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
struct BipartiteMatching {
int n;
vector<vector<int>> g;
vector<int> match;
vector<bool> used, alive;
BipartiteMatching(int n) : n(n), g(n), match(n), used(n), alive(n, true) {}
void addEdge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int maximumMatching() {
int cnt = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < n; v++) {
if (!alive[v])
continue;
if (match[v] == -1) {
fill(used.begin(), used.end(), false);
if (augment(v))
cnt++;
}
}
return cnt;
}
bool augment(int v) {
used[v] = true;
for (int u : g[v]) {
if (!alive[u])
continue;
int w = match[u];
if (w == -1 || (!used[w] && augment(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
};
struct LexicographicallyBipartiteMatching : BipartiteMatching {
LexicographicallyBipartiteMatching(int n) : BipartiteMatching(n) {}
int maximumMatching() {
for (int v = 0; v < n; v++)
sort(g[v].begin(), g[v].end());
int cnt = BipartiteMatching::maximumMatching();
for (int v = 0; v < n; v++) {
if (!alive[v] || match[v] == -1)
continue;
match[match[v]] = -1;
match[v] = -1;
fill(used.begin(), used.end(), false);
augment(v);
alive[match[v]] = 0;
alive[v] = 0;
}
return cnt;
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
N--;
vector<vector<int>> b(N, vector<int>(N));
rep(v, 0, N) rep(u, 0, N) { cin >> b[v][u]; }
LexicographicallyBipartiteMatching lbm(N + N);
rep(v, 0, N) rep(u, 0, N) {
if (b[v][u])
lbm.addEdge(u, N + v);
}
int res = lbm.maximumMatching();
dump(res);
if (res == N) {
cout << "yes" << endl;
rep(v, 0, N) { cout << lbm.match[v] - N + 1 << endl; }
} else {
cout << "no" << endl;
}
return 0;
} | replace | 77 | 78 | 77 | 78 | 0 | |
p00333 | C++ | Runtime Error | #include <iostream>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return (b, a % b);
}
int main() {
int W, H, C;
cin >> W >> H >> C;
int GCD = gcd(W, H);
cout << ((W / GCD) * (H / GCD) * C) << endl;
return 0;
}
| #include <iostream>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
int W, H, C;
cin >> W >> H >> C;
int GCD = gcd(W, H);
cout << ((W / GCD) * (H / GCD) * C) << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p00333 | C++ | Runtime Error | #include <iostream>
using namespace std;
int gcd(int m, int n) {
if (n == 0)
return 0;
return gcd(n, m % n);
}
int main() {
int W, H, C;
cin >> W >> H >> C;
int g = gcd(W, H);
cout << W / g * H / g * C << endl;
return 0;
}
| #include <iostream>
using namespace std;
int gcd(int m, int n) {
if (n == 0)
return m;
return gcd(n, m % n);
}
int main() {
int W, H, C;
cin >> W >> H >> C;
int g = gcd(W, H);
cout << W / g * H / g * C << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | -8 | |
p00334 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int te[100][3];
bool ka[100] = {0};
int n;
int cnt;
int i, j;
int tmp;
cin >> n;
for (i = 0; i < n; i++) {
cin >> te[i][0] >> te[i][1] >> te[i][2];
if (te[i][0] > te[i][1]) {
tmp = te[i][0];
te[i][0] = te[i][1];
te[i][1] = tmp;
}
if (te[i][1] > te[i][2]) {
tmp = te[i][1];
te[i][1] = te[i][2];
te[i][2] = tmp;
if (te[i][0] > te[i][1]) {
tmp = te[i][0];
te[i][0] = te[i][1];
te[i][1] = tmp;
}
}
}
cnt = 0;
for (i = 0; i < n; i++) {
if (!ka[i]) {
for (j = i + 1; j < n; j++) {
if (te[i][0] == te[j][0] && te[i][1] == te[j][1] &&
te[i][2] == te[j][2]) {
cnt++;
ka[j] = true;
}
}
}
}
cout << cnt << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int te[1000 + 1][3];
bool ka[1000 + 1] = {0};
int n;
int cnt;
int i, j;
int tmp;
cin >> n;
for (i = 0; i < n; i++) {
cin >> te[i][0] >> te[i][1] >> te[i][2];
if (te[i][0] > te[i][1]) {
tmp = te[i][0];
te[i][0] = te[i][1];
te[i][1] = tmp;
}
if (te[i][1] > te[i][2]) {
tmp = te[i][1];
te[i][1] = te[i][2];
te[i][2] = tmp;
if (te[i][0] > te[i][1]) {
tmp = te[i][0];
te[i][0] = te[i][1];
te[i][1] = tmp;
}
}
}
cnt = 0;
for (i = 0; i < n; i++) {
if (!ka[i]) {
for (j = i + 1; j < n; j++) {
if (te[i][0] == te[j][0] && te[i][1] == te[j][1] &&
te[i][2] == te[j][2]) {
cnt++;
ka[j] = true;
}
}
}
}
cout << cnt << endl;
return 0;
} | replace | 3 | 5 | 3 | 5 | 0 | |
p00334 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int kumi[100][100][100] = {0};
int main() {
int N;
int count = 0;
int p[3003];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[(3 * i)] >> p[(3 * i) + 1] >> p[(3 * i) + 2];
sort(p + (3 * i), p + (3 * i) + 3);
if (kumi[p[3 * i]][p[(3 * i) + 1]][p[(3 * i) + 2]] == 0) {
kumi[p[3 * i]][p[(3 * i) + 1]][p[(3 * i) + 2]] = 1;
} else {
count++;
}
}
cout << count << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int kumi[1000][1000][1000] = {0};
int main() {
int N;
int count = 0;
int p[3003];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[(3 * i)] >> p[(3 * i) + 1] >> p[(3 * i) + 2];
sort(p + (3 * i), p + (3 * i) + 3);
if (kumi[p[3 * i]][p[(3 * i) + 1]][p[(3 * i) + 2]] == 0) {
kumi[p[3 * i]][p[(3 * i) + 1]][p[(3 * i) + 2]] = 1;
} else {
count++;
}
}
cout << count << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00334 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
class triangle {
public:
int position[3];
};
bool compare(triangle &a, triangle &b) {
for (int i = 0; i < 3; ++i) {
if (a.position[i] < b.position[i]) {
return true;
} else if (a.position[i] > b.position[i]) {
return false;
}
}
return true;
}
void input(vector<triangle> &line) {
int num;
cin >> num;
line.resize(num);
for (int i = 0; i < num; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> line[i].position[j];
}
sort(line[i].position, line[i].position + 3);
}
sort(line.begin(), line.end(), compare);
}
int func(vector<triangle> &line) {
int res = 0;
for (int i = 1; i < line.size(); ++i) {
bool flag = true;
for (int j = 0; j < 3; ++j) {
if (line[i - 1].position[j] != line[i].position[j]) {
flag = false;
break;
}
}
if (flag) {
++res;
}
}
return res;
}
int main() {
vector<triangle> line;
input(line);
cout << func(line) << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
class triangle {
public:
int position[3];
};
bool compare(triangle &a, triangle &b) {
for (int i = 0; i < 3; ++i) {
if (a.position[i] < b.position[i]) {
return true;
} else if (a.position[i] > b.position[i]) {
return false;
}
}
return false;
}
void input(vector<triangle> &line) {
int num;
cin >> num;
line.resize(num);
for (int i = 0; i < num; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> line[i].position[j];
}
sort(line[i].position, line[i].position + 3);
}
sort(line.begin(), line.end(), compare);
}
int func(vector<triangle> &line) {
int res = 0;
for (int i = 1; i < line.size(); ++i) {
bool flag = true;
for (int j = 0; j < 3; ++j) {
if (line[i - 1].position[j] != line[i].position[j]) {
flag = false;
break;
}
}
if (flag) {
++res;
}
}
return res;
}
int main() {
vector<triangle> line;
input(line);
cout << func(line) << endl;
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p00335 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int n;
int p[5000];
int z[5000];
signed main() {
while (cin >> n, n) {
rep(i, n) cin >> p[i];
int ans = 1001001001ll;
for (int t = 0; t <= p[0]; t++) {
int cost = t;
memset(z, 0, sizeof(z));
z[0] = t;
for (int i = 1; i < n; i++) {
cost += (p[i - 1] - z[i - 1]) * 2;
z[i] += p[i - 1] - z[i - 1];
chmin(z[i], p[i]);
}
cost += p[n - 1] - z[n - 1];
chmin(ans, cost);
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int n;
int p[5000];
int z[5000];
signed main() {
while (cin >> n) {
rep(i, n) cin >> p[i];
int ans = 1001001001ll;
for (int t = 0; t <= p[0]; t++) {
int cost = t;
memset(z, 0, sizeof(z));
z[0] = t;
for (int i = 1; i < n; i++) {
cost += (p[i - 1] - z[i - 1]) * 2;
z[i] += p[i - 1] - z[i - 1];
chmin(z[i], p[i]);
}
cost += p[n - 1] - z[n - 1];
chmin(ans, cost);
}
cout << ans << endl;
}
return 0;
} | replace | 25 | 26 | 25 | 26 | TLE | |
p00336 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int dp[1000][1000];
int main() {
string t, b;
cin >> t >> b;
dp[0][0] = 0;
int MOD = 1000000007;
for (int i = 1; i <= b.size(); i++) {
for (int j = 1 + i - 1; j <= t.size(); j++) {
if (b[i - 1] == t[j - 1]) {
if (i == 1)
dp[i][j] = (dp[i][j - 1] + 1) % MOD;
else
dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]) % MOD;
} else
dp[i][j] = dp[i][j - 1] % MOD;
}
}
cout << dp[b.size()][t.size()] % MOD << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int dp[1001][1001];
int main() {
string t, b;
cin >> t >> b;
dp[0][0] = 0;
int MOD = 1000000007;
for (int i = 1; i <= b.size(); i++) {
for (int j = 1 + i - 1; j <= t.size(); j++) {
if (b[i - 1] == t[j - 1]) {
if (i == 1)
dp[i][j] = (dp[i][j - 1] + 1) % MOD;
else
dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]) % MOD;
} else
dp[i][j] = dp[i][j - 1] % MOD;
}
}
cout << dp[b.size()][t.size()] % MOD << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00336 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define bigone t.size() + 1
#define bangone b.size() + 1
#define big t.size()
#define bang b.size()
#define USA 1000000007
using namespace std;
int P[1000][1000];
int main() {
string t, b;
cin >> t >> b;
// P=プロフェッショナル
for (int i = 0; i < bang + 1; i++) {
P[0][i] = 0;
}
for (int i = 0; i < big + 1; i++) {
P[i][0] = 1;
}
for (int i = 1; i < big + 1; i++) {
char ti = t.at(i - 1);
for (int j = 1; j < bang + 1; j++) {
char bj = b.at(j - 1);
if (j <= i) {
if (ti == bj) {
P[i][j] = (P[i - 1][j - 1] + P[i - 1][j]) % USA;
} else {
P[i][j] = P[i - 1][j];
}
} else {
P[i][j] = 0;
}
}
}
cout << P[big][bang] << endl;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define bigone t.size() + 1
#define bangone b.size() + 1
#define big t.size()
#define bang b.size()
#define USA 1000000007
using namespace std;
long long P[10000][10000];
int main() {
string t, b;
cin >> t >> b;
// P=プロフェッショナル
for (int i = 0; i < bang + 1; i++) {
P[0][i] = 0;
}
for (int i = 0; i < big + 1; i++) {
P[i][0] = 1;
}
for (int i = 1; i < big + 1; i++) {
char ti = t.at(i - 1);
for (int j = 1; j < bang + 1; j++) {
char bj = b.at(j - 1);
if (j <= i) {
if (ti == bj) {
P[i][j] = (P[i - 1][j - 1] + P[i - 1][j]) % USA;
} else {
P[i][j] = P[i - 1][j];
}
} else {
P[i][j] = 0;
}
}
}
cout << P[big][bang] << endl;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p00336 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
#define inf 1e9
ll mod = 1e9 + 7;
int main() {
string t, b;
cin >> t >> b;
ll n1 = t.size(), n2 = b.size();
vector<vector<ll>> dp(n1, vector<ll>(n2, 0));
for (int i = 0; i < n1; i++) {
if (t[i] == b[0])
dp[i][0] = 1;
}
for (int i = 1; i < n2; i++) {
ll sum = 0;
for (int j = 0; j < i; j++) {
sum += dp[j][i - 1];
sum %= mod;
}
for (int j = i; j < n1; j++) {
if (t[j] == b[i]) {
dp[j][i] = sum;
}
sum += dp[j][i - 1];
sum %= mod;
}
}
ll res = 0;
/*for(int i=0;i<n2;i++){
for(int j=0;j<n1;j++){
cout<<dp[i][j]<<' ';
}
cout<<endl;
}*/
for (int i = 0; i < n1; i++) {
res += dp[i][n2 - 1];
res %= mod;
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
#define inf 1e9
ll mod = 1e9 + 7;
int main() {
string t, b;
cin >> t >> b;
ll n1 = t.size(), n2 = b.size();
vector<vector<ll>> dp(n1, vector<ll>(n2, 0));
for (int i = 0; i < n1; i++) {
if (t[i] == b[0])
dp[i][0] = 1;
}
if (n1 < n2) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i < n2; i++) {
ll sum = 0;
for (int j = 0; j < i; j++) {
sum += dp[j][i - 1];
sum %= mod;
}
for (int j = i; j < n1; j++) {
if (t[j] == b[i]) {
dp[j][i] = sum;
}
sum += dp[j][i - 1];
sum %= mod;
}
}
ll res = 0;
/*for(int i=0;i<n2;i++){
for(int j=0;j<n1;j++){
cout<<dp[i][j]<<' ';
}
cout<<endl;
}*/
for (int i = 0; i < n1; i++) {
res += dp[i][n2 - 1];
res %= mod;
}
cout << res << endl;
return 0;
}
| replace | 16 | 17 | 16 | 20 | 0 | |
p00336 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long int dp[1001][1001];
int main() {
string t, b;
cin >> t >> b;
int tsize = t.size(), bsize = b.size();
dp[0][0] = 1;
for (int i = 0; i <= t.size(); i++) {
for (int j = 0; j <= b.size(); j++) {
if (t[i] == b[j]) {
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j + 1] %= 1000000007;
}
dp[i + 1][j] += dp[i][j];
dp[i + 1][j] %= 1000000007;
}
}
cout << dp[tsize][bsize] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long int dp[1002][1002];
int main() {
string t, b;
cin >> t >> b;
int tsize = t.size(), bsize = b.size();
dp[0][0] = 1;
for (int i = 0; i <= t.size(); i++) {
for (int j = 0; j <= b.size(); j++) {
if (t[i] == b[j]) {
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j + 1] %= 1000000007;
}
dp[i + 1][j] += dp[i][j];
dp[i + 1][j] %= 1000000007;
}
}
cout << dp[tsize][bsize] << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00336 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int A, B;
string a, b;
cin >> a >> b;
A = a.size();
B = b.size();
vector<vector<ll>> dp(B, vector<ll>(A));
constexpr ll MOD = ((1e9) + 7);
for (int i = 0; i < B; i++) {
for (int j = 0; j < A; j++) {
if (i > 0)
dp[i][j + 1] += dp[i][j];
if (b[i] == a[j]) {
dp[i + 1][j + 1] += (dp[i][j] + (i == 0));
dp[i + 1][j + 1] %= MOD;
}
}
}
ll res = 0;
for (int i = 0; i <= A; i++) {
res += dp[B][i];
res %= MOD;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int A, B;
string a, b;
cin >> a >> b;
A = a.size();
B = b.size();
vector<vector<ll>> dp(B + 1, vector<ll>(A + 1));
constexpr ll MOD = ((1e9) + 7);
for (int i = 0; i < B; i++) {
for (int j = 0; j < A; j++) {
if (i > 0)
dp[i][j + 1] += dp[i][j];
if (b[i] == a[j]) {
dp[i + 1][j + 1] += (dp[i][j] + (i == 0));
dp[i + 1][j + 1] %= MOD;
}
}
}
ll res = 0;
for (int i = 0; i <= A; i++) {
res += dp[B][i];
res %= MOD;
}
cout << res << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | -11 | |
p00338 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define B 600
#define F first
#define S second
typedef long long ll;
typedef pair<ll, ll> P;
ll t[100005];
struct que {
ll o, a, b;
};
struct z {
ll x;
bool operator<(z &q) {
if (t[x] != t[q.x])
return -t[x] < -t[q.x];
else
return x < q.x;
}
};
int n, c;
bool v[100005];
int main(void) {
scanf("%d%d", &n, &c);
for (int i = 0; i < c; i += B) {
set<int> o;
vector<que> m;
for (int k = 0; k < n; k++)
v[k] = false;
for (int j = i; j < i + B && j < c; j++) {
int x;
scanf("%d", &x);
if (x == 0) {
ll a, b;
scanf("%lld%lld", &a, &b);
a--;
v[a] = true;
m.push_back(que{0, a, b});
} else {
int a;
scanf("%d", &a);
m.push_back(que{1, a, 0});
}
}
vector<z> p;
vector<P> q;
for (int k = 0; k < n; k++) {
if (!v[k])
q.push_back(P(-t[k], k));
else
p.push_back(z{k});
}
sort(q.begin(), q.end());
for (int j = 0; j < m.size(); j++) {
ll r = m[j].o, a = m[j].a, b = m[j].b;
if (r == 0)
t[a] += b;
else {
sort(p.begin(), p.end());
a--;
bool e = false;
for (int k = 0; k < p.size(); k++) {
int h = lower_bound(q.begin(), q.end(), P(-t[p[k].x], p[k].x)) -
q.begin();
if (a < h)
break;
else if (a == h) {
printf("%lld %lld\n", p[k].x + 1, t[p[k].x]);
e = true;
break;
} else
a--;
}
if (!e) {
printf("%lld %lld\n", q[a].S + 1, -q[a].F);
}
}
}
}
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define B 500
#define F first
#define S second
typedef long long ll;
typedef pair<ll, ll> P;
ll t[100005];
struct que {
ll o, a, b;
};
struct z {
ll x;
bool operator<(z &q) {
if (t[x] != t[q.x])
return -t[x] < -t[q.x];
else
return x < q.x;
}
};
int n, c;
bool v[100005];
int main(void) {
scanf("%d%d", &n, &c);
for (int i = 0; i < c; i += B) {
set<int> o;
vector<que> m;
for (int k = 0; k < n; k++)
v[k] = false;
for (int j = i; j < i + B && j < c; j++) {
int x;
scanf("%d", &x);
if (x == 0) {
ll a, b;
scanf("%lld%lld", &a, &b);
a--;
v[a] = true;
m.push_back(que{0, a, b});
} else {
int a;
scanf("%d", &a);
m.push_back(que{1, a, 0});
}
}
vector<z> p;
vector<P> q;
for (int k = 0; k < n; k++) {
if (!v[k])
q.push_back(P(-t[k], k));
else
p.push_back(z{k});
}
sort(q.begin(), q.end());
for (int j = 0; j < m.size(); j++) {
ll r = m[j].o, a = m[j].a, b = m[j].b;
if (r == 0)
t[a] += b;
else {
sort(p.begin(), p.end());
a--;
bool e = false;
for (int k = 0; k < p.size(); k++) {
int h = lower_bound(q.begin(), q.end(), P(-t[p[k].x], p[k].x)) -
q.begin();
if (a < h)
break;
else if (a == h) {
printf("%lld %lld\n", p[k].x + 1, t[p[k].x]);
e = true;
break;
} else
a--;
}
if (!e) {
printf("%lld %lld\n", q[a].S + 1, -q[a].F);
}
}
}
}
}
| replace | 6 | 7 | 6 | 7 | TLE | |
p00342 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int a[1001], i, ma = 100000, p, n;
double m1, m2;
int main() {
for (cin >> n; i < n; i++)
cin >> a[i];
sort(a, a + n);
m1 = (double)(a[n - 1] + a[n - 2]) / (a[1] - a[0]);
for (i = n - 1; i > 0; i--)
if (a[i] - a[i - 1] <= ma)
ma = a[i] - a[i++ - 1];
for (i = n - 1; i > 0; i -= 2)
if (i != p) {
m2 = (double)(a[i - 1] + a[i]) / (a[p] - a[p - 1]);
break;
}
m1 = max(m1, m2);
printf("%.9f\n", m1);
} | #include <bits/stdc++.h>
using namespace std;
int a[1001], i, ma = 100000, p, n;
double m1, m2;
int main() {
for (cin >> n; i < n; i++)
cin >> a[i];
sort(a, a + n);
m1 = (double)(a[n - 1] + a[n - 2]) / (a[1] - a[0]);
for (i = n - 1; i > 0; i--)
if (a[i] - a[i - 1] <= ma) {
ma = a[i] - a[i - 1];
p = i;
}
for (i = n - 1; i > 0; i -= 2)
if (i != p) {
m2 = (double)(a[i - 1] + a[i]) / (a[p] - a[p - 1]);
break;
}
m1 = max(m1, m2);
printf("%.9f\n", m1);
} | replace | 10 | 12 | 10 | 14 | TLE | |
p00343 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a) for (__typeof(a.begin()) i = a.begin(); i != a.end(); ++i)
#define __unique(V) V.resize(unique(V.begin(), V.end()) - V.begin())
#define cntbit(X) __builtin_popcount(X)
#define fi first
#define se second
#define LL long long
#define ii pair<int, int>
#define iii pair<int, ii>
#define TASK "sevens"
using namespace std;
int F[65][65][2], m, a[10], b[10], n;
bool ok[15];
///--------------------------
void readf() {
memset(ok, 0, sizeof(ok));
ok[7] = 1;
fo(i, 1, 6) cin >> a[i], ok[a[i]] = 1;
m = 0;
fo(i, 1, 13) if (!ok[i]) b[++m] = i;
}
///--------------------------
inline void on(int &X, int i) { X = (X | (1 << (i - 1))); }
inline int bit(int X, int i) { return ((X >> (i - 1)) & 1); }
///--------------------------
bool dp(int mask1, int mask2, int id) {
if (F[mask1][mask2][id] != -1)
return F[mask1][mask2][id];
bool rs = &F[mask1][mask2][id];
if (mask1 == 0 && id == 0)
return (rs = 1);
if (mask2 == 0 && id == 1)
return (rs = 1);
int tmp = 0;
on(tmp, 7);
fo(i, 1, 6) if (!bit(mask1, i)) on(tmp, a[i]);
fo(i, 1, 6) if (!bit(mask2, i)) on(tmp, b[i]);
rs = 0;
if (id == 0) {
int yes = 0;
fo(i, 1, 6) if (bit(mask1, i) &&
((a[i] > 1 && bit(tmp, a[i] - 1)) || bit(tmp, a[i] + 1))) {
rs |= (!dp(mask1 & (~(1 << (i - 1))), mask2, 1));
yes = 1;
}
if (yes == 0)
rs |= (!dp(mask1, mask2, 1));
return rs;
} else {
int yes = 0;
fo(i, 1, 6) if (bit(mask2, i) &&
((b[i] > 1 && bit(tmp, b[i] - 1)) || bit(tmp, b[i] + 1))) {
rs |= (!dp(mask1, mask2 & (~(1 << (i - 1))), 0));
yes = 1;
}
if (yes == 0)
rs |= (!dp(mask1, mask2, 0));
return rs;
}
}
///--------------------------
void solve() {
memset(F, -1, sizeof(F));
cout << (dp(63, 63, 0) ? "yes\n" : "no\n");
}
///--------------------------
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
#endif // ONLINE_JUDGE
cin >> n;
while (n--) {
readf();
solve();
}
}
| #include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a) for (__typeof(a.begin()) i = a.begin(); i != a.end(); ++i)
#define __unique(V) V.resize(unique(V.begin(), V.end()) - V.begin())
#define cntbit(X) __builtin_popcount(X)
#define fi first
#define se second
#define LL long long
#define ii pair<int, int>
#define iii pair<int, ii>
#define TASK "sevens"
using namespace std;
int F[65][65][2], m, a[10], b[10], n;
bool ok[15];
///--------------------------
void readf() {
memset(ok, 0, sizeof(ok));
ok[7] = 1;
fo(i, 1, 6) cin >> a[i], ok[a[i]] = 1;
m = 0;
fo(i, 1, 13) if (!ok[i]) b[++m] = i;
}
///--------------------------
inline void on(int &X, int i) { X = (X | (1 << (i - 1))); }
inline int bit(int X, int i) { return ((X >> (i - 1)) & 1); }
///--------------------------
bool dp(int mask1, int mask2, int id) {
if (F[mask1][mask2][id] != -1)
return F[mask1][mask2][id];
bool rs = &F[mask1][mask2][id];
if (mask1 == 0 && id == 0)
return (rs = 1);
if (mask2 == 0 && id == 1)
return (rs = 1);
int tmp = 0;
on(tmp, 7);
fo(i, 1, 6) if (!bit(mask1, i)) on(tmp, a[i]);
fo(i, 1, 6) if (!bit(mask2, i)) on(tmp, b[i]);
rs = 0;
if (id == 0) {
int yes = 0;
fo(i, 1, 6) if (bit(mask1, i) &&
((a[i] > 1 && bit(tmp, a[i] - 1)) || bit(tmp, a[i] + 1))) {
rs |= (!dp(mask1 & (~(1 << (i - 1))), mask2, 1));
yes = 1;
}
if (yes == 0)
rs |= (!dp(mask1, mask2, 1));
return rs;
} else {
int yes = 0;
fo(i, 1, 6) if (bit(mask2, i) &&
((b[i] > 1 && bit(tmp, b[i] - 1)) || bit(tmp, b[i] + 1))) {
rs |= (!dp(mask1, mask2 & (~(1 << (i - 1))), 0));
yes = 1;
}
if (yes == 0)
rs |= (!dp(mask1, mask2, 0));
return rs;
}
}
///--------------------------
void solve() {
memset(F, -1, sizeof(F));
cout << (dp(63, 63, 0) ? "yes\n" : "no\n");
}
///--------------------------
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
while (n--) {
readf();
solve();
}
}
| delete | 73 | 77 | 73 | 73 | 0 | |
p00343 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> AP;
vector<int> AQ;
vector<int> BP;
vector<int> BQ;
bool check(vector<int> AP, int ap, int r) {
if (AP[ap] == r)
return true;
return false;
}
bool dfs(int p, int ap, int aq, int bp, int bq, int l, int r) {
if (p == 1) { // 先手
if (ap >= AP.size() && aq >= AQ.size())
return true; // 先手の勝ち
} else {
if (bp >= BP.size() && bq >= BQ.size())
return false; // 先手の負け
}
int cnt = 0;
if (p == 0) { // A 先手の番
if (check(AP, ap, l - 1)) { // 小さいカードを出せる
++cnt;
if (dfs((p + 1) % 2, ap + 1, aq, bp, bq, l - 1, r))
return true;
}
if (check(AQ, aq, r + 1)) { // 大きいカードを出せる
++cnt;
if (dfs((p + 1) % 2, ap, aq + 1, bp, bq, l, r + 1))
return true;
}
if (cnt == 0) { // パス
if (dfs((p + 1) % 2, ap, aq, bp, bq, l, r))
return true;
}
return false;
}
else { // B 後手の番
bool possible = true;
if (check(BP, bp, l - 1)) {
++cnt;
if (!dfs((p + 1) % 2, ap, aq, bp + 1, bq, l - 1, r))
possible = false;
}
if (check(BQ, bq, r + 1)) {
++cnt;
if (!dfs((p + 1) % 2, ap, aq, bp, bq + 1, l, r + 1))
possible = false;
}
if (cnt == 0) { // パス
if (!dfs((p + 1) % 2, ap, aq, bp, bq, l, r))
possible = false;
}
return possible;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
AP.clear();
AQ.clear();
BP.clear();
BQ.clear();
bool used[14] = {};
int input;
for (int j = 0; j < 6; ++j) {
cin >> input;
if (input < 7) {
AP.push_back(input);
used[input] = true;
} else if (7 < input) {
AQ.push_back(input);
used[input] = true;
}
}
sort(AQ.begin(), AQ.end());
sort(AP.begin(), AP.end(), greater<int>());
for (int j = 6; j >= 1; --j) {
if (used[j] == false) {
BP.push_back(j);
}
}
for (int j = 8; j <= 13; ++j) {
if (used[j] == false) {
BQ.push_back(j);
}
}
/*
for(int j = 0;j < AP.size();++j){
cout << AP[j] << ' ';
}
cout << "|";
for(int j = 0;j < AQ.size();++j){
cout << AQ[j] << ' ';
}
cout << endl;
for(int j = 0;j < BP.size();++j){
cout << BP[j] << ' ';
}
cout << "|";
for(int j = 0;j < BQ.size();++j){
cout << BQ[j] << ' ';
}
cout << endl;
*/
if (dfs(0, 0, 0, 0, 0, 7, 7))
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> AP;
vector<int> AQ;
vector<int> BP;
vector<int> BQ;
bool check(vector<int> AP, int ap, int r) {
if (AP.size() <= ap)
return false;
if (AP[ap] == r)
return true;
return false;
}
bool dfs(int p, int ap, int aq, int bp, int bq, int l, int r) {
if (p == 1) { // 先手
if (ap >= AP.size() && aq >= AQ.size())
return true; // 先手の勝ち
} else {
if (bp >= BP.size() && bq >= BQ.size())
return false; // 先手の負け
}
int cnt = 0;
if (p == 0) { // A 先手の番
if (check(AP, ap, l - 1)) { // 小さいカードを出せる
++cnt;
if (dfs((p + 1) % 2, ap + 1, aq, bp, bq, l - 1, r))
return true;
}
if (check(AQ, aq, r + 1)) { // 大きいカードを出せる
++cnt;
if (dfs((p + 1) % 2, ap, aq + 1, bp, bq, l, r + 1))
return true;
}
if (cnt == 0) { // パス
if (dfs((p + 1) % 2, ap, aq, bp, bq, l, r))
return true;
}
return false;
}
else { // B 後手の番
bool possible = true;
if (check(BP, bp, l - 1)) {
++cnt;
if (!dfs((p + 1) % 2, ap, aq, bp + 1, bq, l - 1, r))
possible = false;
}
if (check(BQ, bq, r + 1)) {
++cnt;
if (!dfs((p + 1) % 2, ap, aq, bp, bq + 1, l, r + 1))
possible = false;
}
if (cnt == 0) { // パス
if (!dfs((p + 1) % 2, ap, aq, bp, bq, l, r))
possible = false;
}
return possible;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
AP.clear();
AQ.clear();
BP.clear();
BQ.clear();
bool used[14] = {};
int input;
for (int j = 0; j < 6; ++j) {
cin >> input;
if (input < 7) {
AP.push_back(input);
used[input] = true;
} else if (7 < input) {
AQ.push_back(input);
used[input] = true;
}
}
sort(AQ.begin(), AQ.end());
sort(AP.begin(), AP.end(), greater<int>());
for (int j = 6; j >= 1; --j) {
if (used[j] == false) {
BP.push_back(j);
}
}
for (int j = 8; j <= 13; ++j) {
if (used[j] == false) {
BQ.push_back(j);
}
}
/*
for(int j = 0;j < AP.size();++j){
cout << AP[j] << ' ';
}
cout << "|";
for(int j = 0;j < AQ.size();++j){
cout << AQ[j] << ' ';
}
cout << endl;
for(int j = 0;j < BP.size();++j){
cout << BP[j] << ' ';
}
cout << "|";
for(int j = 0;j < BQ.size();++j){
cout << BQ[j] << ' ';
}
cout << endl;
*/
if (dfs(0, 0, 0, 0, 0, 7, 7))
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
| insert | 9 | 9 | 9 | 11 | -11 | |
p00344 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg) \
if (flg) { \
cout << "yes" << endl; \
} else { \
cout << "no" << endl; \
}
#define vi vector<int>
#define MAX_N 200005
#define i197 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, P1> P2;
const int inf = 1000000000;
P1 xy[MAX_N] = {};
bool dp[100001] = {};
int main() {
int n;
cin >> n;
int a[100001];
rep(i, n) cin >> a[i];
int t = 0;
rep(i, n) {
if (dp[i])
continue;
bool dp2[100001] = {};
dp[i] = true;
dp2[i] = true;
int k = (i + a[i]) % n;
while (1) {
if (dp2[k]) {
if (k == i) {
// success
rep(j, n) {
if (dp2[j]) {
t++;
dp[j] = true;
}
}
}
break;
}
if (dp[k]) {
// rep(j,n){
// if(dp2[j])dp[j]=true;
// //false
// }
// break;
}
dp2[k] = true;
k = (k + a[k]) % n;
}
}
cout << t << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg) \
if (flg) { \
cout << "yes" << endl; \
} else { \
cout << "no" << endl; \
}
#define vi vector<int>
#define MAX_N 200005
#define i197 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, P1> P2;
const int inf = 1000000000;
P1 xy[MAX_N] = {};
bool dp[100001] = {};
int main() {
int n;
cin >> n;
int a[100001];
rep(i, n) cin >> a[i];
int t = 0;
rep(i, n) {
if (dp[i])
continue;
bool dp2[100001] = {};
dp[i] = true;
dp2[i] = true;
int k = (i + a[i]) % n;
while (1) {
if (dp2[k]) {
if (k == i) {
// success
t++;
k = (k + a[k]) % n;
while (k != i) {
t++;
dp[k] = true;
k = (k + a[k]) % n;
}
}
break;
}
if (dp[k]) {
// rep(j,n){
// if(dp2[j])dp[j]=true;
// //false
// }
// break;
}
dp2[k] = true;
k = (k + a[k]) % n;
}
}
cout << t << endl;
return 0;
}
| replace | 40 | 45 | 40 | 46 | TLE | |
p00344 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool a[10000], s[10000];
int b[10000], c[10000];
signed main() {
int d, sum = 0;
cin >> d;
for (int e = 0; e < d; e++) {
scanf("%d", &b[e]);
}
for (int i = 0; i < d; i++) {
if (!a[i]) {
memset(c, 0, sizeof(c));
int now = i;
while (1) {
a[now] = true;
if (c[now] == 2)
break;
else if (c[now] == 1)
s[now] = true;
c[now]++;
now += b[now];
now %= d;
}
}
}
for (bool u : s)
sum += u;
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
bool a[100000], s[100000];
int b[100000], c[100000];
signed main() {
int d, sum = 0;
cin >> d;
for (int e = 0; e < d; e++) {
scanf("%d", &b[e]);
}
for (int i = 0; i < d; i++) {
if (!a[i]) {
memset(c, 0, sizeof(c));
int now = i;
while (1) {
a[now] = true;
if (c[now] == 2)
break;
else if (c[now] == 1)
s[now] = true;
c[now]++;
now += b[now];
now %= d;
}
}
}
for (bool u : s)
sum += u;
cout << sum << endl;
} | replace | 3 | 5 | 3 | 5 | 0 | |
p00344 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
struct SCC { // O(V+E)
static const int MAX_V = 10100;
int V;
vector<int> G[MAX_V], rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];
vector<vector<int>> res;
SCC(int v) : V(v){};
void add_edge(int from, int to) {
G[from].push_back(to);
rG[to].push_back(from);
}
void dfs(int v) {
used[v] = true;
for (int i = 0; i < G[v].size(); i++) {
if (!used[G[v][i]])
dfs(G[v][i]);
}
vs.push_back(v);
}
void rdfs(int v, int k) {
used[v] = true;
cmp[v] = k;
for (int i = 0; i < rG[v].size(); i++) {
if (!used[rG[v][i]])
rdfs(rG[v][i], k);
}
}
int scc() {
memset(used, 0, sizeof(used));
vs.clear();
for (int v = 0; v < V; v++) {
if (!used[v])
dfs(v);
}
memset(used, 0, sizeof(used));
int k = 0;
for (int i = vs.size() - 1; i >= 0; i--) {
if (!used[vs[i]])
rdfs(vs[i], k++);
}
res.clear();
res.resize(k);
for (int i = 0; i < V; i++) {
res[cmp[i]].push_back(i);
}
return k;
}
};
int main() {
int ans = 0;
int n;
cin >> n;
SCC scc(n);
rep(i, n) {
int a;
cin >> a;
(a += i) %= n;
if (a == i)
ans++;
else
scc.add_edge(i, a);
}
scc.scc();
for (auto a : scc.res) {
if (a.size() != 1)
ans += a.size();
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
struct SCC { // O(V+E)
static const int MAX_V = 101000;
int V;
vector<int> G[MAX_V], rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];
vector<vector<int>> res;
SCC(int v) : V(v){};
void add_edge(int from, int to) {
G[from].push_back(to);
rG[to].push_back(from);
}
void dfs(int v) {
used[v] = true;
for (int i = 0; i < G[v].size(); i++) {
if (!used[G[v][i]])
dfs(G[v][i]);
}
vs.push_back(v);
}
void rdfs(int v, int k) {
used[v] = true;
cmp[v] = k;
for (int i = 0; i < rG[v].size(); i++) {
if (!used[rG[v][i]])
rdfs(rG[v][i], k);
}
}
int scc() {
memset(used, 0, sizeof(used));
vs.clear();
for (int v = 0; v < V; v++) {
if (!used[v])
dfs(v);
}
memset(used, 0, sizeof(used));
int k = 0;
for (int i = vs.size() - 1; i >= 0; i--) {
if (!used[vs[i]])
rdfs(vs[i], k++);
}
res.clear();
res.resize(k);
for (int i = 0; i < V; i++) {
res[cmp[i]].push_back(i);
}
return k;
}
};
int main() {
int ans = 0;
int n;
cin >> n;
SCC scc(n);
rep(i, n) {
int a;
cin >> a;
(a += i) %= n;
if (a == i)
ans++;
else
scc.add_edge(i, a);
}
scc.scc();
for (auto a : scc.res) {
if (a.size() != 1)
ans += a.size();
}
cout << ans << endl;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p00345 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int e, f1, f2, g1, g2;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cin >> S;
string T;
bool flag = false;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '.') {
e = stoi(T);
T = "";
} else if (S[i] == '(') {
f1 = stoi(T);
f2 = pow(10, T.size());
T = "";
flag = true;
} else if (S[i] == ')') {
g1 = stoi(T);
g2 = pow(10, T.size()) - 1;
T = "";
} else {
T += S[i];
}
}
if (flag == false) {
f1 = stoi(T);
f2 = pow(10, T.size());
g1 = 0;
g2 = 1;
}
int E1 = e * f2 * g2 + f1 * g2 + g1, E2 = f2 * g2;
cout << E1 / gcd(E1, E2) << "/" << E2 / gcd(E1, E2) << endl;
return 0;
} | #include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int e, f1, f2, g1, g2;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cin >> S;
string T;
bool flag = false;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '.') {
e = stoi(T);
T = "";
} else if (S[i] == '(') {
if (T.size() >= 1) {
f1 = stoi(T);
}
f2 = pow(10, T.size());
T = "";
flag = true;
} else if (S[i] == ')') {
g1 = stoi(T);
g2 = pow(10, T.size()) - 1;
T = "";
} else {
T += S[i];
}
}
if (flag == false) {
f1 = stoi(T);
f2 = pow(10, T.size());
g1 = 0;
g2 = 1;
}
int E1 = e * f2 * g2 + f1 * g2 + g1, E2 = f2 * g2;
cout << E1 / gcd(E1, E2) << "/" << E2 / gcd(E1, E2) << endl;
return 0;
} | replace | 20 | 21 | 20 | 23 | -6 | terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
|
p00346 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
const int LIM = 1.5e3 + 5;
struct data {
int x, d;
};
bool operator<(data a, data b) { return a.d > b.d; }
int n, m, dis[LIM][LIM], max, ans;
std::vector<data> edg[LIM];
bool chk[LIM], vis[LIM];
std::priority_queue<data> q;
void dijkstra(int s, int *dis) {
q.push({s, 0});
while (!q.empty()) {
data x = q.top();
q.pop();
if (!vis[x.x]) {
vis[x.x] = true;
dis[x.x] = x.d;
for (data y : edg[x.x])
if (!vis[y.x])
q.push({y.x, x.d + y.d});
}
}
}
void trace(int x, int *dis) {
if (!chk[x]) {
--ans;
chk[x] = true;
}
for (data y : edg[x])
if (!vis[y.x] && dis[y.x] == dis[x] - y.d)
trace(y.x, dis);
}
int main() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v, d;
scanf("%d%d%d", &u, &v, &d);
edg[u].push_back({v, d});
edg[v].push_back({u, d});
}
for (int i = 1; i <= n; ++i) {
memset(vis, 0x00, sizeof(vis));
dijkstra(i, dis[i]);
for (int j = 1; j <= n; ++j)
max = std::max(max, dis[i][j]);
}
for (int i = 1; i <= n; ++i) {
memset(vis, 0x00, sizeof(vis));
for (int j = 1; j <= n; ++j)
if (dis[i][j] == max)
trace(j, dis[i]);
}
printf("%d\n", ans + n);
for (int i = 1; i <= n; ++i)
if (!chk[i])
printf("%d\n", i);
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
const int LIM = 1.5e3 + 5;
struct data {
int x, d;
};
bool operator<(data a, data b) { return a.d > b.d; }
int n, m, dis[LIM][LIM], max, ans;
std::vector<data> edg[LIM];
bool chk[LIM], vis[LIM];
std::priority_queue<data> q;
void dijkstra(int s, int *dis) {
q.push({s, 0});
while (!q.empty()) {
data x = q.top();
q.pop();
if (!vis[x.x]) {
vis[x.x] = true;
dis[x.x] = x.d;
for (data y : edg[x.x])
if (!vis[y.x])
q.push({y.x, x.d + y.d});
}
}
}
void trace(int x, int *dis) {
vis[x] = true;
if (!chk[x]) {
--ans;
chk[x] = true;
}
for (data y : edg[x])
if (!vis[y.x] && dis[y.x] == dis[x] - y.d)
trace(y.x, dis);
}
int main() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v, d;
scanf("%d%d%d", &u, &v, &d);
edg[u].push_back({v, d});
edg[v].push_back({u, d});
}
for (int i = 1; i <= n; ++i) {
memset(vis, 0x00, sizeof(vis));
dijkstra(i, dis[i]);
for (int j = 1; j <= n; ++j)
max = std::max(max, dis[i][j]);
}
for (int i = 1; i <= n; ++i) {
memset(vis, 0x00, sizeof(vis));
for (int j = 1; j <= n; ++j)
if (dis[i][j] == max)
trace(j, dis[i]);
}
printf("%d\n", ans + n);
for (int i = 1; i <= n; ++i)
if (!chk[i])
printf("%d\n", i);
}
| insert | 34 | 34 | 34 | 35 | TLE | |
p00346 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, M;
vector<P> G[1500];
int D[1500][1500];
void dijkstra(int s) {
int *dist = D[s];
priority_queue<P, vector<P>, greater<P>> q;
dist[s] = 0;
q.push(P(0, s));
while (!q.empty()) {
int x = q.top()._2, r = q.top()._1;
q.pop();
if (dist[x] < r)
continue;
for (P p : G[x]) {
int t = p._1, l = p._2;
if (dist[t] > r + l) {
dist[t] = r + l;
q.push(P(r + l, t));
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
rep(i, M) {
int s, t, d;
cin >> s >> t >> d;
s--, t--;
G[s].pb(P(t, d));
G[t].pb(P(s, d));
}
rep(i, N) rep(j, N) D[i][j] = INF;
rep(i, N) dijkstra(i);
int R = 0;
rep(i, N) rep(j, N) R = max(R, D[i][j]);
vector<int> ans;
rep(i, N) {
vector<int> rs;
map<int, vector<int>> vs;
rep(j, N) rs.pb(D[i][j]), vs[D[i][j]].pb(j);
sort(all(rs));
// for (int x:rs)cout<<x<<",";cout<<" i="<<i<<"\n";
bool ok = true;
for (int x : rs) {
if (binary_search(all(rs), R - x)) {
for (int s : vs[x]) {
for (int t : vs[R - x]) {
if (D[s][t] == R) {
ok = false;
break;
}
}
}
}
}
if (ok)
ans.pb(i);
}
cout << ans.size() << "\n";
for (int x : ans)
cout << x + 1 << "\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, M;
vector<P> G[1500];
int D[1500][1500];
void dijkstra(int s) {
int *dist = D[s];
priority_queue<P, vector<P>, greater<P>> q;
dist[s] = 0;
q.push(P(0, s));
while (!q.empty()) {
int x = q.top()._2, r = q.top()._1;
q.pop();
if (dist[x] < r)
continue;
for (P p : G[x]) {
int t = p._1, l = p._2;
if (dist[t] > r + l) {
dist[t] = r + l;
q.push(P(r + l, t));
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
rep(i, M) {
int s, t, d;
cin >> s >> t >> d;
s--, t--;
G[s].pb(P(t, d));
G[t].pb(P(s, d));
}
rep(i, N) rep(j, N) D[i][j] = INF;
rep(i, N) dijkstra(i);
int R = 0;
rep(i, N) rep(j, N) R = max(R, D[i][j]);
vector<int> ans;
rep(i, N) {
vector<int> rs;
map<int, vector<int>> vs;
rep(j, N) rs.pb(D[i][j]), vs[D[i][j]].pb(j);
sort(all(rs));
uniq(rs);
// for (int x:rs)cout<<x<<",";cout<<" i="<<i<<"\n";
bool ok = true;
for (int x : rs) {
if (binary_search(all(rs), R - x)) {
for (int s : vs[x]) {
for (int t : vs[R - x]) {
if (D[s][t] == R) {
ok = false;
break;
}
}
}
}
}
if (ok)
ans.pb(i);
}
cout << ans.size() << "\n";
for (int x : ans)
cout << x + 1 << "\n";
return 0;
} | insert | 71 | 71 | 71 | 72 | TLE | |
p00347 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int w, h;
int dp[2000][2000][2], s[2000][2000];
int sum[2000][2000];
int dx[]{1, 0}, dy[]{0, 1};
int rec(int x, int y, int a) {
if (dp[x][y][a] != -1)
return dp[x][y][a];
if (y == w)
return 0;
int res = (a == 0 ? INT_MIN : INT_MAX);
rep(i, 2) {
int nx = x + dx[i], ny = y + dy[i];
if (nx > h)
continue;
int b = rec(nx, ny, !a) + (i == 1 ? sum[x][y] : 0);
if (a == 0)
res = max(res, b);
else
res = min(res, b);
}
return res;
}
int main() {
scanf("%d%d", &w, &h);
rep(i, h) rep(j, w) scanf("%d", &s[i][j]);
int a = 0;
rep(i, w) rep(j, h) {
sum[j + 1][i] = sum[j][i] + s[j][i];
a += s[j][i];
}
memset(dp, -1, sizeof(dp));
cout << abs(a - rec(0, 0, 0) * 2) << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int w, h;
int dp[2000][2000][2], s[2000][2000];
int sum[2000][2000];
int dx[]{1, 0}, dy[]{0, 1};
int rec(int x, int y, int a) {
if (dp[x][y][a] != -1)
return dp[x][y][a];
if (y == w)
return 0;
int res = (a == 0 ? INT_MIN : INT_MAX);
rep(i, 2) {
int nx = x + dx[i], ny = y + dy[i];
if (nx > h)
continue;
int b = rec(nx, ny, !a) + (i == 1 ? sum[x][y] : 0);
if (a == 0)
res = max(res, b);
else
res = min(res, b);
}
return dp[x][y][a] = res;
}
int main() {
scanf("%d%d", &w, &h);
rep(i, h) rep(j, w) scanf("%d", &s[i][j]);
int a = 0;
rep(i, w) rep(j, h) {
sum[j + 1][i] = sum[j][i] + s[j][i];
a += s[j][i];
}
memset(dp, -1, sizeof(dp));
cout << abs(a - rec(0, 0, 0) * 2) << endl;
} | replace | 25 | 26 | 25 | 26 | TLE | |
p00348 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define removeDuplicate(a) \
sort(a.begin(), a.end()); \
a.resize(distance(a.begin(), unique(a.begin(), a.end())));
const int N = 2e5 + 10;
int n;
int a[N];
set<int> *q[N];
void merge(set<int> *&a, set<int> *&b) {
if (a->size() > b->size()) {
for (auto value : *b) {
a->insert(value);
}
b->clear();
} else {
for (auto value : *a) {
b->insert(value);
}
a->clear();
a = b;
}
}
void zip() {
vector<int> rar;
for (int i = 1; i <= n; i++) {
rar.push_back(a[i]);
}
removeDuplicate(rar);
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(rar.begin(), rar.end(), a[i]) - rar.begin() + 1;
}
}
int main() {
#define file "9"
// freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
cin >> n;
for (int i = 1; i <= 3 * n; i++) {
q[i] = new set<int>;
}
for (int i = 1; i <= n; i++) {
int value;
cin >> value;
a[i] = value;
}
zip();
for (int i = 1; i <= n; i++) {
q[i]->insert(a[i]);
}
long long ret = 0;
int front = 1, back = n;
for (int value = 1; value <= n; value++) {
for (int i = front; i <= back; i++) {
merge(q[back + 1], q[i]);
front++;
if (q[back + 1]->find(value) != q[back + 1]->end()) {
break;
}
}
back++;
q[back]->erase(value);
if (q[back]->empty()) {
back--;
continue;
}
ret += ((int)(q[back]->size()));
}
cout << ret << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define removeDuplicate(a) \
sort(a.begin(), a.end()); \
a.resize(distance(a.begin(), unique(a.begin(), a.end())));
const int N = 6e5 + 10;
int n;
int a[N];
set<int> *q[N];
void merge(set<int> *&a, set<int> *&b) {
if (a->size() > b->size()) {
for (auto value : *b) {
a->insert(value);
}
b->clear();
} else {
for (auto value : *a) {
b->insert(value);
}
a->clear();
a = b;
}
}
void zip() {
vector<int> rar;
for (int i = 1; i <= n; i++) {
rar.push_back(a[i]);
}
removeDuplicate(rar);
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(rar.begin(), rar.end(), a[i]) - rar.begin() + 1;
}
}
int main() {
#define file "9"
// freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
cin >> n;
for (int i = 1; i <= 3 * n; i++) {
q[i] = new set<int>;
}
for (int i = 1; i <= n; i++) {
int value;
cin >> value;
a[i] = value;
}
zip();
for (int i = 1; i <= n; i++) {
q[i]->insert(a[i]);
}
long long ret = 0;
int front = 1, back = n;
for (int value = 1; value <= n; value++) {
for (int i = front; i <= back; i++) {
merge(q[back + 1], q[i]);
front++;
if (q[back + 1]->find(value) != q[back + 1]->end()) {
break;
}
}
back++;
q[back]->erase(value);
if (q[back]->empty()) {
back--;
continue;
}
ret += ((int)(q[back]->size()));
}
cout << ret << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p00348 | 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;
typedef set<int> Group;
Group *make_group(int num) {
Group *new_group = new Group();
new_group->insert(num);
return new_group;
}
Group *merge(Group *left, Group *right) {
if (left->size() < right->size()) {
swap(left, right);
}
for (Group::iterator it = right->begin(); it != right->end(); it++)
left->insert(*it);
return left;
}
int main() {
int N;
scanf("%d", &N);
queue<Group *> Q;
vector<int> V, WORK;
int tmp;
map<int, int> MAP;
for (int i = 0; i < N; i++) {
scanf("%d", &tmp);
V.push_back(tmp);
WORK.push_back(tmp);
}
sort(WORK.begin(), WORK.end());
for (int i = 0; i < N; i++) {
MAP[WORK[i]] = i + 1;
}
for (int i = 0; i < N; i++) {
V[i] = MAP[V[i]];
}
for (int i = 0; i < N; i++) {
Q.push(make_group(V[i]));
}
ll ans = 0;
for (int num = 1; num <= N; num++) {
Group *group = Q.front();
Q.pop();
while (true) {
if (*(group->begin()) == num) {
group->erase(group->begin());
ans += group->size();
if (group->size() > 0) {
Q.push(group);
}
break;
}
Group *next_group = Q.front();
Q.pop();
merge(group, next_group);
}
}
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;
typedef set<int> Group;
Group *make_group(int num) {
Group *new_group = new Group();
new_group->insert(num);
return new_group;
}
Group *merge(Group *left, Group *right) {
if (left->size() < right->size()) {
swap(left, right);
}
for (Group::iterator it = right->begin(); it != right->end(); it++)
left->insert(*it);
return left;
}
int main() {
int N;
scanf("%d", &N);
queue<Group *> Q;
vector<int> V, WORK;
int tmp;
map<int, int> MAP;
for (int i = 0; i < N; i++) {
scanf("%d", &tmp);
V.push_back(tmp);
WORK.push_back(tmp);
}
sort(WORK.begin(), WORK.end());
for (int i = 0; i < N; i++) {
MAP[WORK[i]] = i + 1;
}
for (int i = 0; i < N; i++) {
V[i] = MAP[V[i]];
}
for (int i = 0; i < N; i++) {
Q.push(make_group(V[i]));
}
ll ans = 0;
for (int num = 1; num <= N; num++) {
Group *group = Q.front();
Q.pop();
while (true) {
if (*(group->begin()) == num) {
group->erase(group->begin());
ans += group->size();
if (group->size() > 0) {
Q.push(group);
}
break;
}
Group *next_group = Q.front();
Q.pop();
group = merge(group, next_group);
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 83 | 84 | 83 | 84 | 0 | |
p00348 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>
const int LIM = 1e5 + 5;
int n, dsu[LIM], a[LIM], b[LIM];
long long ans;
std::map<int, int> map;
std::queue<int> q;
int root(int x) {
if (dsu[x] <= 0)
return x;
else
return dsu[x] = root(dsu[x]);
}
void merge(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (dsu[x] < dsu[y])
std::swap(x, y);
dsu[y] += dsu[x];
dsu[x] = y;
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
b[i] = a[i];
}
std::sort(b + 1, b + n + 1);
for (int i = 1; i <= n; ++i)
map[b[i]] = i;
for (int i = 1; i <= n; ++i)
a[i] = map[a[i]];
a[n + 1] = n + 1;
memset(dsu, 0xff, sizeof(dsu));
for (int i = 1; i <= n; ++i)
q.push(a[i]);
for (int i = 1; i <= n; ++i) {
int s = root(q.front());
q.pop();
while (root(i) != root(s)) {
merge(s, q.front());
q.pop();
}
ans -= ++dsu[root(s)];
// printf("%d -> %d\n", i, -dsu[root(s)]);
q.push(root(s));
}
printf("%lld\n", ans);
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>
const int LIM = 2e5 + 5;
int n, dsu[LIM], a[LIM], b[LIM];
long long ans;
std::map<int, int> map;
std::queue<int> q;
int root(int x) {
if (dsu[x] <= 0)
return x;
else
return dsu[x] = root(dsu[x]);
}
void merge(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (dsu[x] < dsu[y])
std::swap(x, y);
dsu[y] += dsu[x];
dsu[x] = y;
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
b[i] = a[i];
}
std::sort(b + 1, b + n + 1);
for (int i = 1; i <= n; ++i)
map[b[i]] = i;
for (int i = 1; i <= n; ++i)
a[i] = map[a[i]];
a[n + 1] = n + 1;
memset(dsu, 0xff, sizeof(dsu));
for (int i = 1; i <= n; ++i)
q.push(a[i]);
for (int i = 1; i <= n; ++i) {
int s = root(q.front());
q.pop();
while (root(i) != root(s)) {
merge(s, q.front());
q.pop();
}
ans -= ++dsu[root(s)];
// printf("%d -> %d\n", i, -dsu[root(s)]);
q.push(root(s));
}
printf("%lld\n", ans);
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p00349 | C++ | Runtime Error | // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0354
#include <bits/stdc++.h>
const int N = 1e5 + 5;
const int inf = 1e9 + 7;
using namespace std;
vector<int> mv[2];
int n, w, h, x[N], y[N], p[N], ans[N];
char s[N];
void cal(vector<int> &a, bool ck) {
if (a.size() == 0)
return;
queue<int> Q1, Q2;
for (int i = 0; i < a.size(); i++)
if (s[a[i]] == 'E')
Q1.push(a[i]);
for (int i = (int)a.size() - 1; i >= 0; i--)
if (s[a[i]] == 'S')
Q2.push(a[i]);
// if (x[a[0]] + y[a[0]] == 6 && ck)
// for (int i = 0; i < a.size(); i++)
// cout << a[i] << " " << x[a[i]] << " " << y[a[i]] << " " << s[a[i]]
// << "\n";
//
// cout << "\n";
for (int i = 0; i < a.size(); i++) {
int E = ((Q1.size()) ? Q1.front() : inf),
S = ((Q2.size()) ? Q2.front() : inf);
if (E != inf && (S == inf || w - x[E] < h - y[S])) {
ans[a[i]] = w - x[E] + 1 + ck;
Q1.pop();
} else {
ans[a.back()] = h - y[S] + 1 + ck;
a.pop_back();
Q2.pop();
i--;
}
}
// cout << "\n";
}
void change(vector<int> &a) {
for (int i = 1; i < a.size(); i++) {
if (x[a[i]] == x[a[i - 1]] && y[a[i]] == y[a[i - 1]])
swap(s[a[i]], s[a[i - 1]]), swap(a[i], a[i - 1]);
}
}
void solve(vector<int> &a, bool ck) {
vector<int> X, Y;
for (int i = 0; i < a.size(); i++) {
int sum = x[a[i]] + y[a[i]];
for (; i < a.size(); i++) {
if (x[a[i]] + y[a[i]] != sum)
break;
if (x[a[i]] % 2 == 0)
X.push_back(a[i]);
else
Y.push_back(a[i]);
}
cal(X, ck);
X.clear();
cal(Y, ck);
Y.clear();
i--;
}
}
bool cmp(int a, int b) {
if (x[a] + y[a] < x[b] + y[b])
return true;
if (x[a] + y[a] == x[b] + y[b] && x[a] > x[b])
return true;
if (x[a] == x[b] && y[a] == y[b] && s[a] == 'E')
return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> w >> h >> n;
vector<int> vc;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> s[i];
if (s[i] == 'E')
vc.push_back(w - x[i] + 1);
else
vc.push_back(h - y[i] + 1);
if ((x[i] + y[i]) % 2 == 1) {
if (s[i] == 'E')
x[i]++;
else
y[i]++;
mv[1].push_back(i);
} else {
mv[0].push_back(i);
}
}
sort(mv[0].begin(), mv[0].end(), cmp);
sort(mv[1].begin(), mv[1].end(), cmp);
change(mv[1]);
solve(mv[0], 0);
solve(mv[1], 1);
sort(vc.begin(), vc.end());
for (int i = 1; i <= n; i++)
p[i] = i;
sort(p + 1, p + 1 + n, [](int x, int y) {
return ((ans[x] < ans[y]) || (ans[x] == ans[y] && x < y));
});
for (int i = 1; i <= n; i++)
cout << p[i] << "\n";
}
| // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0354
#include <bits/stdc++.h>
const int N = 2e5 + 5;
const int inf = 1e9 + 7;
using namespace std;
vector<int> mv[2];
int n, w, h, x[N], y[N], p[N], ans[N];
char s[N];
void cal(vector<int> &a, bool ck) {
if (a.size() == 0)
return;
queue<int> Q1, Q2;
for (int i = 0; i < a.size(); i++)
if (s[a[i]] == 'E')
Q1.push(a[i]);
for (int i = (int)a.size() - 1; i >= 0; i--)
if (s[a[i]] == 'S')
Q2.push(a[i]);
// if (x[a[0]] + y[a[0]] == 6 && ck)
// for (int i = 0; i < a.size(); i++)
// cout << a[i] << " " << x[a[i]] << " " << y[a[i]] << " " << s[a[i]]
// << "\n";
//
// cout << "\n";
for (int i = 0; i < a.size(); i++) {
int E = ((Q1.size()) ? Q1.front() : inf),
S = ((Q2.size()) ? Q2.front() : inf);
if (E != inf && (S == inf || w - x[E] < h - y[S])) {
ans[a[i]] = w - x[E] + 1 + ck;
Q1.pop();
} else {
ans[a.back()] = h - y[S] + 1 + ck;
a.pop_back();
Q2.pop();
i--;
}
}
// cout << "\n";
}
void change(vector<int> &a) {
for (int i = 1; i < a.size(); i++) {
if (x[a[i]] == x[a[i - 1]] && y[a[i]] == y[a[i - 1]])
swap(s[a[i]], s[a[i - 1]]), swap(a[i], a[i - 1]);
}
}
void solve(vector<int> &a, bool ck) {
vector<int> X, Y;
for (int i = 0; i < a.size(); i++) {
int sum = x[a[i]] + y[a[i]];
for (; i < a.size(); i++) {
if (x[a[i]] + y[a[i]] != sum)
break;
if (x[a[i]] % 2 == 0)
X.push_back(a[i]);
else
Y.push_back(a[i]);
}
cal(X, ck);
X.clear();
cal(Y, ck);
Y.clear();
i--;
}
}
bool cmp(int a, int b) {
if (x[a] + y[a] < x[b] + y[b])
return true;
if (x[a] + y[a] == x[b] + y[b] && x[a] > x[b])
return true;
if (x[a] == x[b] && y[a] == y[b] && s[a] == 'E')
return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> w >> h >> n;
vector<int> vc;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> s[i];
if (s[i] == 'E')
vc.push_back(w - x[i] + 1);
else
vc.push_back(h - y[i] + 1);
if ((x[i] + y[i]) % 2 == 1) {
if (s[i] == 'E')
x[i]++;
else
y[i]++;
mv[1].push_back(i);
} else {
mv[0].push_back(i);
}
}
sort(mv[0].begin(), mv[0].end(), cmp);
sort(mv[1].begin(), mv[1].end(), cmp);
change(mv[1]);
solve(mv[0], 0);
solve(mv[1], 1);
sort(vc.begin(), vc.end());
for (int i = 1; i <= n; i++)
p[i] = i;
sort(p + 1, p + 1 + n, [](int x, int y) {
return ((ans[x] < ans[y]) || (ans[x] == ans[y] && x < y));
});
for (int i = 1; i <= n; i++)
cout << p[i] << "\n";
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p00351 | C++ | Time Limit Exceeded | ////////////////////
// ???????????????
#include <algorithm>
#include <cassert>
#include <cmath>
////////////////////
// ??¨????????¢???
using D = double;
////////////////////
// ?????°
const D EPS = 1e-9; // |EPS|???????????°???0??¨????????±???
enum POSITION {
ONLINE_FRONT = -2,
CLOCKWISE,
ON_SEGMENT,
COUNTER_CLOCKWISE,
ONLINE_BACK
}; // 3??????????????¢???
////////////////////
// ?§???????
struct Point {
D x, y;
Point(const D d = 0.0) : x(d), y(d) {}
Point(const D x, const D y) : x(x), y(y) {}
};
struct Segment {
Point initial, terminal;
Segment(const Point &initial, const Point &terminal)
: initial(initial), terminal(terminal) {}
Segment(const D x1, const D y1, const D x2, const D y2)
: initial(x1, y1), terminal(x2, y2) {}
};
struct Line {
Point initial, terminal;
Line(const Point &initial, const Point &terminal)
: initial(initial), terminal(terminal) {}
Line(const D x1, const D y1, const D x2, const D y2)
: initial(x1, y1), terminal(x2, y2) {}
Line(const Segment &s) : initial(s.initial), terminal(s.terminal) {}
};
////////////////////
// ????£?
bool relative_equal(const D d1, const D d2) {
return d1 == 0 ? std::abs(d2) < EPS : std::abs((d1 - d2) / d1) < EPS;
}
// ??????????????????????????????
bool operator==(const Point &lhs, const Point &rhs) {
return relative_equal(lhs.x, rhs.x) && relative_equal(lhs.y, rhs.y);
}
bool operator<(const Point &lhs, const Point &rhs) {
return relative_equal(lhs.x, rhs.x) ? lhs.y < rhs.y : lhs.x < rhs.x;
}
bool operator>(const Point &lhs, const Point &rhs) {
return relative_equal(lhs.x, rhs.x) ? lhs.y > rhs.y : lhs.x > rhs.x;
}
bool operator!=(const Point &lhs, const Point &rhs) { return !(lhs == rhs); }
bool operator<=(const Point &lhs, const Point &rhs) { return !(lhs > rhs); }
bool operator>=(const Point &lhs, const Point &rhs) { return !(lhs < rhs); }
const Point operator+(const Point &lhs, const Point &rhs) {
return Point(lhs.x + rhs.x, lhs.y + rhs.y);
}
const Point operator-(const Point &lhs, const Point &rhs) {
return Point(lhs.x - rhs.x, lhs.y - rhs.y);
}
const Point operator*(const Point &lhs, const Point &rhs) {
return Point(lhs.x * rhs.x, lhs.y * rhs.y);
}
const Point operator/(const Point &lhs, const Point &rhs) {
return Point(lhs.x / rhs.x, lhs.y / rhs.y);
}
const Point operator-(const Point &p) { return Point(-p.x, -p.y); }
// ???
D abs(const Point &p) { return std::hypot(p.x, p.y); }
D norm(const Point &p) { return p.x * p.x + p.y * p.y; }
D dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
D cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
// ??´???
bool parallel(const Line &l1, const Line &l2) {
return relative_equal(
0.0, cross(l2.terminal - l2.initial, l1.terminal - l1.initial));
}
bool orthogonal(const Line &l1, const Line &l2) {
return relative_equal(
0.0, dot(l2.terminal - l2.initial, l1.terminal - l1.initial));
}
// 3??????????????¢???
POSITION ccw(const Point &a, const Point &b, const Point &p) {
Point v1 = b - a;
Point v2 = p - a;
if (cross(v1, v2) >= EPS)
return COUNTER_CLOCKWISE;
if (cross(v1, v2) <= -EPS)
return CLOCKWISE;
if (dot(v1, v2) <= -EPS)
return ONLINE_BACK;
if (norm(v1) < norm(v2))
return ONLINE_FRONT; // ????????????: norm(v1)<norm(v2)+EPS?????¨WrongAnswer
return ON_SEGMENT;
}
// ????????????
bool intersect(const Point &p1, const Point &p2) { return p1 == p2; }
bool intersect(const Point &p, const Segment &s) {
return abs(p - s.initial) + abs(p - s.terminal) -
abs(s.initial - s.terminal) <=
EPS;
}
bool intersect(const Segment &s, const Point &p) { return intersect(p, s); }
bool intersect(const Point &p, const Line &l) {
return !parallel(Line(p, l.initial), Line(p, l.terminal));
}
bool intersect(const Line &l, const Point &p) { return intersect(p, l); }
bool intersect(const Segment &s1, const Segment &s2) {
return ccw(s1.initial, s1.terminal, s2.initial) *
ccw(s1.initial, s1.terminal, s2.terminal) <=
0 &&
ccw(s2.initial, s2.terminal, s1.initial) *
ccw(s2.initial, s2.terminal, s1.terminal) <=
0;
}
bool intersect(const Segment &s, const Line &l) {
auto v1 = l.terminal - l.initial;
auto v2 = s.initial - l.initial;
auto v3 = s.terminal - l.initial;
return cross(v1, v2) * cross(v1, v3) <= EPS;
}
bool intersect(const Line &l, const Segment &s) { return intersect(s, l); }
bool intersect(const Line &l1, const Line &l2) {
return !parallel(l1, l2) || intersect(l1.initial, l2);
}
// ???????§????
Point rotate(const Point &p, const D a) {
return Point(p.x * std::cos(a) - p.y * std::sin(a),
p.x * std::sin(a) + p.y * std::cos(a));
}
Point projection(const Point &p, const Line &l) {
auto v = l.initial - l.terminal;
return l.initial + dot(p - l.initial, v) / norm(v) * v;
}
Point projection(const Line &l, const Point &p) { return projection(p, l); }
Point reflection(const Point &p, const Line &l) {
return p + 2 * (projection(p, l) - p);
}
Point reflection(const Line &l, const Point &p) { return reflection(p, l); }
// ?????¢
D distance(const Point &p1, const Point &p2) {
auto p = p1 - p2;
return hypot(p.x, p.y);
}
D distance(const Point &p, const Segment &s) {
auto r = projection(s, p);
return intersect(r, s)
? distance(p, r)
: std::min(distance(p, s.initial), distance(p, s.terminal));
}
D distance(const Segment &s, const Point &p) { return distance(p, s); }
D distance(const Point &p, const Line &l) {
return distance(p, projection(p, l));
}
D distance(const Line &l, const Point &p) { return distance(p, l); }
D distance(const Segment &s1, const Segment &s2) {
return intersect(s1, s2)
? 0.0
: std::min({distance(s1, s2.initial), distance(s1, s2.terminal),
distance(s2, s1.initial), distance(s2, s1.terminal)});
}
D distance(const Segment &s, const Line &l) {
return intersect(s, l)
? 0.0
: std::min(distance(s.initial, l), distance(s.terminal, l));
}
D distance(const Line &l, const Segment &s) { return distance(s, l); }
D distance(const Line &l1, const Line &l2) {
return intersect(l1, l2) ? 0.0 : distance(l1.initial, l2);
}
// ??????
const Point crosspoint(const Line &l1, const Line &l2) {
assert(intersect(l1, l2));
if (parallel(l1, l2))
return l1.initial; // ???????????¨???l1????§?????????????
D A = cross(l1.terminal - l1.initial, l2.terminal - l2.initial);
D B = cross(l1.terminal - l1.initial, l1.terminal - l2.initial);
return l2.initial + B / A * (l2.terminal - l2.initial);
}
const Point crosspoint(const Segment &s, const Line &l) {
assert(intersect(s, l));
if (parallel(s, l))
return s.initial;
return crosspoint(Line(s), l);
}
const Point crosspoint(const Line &l, const Segment &s) {
return crosspoint(s, l);
}
const Point crosspoint(const Segment &s1, const Segment &s2) {
assert(intersect(s1, s2));
if (parallel(s1, s2)) { // ???????????¨?????????????????????????????????
if (intersect(s1.initial, s2))
return s1.initial;
if (intersect(s1.terminal, s2))
return s1.terminal;
if (intersect(s2.initial, s1))
return s2.initial;
if (intersect(s2.terminal, s1))
return s2.terminal;
}
return crosspoint(Line(s1), Line(s2));
}
////////////////////////////////////////////////////////////////////////////////
// ?????????
#include <vector>
const D PI = std::acos(-1);
struct Circle {
Point center;
D radius;
Circle(const Point ¢er = 0, const D radius = 0)
: center(center), radius(radius) {}
Circle(const D x, const D y, const D radius) : center(x, y), radius(radius) {}
};
D area(const Circle &c) { return PI * c.radius * c.radius; }
bool contain(const Circle &c, const Point &p) {
D d = abs(p - c.center);
if (relative_equal(c.radius, d))
return true;
return d < c.radius;
}
bool contain(const Point &p, const Circle &c) { return contain(c, p); }
#include <bits/stdc++.h>
using namespace std;
std::vector<Point> crosspoint(const Circle &c, const Line &l) {
std::vector<Point> cp;
Point p = projection(c.center, l);
if (!contain(c, p))
return cp;
Point v = p - c.center;
if (relative_equal(abs(v), 0)) {
Point p = l.initial - c.center;
if (p == 0)
p = l.terminal - c.center;
p = (c.radius * p / abs(p));
cp.push_back(c.center + p);
cp.push_back(c.center - p);
return cp;
}
D angle = acos(abs(v) / c.radius);
for (D a : {angle, -angle})
cp.push_back(c.center + c.radius * (rotate(v, a) / abs(v)));
return cp;
}
std::vector<Point> crosspoint(const Line &l, const Circle &c) {
return crosspoint(c, l);
}
int tangent(const Circle &c1, const Circle &c2) {
D d = abs(c1.center - c2.center);
D r = c1.radius + c2.radius;
if (relative_equal(d, r))
return 3; // ?????\
if(r < d) return 4; // ?????¢
r = std::abs(c1.radius - c2.radius);
if (relative_equal(d, r))
return 1; // ?????\
if(r < d) return 2; // ??????
return 0; // ??????
}
#include <bits/stdc++.h>
using namespace std;
int N;
D R;
vector<Point> P;
D triangle(const Point &a, const Point &b, const Point &c) {
return abs(cross(b - a, c - a)) / 2.0;
}
D sector(const Circle &c, Point a, Point b) {
a = a - c.center;
b = b - c.center;
auto angle = acos(dot(a, b) / abs(a) / abs(b));
return c.radius * c.radius * angle / 2.0;
// auto a1 = atan2(a.y - c.center.y, a.x - c.center.x);
// auto a2 = atan2(b.y - c.center.y, b.x - c.center.x);
// auto angle = a2 - a1;
// cout<<a1<<" "<<a2<<endl;
// cout<<angle<<endl;
// return c.radius * c.radius * angle / 2.0;
}
D area(const Circle &c, Point a, Point b) {
if (a > b)
swap(a, b);
if (a == b || c.center == a || c.center == b)
return 0;
// ??????2????????????
if (contain(c, a) && contain(c, b))
return triangle(c.center, a, b);
auto cp = crosspoint(c, Line(a, b));
// ????§???¢????????§?????????
if (cp.empty())
return sector(c, a, b);
if (cp[0] > cp[1])
swap(cp[0], cp[1]);
// 2???????????????
if (!contain(c, a) && !contain(c, b)) {
if (b < cp[0] || cp[1] < a)
return sector(c, a, b);
else
return sector(c, a, cp[0]) + triangle(c.center, cp[0], cp[1]) +
sector(c, cp[1], b);
}
// 1?????????????????????
if (contain(c, a))
return triangle(c.center, a, cp[1]) + sector(c, cp[1], b);
else
return triangle(c.center, cp[0], b) + sector(c, a, cp[0]);
}
bool ok(D h) {
D covered = 0;
Circle c(0, h, R);
for (auto i = 0; i < P.size(); ++i) {
auto &cur = P[i], nex = P[(i + 1) % P.size()];
auto rev = ccw(c.center, cur, nex) == COUNTER_CLOCKWISE;
covered += area(c, cur, nex) * (rev ? -1 : 1);
}
return covered < area(c) / 2.0;
}
int main() {
cin >> N >> R;
D p = -200;
P.emplace_back(p, -200);
for (auto i = 0; i < N; ++i) {
D x, w, h;
cin >> x >> w >> h;
if (p != x)
P.emplace_back(p, 0);
if (p != x)
P.emplace_back(x, 0);
P.emplace_back(x, h);
P.emplace_back(x + w, h);
p = x + w;
}
P.emplace_back(p, 0);
P.emplace_back(200, 0);
P.emplace_back(200, -200);
const int LIMIT = 1e5;
D low = -100, high = 200;
for (auto step = 0; step < LIMIT; ++step) {
auto middle = (low + high) / 2.0;
if (ok(middle))
high = middle;
else
low = middle;
}
cout << setprecision(8) << fixed << low << endl;
} | ////////////////////
// ???????????????
#include <algorithm>
#include <cassert>
#include <cmath>
////////////////////
// ??¨????????¢???
using D = double;
////////////////////
// ?????°
const D EPS = 1e-9; // |EPS|???????????°???0??¨????????±???
enum POSITION {
ONLINE_FRONT = -2,
CLOCKWISE,
ON_SEGMENT,
COUNTER_CLOCKWISE,
ONLINE_BACK
}; // 3??????????????¢???
////////////////////
// ?§???????
struct Point {
D x, y;
Point(const D d = 0.0) : x(d), y(d) {}
Point(const D x, const D y) : x(x), y(y) {}
};
struct Segment {
Point initial, terminal;
Segment(const Point &initial, const Point &terminal)
: initial(initial), terminal(terminal) {}
Segment(const D x1, const D y1, const D x2, const D y2)
: initial(x1, y1), terminal(x2, y2) {}
};
struct Line {
Point initial, terminal;
Line(const Point &initial, const Point &terminal)
: initial(initial), terminal(terminal) {}
Line(const D x1, const D y1, const D x2, const D y2)
: initial(x1, y1), terminal(x2, y2) {}
Line(const Segment &s) : initial(s.initial), terminal(s.terminal) {}
};
////////////////////
// ????£?
bool relative_equal(const D d1, const D d2) {
return d1 == 0 ? std::abs(d2) < EPS : std::abs((d1 - d2) / d1) < EPS;
}
// ??????????????????????????????
bool operator==(const Point &lhs, const Point &rhs) {
return relative_equal(lhs.x, rhs.x) && relative_equal(lhs.y, rhs.y);
}
bool operator<(const Point &lhs, const Point &rhs) {
return relative_equal(lhs.x, rhs.x) ? lhs.y < rhs.y : lhs.x < rhs.x;
}
bool operator>(const Point &lhs, const Point &rhs) {
return relative_equal(lhs.x, rhs.x) ? lhs.y > rhs.y : lhs.x > rhs.x;
}
bool operator!=(const Point &lhs, const Point &rhs) { return !(lhs == rhs); }
bool operator<=(const Point &lhs, const Point &rhs) { return !(lhs > rhs); }
bool operator>=(const Point &lhs, const Point &rhs) { return !(lhs < rhs); }
const Point operator+(const Point &lhs, const Point &rhs) {
return Point(lhs.x + rhs.x, lhs.y + rhs.y);
}
const Point operator-(const Point &lhs, const Point &rhs) {
return Point(lhs.x - rhs.x, lhs.y - rhs.y);
}
const Point operator*(const Point &lhs, const Point &rhs) {
return Point(lhs.x * rhs.x, lhs.y * rhs.y);
}
const Point operator/(const Point &lhs, const Point &rhs) {
return Point(lhs.x / rhs.x, lhs.y / rhs.y);
}
const Point operator-(const Point &p) { return Point(-p.x, -p.y); }
// ???
D abs(const Point &p) { return std::hypot(p.x, p.y); }
D norm(const Point &p) { return p.x * p.x + p.y * p.y; }
D dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
D cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
// ??´???
bool parallel(const Line &l1, const Line &l2) {
return relative_equal(
0.0, cross(l2.terminal - l2.initial, l1.terminal - l1.initial));
}
bool orthogonal(const Line &l1, const Line &l2) {
return relative_equal(
0.0, dot(l2.terminal - l2.initial, l1.terminal - l1.initial));
}
// 3??????????????¢???
POSITION ccw(const Point &a, const Point &b, const Point &p) {
Point v1 = b - a;
Point v2 = p - a;
if (cross(v1, v2) >= EPS)
return COUNTER_CLOCKWISE;
if (cross(v1, v2) <= -EPS)
return CLOCKWISE;
if (dot(v1, v2) <= -EPS)
return ONLINE_BACK;
if (norm(v1) < norm(v2))
return ONLINE_FRONT; // ????????????: norm(v1)<norm(v2)+EPS?????¨WrongAnswer
return ON_SEGMENT;
}
// ????????????
bool intersect(const Point &p1, const Point &p2) { return p1 == p2; }
bool intersect(const Point &p, const Segment &s) {
return abs(p - s.initial) + abs(p - s.terminal) -
abs(s.initial - s.terminal) <=
EPS;
}
bool intersect(const Segment &s, const Point &p) { return intersect(p, s); }
bool intersect(const Point &p, const Line &l) {
return !parallel(Line(p, l.initial), Line(p, l.terminal));
}
bool intersect(const Line &l, const Point &p) { return intersect(p, l); }
bool intersect(const Segment &s1, const Segment &s2) {
return ccw(s1.initial, s1.terminal, s2.initial) *
ccw(s1.initial, s1.terminal, s2.terminal) <=
0 &&
ccw(s2.initial, s2.terminal, s1.initial) *
ccw(s2.initial, s2.terminal, s1.terminal) <=
0;
}
bool intersect(const Segment &s, const Line &l) {
auto v1 = l.terminal - l.initial;
auto v2 = s.initial - l.initial;
auto v3 = s.terminal - l.initial;
return cross(v1, v2) * cross(v1, v3) <= EPS;
}
bool intersect(const Line &l, const Segment &s) { return intersect(s, l); }
bool intersect(const Line &l1, const Line &l2) {
return !parallel(l1, l2) || intersect(l1.initial, l2);
}
// ???????§????
Point rotate(const Point &p, const D a) {
return Point(p.x * std::cos(a) - p.y * std::sin(a),
p.x * std::sin(a) + p.y * std::cos(a));
}
Point projection(const Point &p, const Line &l) {
auto v = l.initial - l.terminal;
return l.initial + dot(p - l.initial, v) / norm(v) * v;
}
Point projection(const Line &l, const Point &p) { return projection(p, l); }
Point reflection(const Point &p, const Line &l) {
return p + 2 * (projection(p, l) - p);
}
Point reflection(const Line &l, const Point &p) { return reflection(p, l); }
// ?????¢
D distance(const Point &p1, const Point &p2) {
auto p = p1 - p2;
return hypot(p.x, p.y);
}
D distance(const Point &p, const Segment &s) {
auto r = projection(s, p);
return intersect(r, s)
? distance(p, r)
: std::min(distance(p, s.initial), distance(p, s.terminal));
}
D distance(const Segment &s, const Point &p) { return distance(p, s); }
D distance(const Point &p, const Line &l) {
return distance(p, projection(p, l));
}
D distance(const Line &l, const Point &p) { return distance(p, l); }
D distance(const Segment &s1, const Segment &s2) {
return intersect(s1, s2)
? 0.0
: std::min({distance(s1, s2.initial), distance(s1, s2.terminal),
distance(s2, s1.initial), distance(s2, s1.terminal)});
}
D distance(const Segment &s, const Line &l) {
return intersect(s, l)
? 0.0
: std::min(distance(s.initial, l), distance(s.terminal, l));
}
D distance(const Line &l, const Segment &s) { return distance(s, l); }
D distance(const Line &l1, const Line &l2) {
return intersect(l1, l2) ? 0.0 : distance(l1.initial, l2);
}
// ??????
const Point crosspoint(const Line &l1, const Line &l2) {
assert(intersect(l1, l2));
if (parallel(l1, l2))
return l1.initial; // ???????????¨???l1????§?????????????
D A = cross(l1.terminal - l1.initial, l2.terminal - l2.initial);
D B = cross(l1.terminal - l1.initial, l1.terminal - l2.initial);
return l2.initial + B / A * (l2.terminal - l2.initial);
}
const Point crosspoint(const Segment &s, const Line &l) {
assert(intersect(s, l));
if (parallel(s, l))
return s.initial;
return crosspoint(Line(s), l);
}
const Point crosspoint(const Line &l, const Segment &s) {
return crosspoint(s, l);
}
const Point crosspoint(const Segment &s1, const Segment &s2) {
assert(intersect(s1, s2));
if (parallel(s1, s2)) { // ???????????¨?????????????????????????????????
if (intersect(s1.initial, s2))
return s1.initial;
if (intersect(s1.terminal, s2))
return s1.terminal;
if (intersect(s2.initial, s1))
return s2.initial;
if (intersect(s2.terminal, s1))
return s2.terminal;
}
return crosspoint(Line(s1), Line(s2));
}
////////////////////////////////////////////////////////////////////////////////
// ?????????
#include <vector>
const D PI = std::acos(-1);
struct Circle {
Point center;
D radius;
Circle(const Point ¢er = 0, const D radius = 0)
: center(center), radius(radius) {}
Circle(const D x, const D y, const D radius) : center(x, y), radius(radius) {}
};
D area(const Circle &c) { return PI * c.radius * c.radius; }
bool contain(const Circle &c, const Point &p) {
D d = abs(p - c.center);
if (relative_equal(c.radius, d))
return true;
return d < c.radius;
}
bool contain(const Point &p, const Circle &c) { return contain(c, p); }
#include <bits/stdc++.h>
using namespace std;
std::vector<Point> crosspoint(const Circle &c, const Line &l) {
std::vector<Point> cp;
Point p = projection(c.center, l);
if (!contain(c, p))
return cp;
Point v = p - c.center;
if (relative_equal(abs(v), 0)) {
Point p = l.initial - c.center;
if (p == 0)
p = l.terminal - c.center;
p = (c.radius * p / abs(p));
cp.push_back(c.center + p);
cp.push_back(c.center - p);
return cp;
}
D angle = acos(abs(v) / c.radius);
for (D a : {angle, -angle})
cp.push_back(c.center + c.radius * (rotate(v, a) / abs(v)));
return cp;
}
std::vector<Point> crosspoint(const Line &l, const Circle &c) {
return crosspoint(c, l);
}
int tangent(const Circle &c1, const Circle &c2) {
D d = abs(c1.center - c2.center);
D r = c1.radius + c2.radius;
if (relative_equal(d, r))
return 3; // ?????\
if(r < d) return 4; // ?????¢
r = std::abs(c1.radius - c2.radius);
if (relative_equal(d, r))
return 1; // ?????\
if(r < d) return 2; // ??????
return 0; // ??????
}
#include <bits/stdc++.h>
using namespace std;
int N;
D R;
vector<Point> P;
D triangle(const Point &a, const Point &b, const Point &c) {
return abs(cross(b - a, c - a)) / 2.0;
}
D sector(const Circle &c, Point a, Point b) {
a = a - c.center;
b = b - c.center;
auto angle = acos(dot(a, b) / abs(a) / abs(b));
return c.radius * c.radius * angle / 2.0;
// auto a1 = atan2(a.y - c.center.y, a.x - c.center.x);
// auto a2 = atan2(b.y - c.center.y, b.x - c.center.x);
// auto angle = a2 - a1;
// cout<<a1<<" "<<a2<<endl;
// cout<<angle<<endl;
// return c.radius * c.radius * angle / 2.0;
}
D area(const Circle &c, Point a, Point b) {
if (a > b)
swap(a, b);
if (a == b || c.center == a || c.center == b)
return 0;
// ??????2????????????
if (contain(c, a) && contain(c, b))
return triangle(c.center, a, b);
auto cp = crosspoint(c, Line(a, b));
// ????§???¢????????§?????????
if (cp.empty())
return sector(c, a, b);
if (cp[0] > cp[1])
swap(cp[0], cp[1]);
// 2???????????????
if (!contain(c, a) && !contain(c, b)) {
if (b < cp[0] || cp[1] < a)
return sector(c, a, b);
else
return sector(c, a, cp[0]) + triangle(c.center, cp[0], cp[1]) +
sector(c, cp[1], b);
}
// 1?????????????????????
if (contain(c, a))
return triangle(c.center, a, cp[1]) + sector(c, cp[1], b);
else
return triangle(c.center, cp[0], b) + sector(c, a, cp[0]);
}
bool ok(D h) {
D covered = 0;
Circle c(0, h, R);
for (auto i = 0; i < P.size(); ++i) {
auto &cur = P[i], nex = P[(i + 1) % P.size()];
auto rev = ccw(c.center, cur, nex) == COUNTER_CLOCKWISE;
covered += area(c, cur, nex) * (rev ? -1 : 1);
}
return covered < area(c) / 2.0;
}
int main() {
cin >> N >> R;
D p = -200;
P.emplace_back(p, -200);
for (auto i = 0; i < N; ++i) {
D x, w, h;
cin >> x >> w >> h;
if (p != x)
P.emplace_back(p, 0);
if (p != x)
P.emplace_back(x, 0);
P.emplace_back(x, h);
P.emplace_back(x + w, h);
p = x + w;
}
P.emplace_back(p, 0);
P.emplace_back(200, 0);
P.emplace_back(200, -200);
const int LIMIT = 1e4;
D low = -100, high = 200;
for (auto step = 0; step < LIMIT; ++step) {
auto middle = (low + high) / 2.0;
if (ok(middle))
high = middle;
else
low = middle;
}
cout << setprecision(8) << fixed << low << endl;
} | replace | 347 | 348 | 347 | 348 | TLE | |
p00355 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int a, b, n, s, f, i = 0;
cin >> a >> b >> n;
while (1) {
cin >> s >> f;
if ((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)) {
cout << '1' << endl;
break;
}
if (++i == n) {
cout << '0' << endl;
break;
}
}
}
| #include <iostream>
using namespace std;
int main() {
int a, b, n, s, f, i = 0;
cin >> a >> b >> n;
while (1) {
cin >> s >> f;
if ((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)) {
cout << '1' << endl;
break;
}
if (++i >= n) {
cout << '0' << endl;
break;
}
}
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p00355 | C++ | Runtime Error | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
vi a(10000);
int n, l, r;
int main() {
cin >> l >> r >> n;
for (int i = 0; i < n; i++) {
int L, R;
cin >> L >> R;
for (int j = L; j < R; j++)
a[j] = 1;
}
for (int i = l; i < r; i++) {
if (a[i]) {
cout << 1 << endl;
return 1;
}
}
cout << 0 << endl;
}
| #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
vi a(10000);
int n, l, r;
int main() {
cin >> l >> r >> n;
for (int i = 0; i < n; i++) {
int L, R;
cin >> L >> R;
for (int j = L; j < R; j++)
a[j] = 1;
}
for (int i = l; i < r; i++) {
if (a[i]) {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p00357 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, t[100000], r = 1;
cin >> n;
for (int i = 0; i < n; i++)
cin >> t[i];
int le = t[0];
for (int i = 1; i < n; i++) {
le -= 10;
if (le < 0)
r = 0;
le = max(le, t[i]);
}
reverse(t, t + n);
le = t[0];
for (int i = 1; i < n; i++) {
le -= 10;
if (le < 0)
r = 0;
le = max(le, t[i]);
}
cout << (r ? "yes" : "no") << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, t[300010], r = 1;
cin >> n;
for (int i = 0; i < n; i++)
cin >> t[i];
int le = t[0];
for (int i = 1; i < n; i++) {
le -= 10;
if (le < 0)
r = 0;
le = max(le, t[i]);
}
reverse(t, t + n);
le = t[0];
for (int i = 1; i < n; i++) {
le -= 10;
if (le < 0)
r = 0;
le = max(le, t[i]);
}
cout << (r ? "yes" : "no") << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p00357 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int d[300000];
int a[300000];
#ifndef MAX
#define MAX 400000
#endif
// Range Update Query+Range Sum Query
template <class T> class RUQ_RSQ {
public:
int n;
T dat[MAX], lazy[MAX], ZERO, DEFAULT;
void init(int n_, T d = INT_MAX, T t = 0) {
DEFAULT = d;
ZERO = T();
n = 1;
while (n < n_)
n <<= 1;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = t;
lazy[i] = DEFAULT;
}
}
inline void push(int k, int s) {
if (lazy[k] == DEFAULT)
return;
dat[k] = lazy[k] * s;
if (k < n - 1) {
lazy[k * 2 + 1] = lazy[k];
lazy[k * 2 + 2] = lazy[k];
}
lazy[k] = DEFAULT;
}
inline void update_node(int k) { dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2]; }
inline void update(int a, int b, T x, int k, int l, int r) {
push(k, r - l);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] = x;
push(k, r - l);
return;
}
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
update_node(k);
}
inline T query(int a, int b, int k, int l, int r) {
push(k, r - l);
if (r <= a || b <= l)
return ZERO;
if (a <= l && r <= b)
return dat[k];
T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
update_node(k);
return lb + rb;
}
inline void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
inline void update(int a, T x) { update(a, a + 1, x); }
inline T query(int a, int b) { return query(a, b, 0, 0, n); }
inline T query(int a) { return query(a, a + 1); }
};
RUQ_RSQ<int> seg1, seg2;
int main() {
int n;
scanf("%d", &n);
rep(i, n) {
scanf("%d", &d[i]);
a[i] = i * 10;
}
seg1.init(n);
seg1.update(0, 1);
seg2.init(n);
seg2.update(n - 1, 1);
rep(i, n) {
if (!seg1.query(i))
continue;
int k = upper_bound(a, a + n, a[i] + d[i]) - a;
seg1.update(i + 1, k, 1);
}
if (seg1.query(n - 1) == 0) {
puts("no");
return 0;
}
for (int i = n - 1; i >= 0; i--) {
if (!seg2.query(i))
continue;
int k = lower_bound(a, a + n, a[i] - d[i]) - a;
seg2.update(k, i, 1);
}
if (seg2.query(0) == 0) {
puts("no");
return 0;
}
puts("yes");
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int d[300000];
int a[300000];
#ifndef MAX
#define MAX 1200000
#endif
// Range Update Query+Range Sum Query
template <class T> class RUQ_RSQ {
public:
int n;
T dat[MAX], lazy[MAX], ZERO, DEFAULT;
void init(int n_, T d = INT_MAX, T t = 0) {
DEFAULT = d;
ZERO = T();
n = 1;
while (n < n_)
n <<= 1;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = t;
lazy[i] = DEFAULT;
}
}
inline void push(int k, int s) {
if (lazy[k] == DEFAULT)
return;
dat[k] = lazy[k] * s;
if (k < n - 1) {
lazy[k * 2 + 1] = lazy[k];
lazy[k * 2 + 2] = lazy[k];
}
lazy[k] = DEFAULT;
}
inline void update_node(int k) { dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2]; }
inline void update(int a, int b, T x, int k, int l, int r) {
push(k, r - l);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] = x;
push(k, r - l);
return;
}
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
update_node(k);
}
inline T query(int a, int b, int k, int l, int r) {
push(k, r - l);
if (r <= a || b <= l)
return ZERO;
if (a <= l && r <= b)
return dat[k];
T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
update_node(k);
return lb + rb;
}
inline void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
inline void update(int a, T x) { update(a, a + 1, x); }
inline T query(int a, int b) { return query(a, b, 0, 0, n); }
inline T query(int a) { return query(a, a + 1); }
};
RUQ_RSQ<int> seg1, seg2;
int main() {
int n;
scanf("%d", &n);
rep(i, n) {
scanf("%d", &d[i]);
a[i] = i * 10;
}
seg1.init(n);
seg1.update(0, 1);
seg2.init(n);
seg2.update(n - 1, 1);
rep(i, n) {
if (!seg1.query(i))
continue;
int k = upper_bound(a, a + n, a[i] + d[i]) - a;
seg1.update(i + 1, k, 1);
}
if (seg1.query(n - 1) == 0) {
puts("no");
return 0;
}
for (int i = n - 1; i >= 0; i--) {
if (!seg2.query(i))
continue;
int k = lower_bound(a, a + n, a[i] - d[i]) - a;
seg2.update(k, i, 1);
}
if (seg2.query(0) == 0) {
puts("no");
return 0;
}
puts("yes");
} | replace | 8 | 9 | 8 | 9 | 0 | |
p00357 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
//
int N;
VE D;
bool DFS(int now, int nok) {
if (nok < 10) {
return false;
} else if (now == N - 1) {
return true;
}
now++;
nok -= 10;
if (DFS(now, D[now])) {
return true;
}
if (DFS(now, nok)) {
return true;
}
return false;
}
int main() {
cin >> N;
FOR(i, 0, N) {
int d;
cin >> d;
D.PB(d);
}
if (!DFS(0, D[0])) {
cout << "no" << endl;
return 0;
}
reverse(D.begin(), D.end());
if (!DFS(0, D[0])) {
cout << "no" << endl;
} else {
cout << "yes" << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
//
int N;
VE D;
bool DFS(int now, int nok) {
if (nok < 10) {
return false;
} else if (now == N - 1) {
return true;
}
now++;
nok -= 10;
if (DFS(now, max(D[now], nok))) {
return true;
}
return false;
}
int main() {
cin >> N;
FOR(i, 0, N) {
int d;
cin >> d;
D.PB(d);
}
if (!DFS(0, D[0])) {
cout << "no" << endl;
return 0;
}
reverse(D.begin(), D.end());
if (!DFS(0, D[0])) {
cout << "no" << endl;
} else {
cout << "yes" << endl;
}
return 0;
}
| replace | 33 | 37 | 33 | 34 | TLE | |
p00357 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
int a[100000];
int main() {
long int N;
bool flag = 0;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> a[i - 1];
}
if (a[0] >= 10 && a[N - 1] >= 10) {
for (int k = 1; k <= N - 2; k++) {
if (a[k] < 10) {
flag = 0;
int yosi = 0;
for (int o = 1;; o++) {
if (a[k - o] >= (10 * o + 10)) {
yosi++;
break;
}
if ((k - o) == 0) {
cout << "no" << endl;
return 0;
}
}
for (int u = 1;; u++) {
if (a[k + u] >= (10 * u + 10)) {
yosi++;
break;
}
if ((k + u) == (N - 1)) {
cout << "no" << endl;
return 0;
}
}
if (yosi == 2) {
flag = 1;
} else {
cout << "no" << endl;
return 0;
}
}
}
flag = 1;
}
if (flag == 0) {
cout << "no" << endl;
} else {
cout << "yes" << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
int a[300000];
int main() {
long int N;
bool flag = 0;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> a[i - 1];
}
if (a[0] >= 10 && a[N - 1] >= 10) {
for (int k = 1; k <= N - 2; k++) {
if (a[k] < 10) {
flag = 0;
int yosi = 0;
for (int o = 1;; o++) {
if (a[k - o] >= (10 * o + 10)) {
yosi++;
break;
}
if ((k - o) == 0) {
cout << "no" << endl;
return 0;
}
}
for (int u = 1;; u++) {
if (a[k + u] >= (10 * u + 10)) {
yosi++;
break;
}
if ((k + u) == (N - 1)) {
cout << "no" << endl;
return 0;
}
}
if (yosi == 2) {
flag = 1;
} else {
cout << "no" << endl;
return 0;
}
}
}
flag = 1;
}
if (flag == 0) {
cout << "no" << endl;
} else {
cout << "yes" << endl;
}
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p00357 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int a[100001];
bool solve1(int n) {
int p = 0;
for (int i = 0; i < n; i++) {
if (i > p)
return 0;
p = max(p, i + (a[i] / 10));
}
return p >= n - 1;
}
bool solve2(int n) {
int p = n - 1;
for (int i = n - 1; i >= 0; i--) {
if (i < p)
return 0;
p = min(p, i - (a[i] / 10));
}
return p <= 0;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
bool x = solve1(n);
bool y = solve2(n);
if (x && y)
printf("yes\n");
else
printf("no\n");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int a[300001];
bool solve1(int n) {
int p = 0;
for (int i = 0; i < n; i++) {
if (i > p)
return 0;
p = max(p, i + (a[i] / 10));
}
return p >= n - 1;
}
bool solve2(int n) {
int p = n - 1;
for (int i = n - 1; i >= 0; i--) {
if (i < p)
return 0;
p = min(p, i - (a[i] / 10));
}
return p <= 0;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
bool x = solve1(n);
bool y = solve2(n);
if (x && y)
printf("yes\n");
else
printf("no\n");
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p00358 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int H, N;
int ngmask[1000];
int dp[1000][1 << 4];
int rec(int idx, int upbit) {
if (idx == H)
return (0);
if (~dp[idx][upbit])
return (dp[idx][upbit]);
int ret = rec(idx + 1, ngmask[idx]);
for (int i = 0; i < 3; i++) {
if ((upbit >> i) & 3)
continue;
if ((ngmask[idx] >> i) & 3)
continue;
ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
}
if (ngmask[idx] == 0 && upbit == 0) {
ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
}
return (dp[idx][upbit] = ret);
}
int main() {
cin >> H >> N;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
ngmask[y] |= 1 << x;
}
memset(dp, -1, sizeof(dp));
cout << rec(1, ngmask[0]) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int H, N;
int ngmask[10000];
int dp[10000][1 << 4];
int rec(int idx, int upbit) {
if (idx == H)
return (0);
if (~dp[idx][upbit])
return (dp[idx][upbit]);
int ret = rec(idx + 1, ngmask[idx]);
for (int i = 0; i < 3; i++) {
if ((upbit >> i) & 3)
continue;
if ((ngmask[idx] >> i) & 3)
continue;
ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
}
if (ngmask[idx] == 0 && upbit == 0) {
ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
}
return (dp[idx][upbit] = ret);
}
int main() {
cin >> H >> N;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
ngmask[y] |= 1 << x;
}
memset(dp, -1, sizeof(dp));
cout << rec(1, ngmask[0]) << endl;
} | replace | 5 | 7 | 5 | 7 | 0 | |
p00359 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int, int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
//
struct poi {
int X;
int Y;
int Z;
bool operator<(const poi &R) const {
return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
}
};
//
//
int main() {
int W, H, N;
VP V;
cin >> W >> H >> N;
FOR(i, 0, N) {
int X, Y;
cin >> X >> Y;
V.PB(MA(X, Y));
}
sort(V.begin(), V.end());
VP mid;
int now = 0;
while (now < N - 1) {
while (now < N - 1 && V[now].FI == V[now + 1].FI) {
now++;
}
mid.PB(V[now]);
now++;
if (now == N - 1) {
mid.PB(V[now]);
}
}
VP ans;
ans.PB(mid.back());
ROF(i, 0, (int)mid.size()) {
if (mid[i].SE > ans.back().SE) {
ans.PB(mid[i]);
}
}
reverse(ans.begin(), ans.end());
int a = min(ans[0].SE, ans.back().FI);
FOR(i, 0, (int)ans.size() - 1) { a = min(a, ans[i].FI + ans[i + 1].SE); }
cout << a << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int, int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
//
struct poi {
int X;
int Y;
int Z;
bool operator<(const poi &R) const {
return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
}
};
//
//
int main() {
int W, H, N;
VP V;
cin >> W >> H >> N;
FOR(i, 0, N) {
int X, Y;
cin >> X >> Y;
V.PB(MA(X, Y));
}
sort(V.begin(), V.end());
if (N == 1) {
cout << min(V[0].FI, V[0].SE) << endl;
return 0;
}
VP mid;
int now = 0;
while (now < N - 1) {
while (now < N - 1 && V[now].FI == V[now + 1].FI) {
now++;
}
mid.PB(V[now]);
now++;
if (now == N - 1) {
mid.PB(V[now]);
}
}
VP ans;
ans.PB(mid.back());
ROF(i, 0, (int)mid.size()) {
if (mid[i].SE > ans.back().SE) {
ans.PB(mid[i]);
}
}
reverse(ans.begin(), ans.end());
int a = min(ans[0].SE, ans.back().FI);
FOR(i, 0, (int)ans.size() - 1) { a = min(a, ans[i].FI + ans[i + 1].SE); }
cout << a << endl;
return 0;
}
| insert | 49 | 49 | 49 | 53 | 0 | |
p00359 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int wh[10001] = {};
int main(void) {
int w, h, n;
cin >> w >> h >> n;
int at_most_w = 0, at_most_h = 0;
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
wh[y] = max(wh[y], x);
at_most_w = max(x, at_most_w);
at_most_h = max(y, at_most_h);
}
int x_position, y_position, MIN;
MIN = wh[h - 1] + (h - 1);
x_position = wh[h - 1];
y_position = h - 1;
for (int i = 0; i < h - 1; i++) {
y_position--;
int a = x_position, b = y_position;
MIN = min(MIN, a + b);
if (a < wh[b]) {
x_position = wh[y_position];
int a = x_position, b = y_position;
MIN = min(MIN, a + b);
}
}
cout << min(MIN, min(at_most_w, at_most_h)) << endl;
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int wh[100001] = {};
int main(void) {
int w, h, n;
cin >> w >> h >> n;
int at_most_w = 0, at_most_h = 0;
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
wh[y] = max(wh[y], x);
at_most_w = max(x, at_most_w);
at_most_h = max(y, at_most_h);
}
int x_position, y_position, MIN;
MIN = wh[h - 1] + (h - 1);
x_position = wh[h - 1];
y_position = h - 1;
for (int i = 0; i < h - 1; i++) {
y_position--;
int a = x_position, b = y_position;
MIN = min(MIN, a + b);
if (a < wh[b]) {
x_position = wh[y_position];
int a = x_position, b = y_position;
MIN = min(MIN, a + b);
}
}
cout << min(MIN, min(at_most_w, at_most_h)) << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p00360 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef pair<int, int> P;
#ifndef MAX
#define MAX 400000
#endif
// Range Update Query+Range Minimum Query
template <class T> class RUQ_RMQ {
public:
int n;
T dat[MAX], lazy[MAX], DEFAULT;
bool (*cmp)(T, T);
void init(
int n_, bool (*c)(T, T) = [](int a, int b) { return a < b; },
T d = INT_MAX) {
cmp = c;
DEFAULT = d;
n = 1;
while (n < n_)
n <<= 1;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = lazy[i] = DEFAULT;
}
}
inline void push(int k) {
if (lazy[k] == DEFAULT)
return;
dat[k] = lazy[k];
if (k < n - 1) {
lazy[k * 2 + 1] = lazy[k];
lazy[k * 2 + 2] = lazy[k];
}
lazy[k] = DEFAULT;
}
inline void update_node(int k) {
if (cmp(dat[k * 2 + 1], dat[k * 2 + 2]))
dat[k] = dat[k * 2 + 1];
else
dat[k] = dat[k * 2 + 2];
}
inline void update(int a, int b, T x, int k, int l, int r) {
push(k);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] = x;
push(k);
return;
}
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
update_node(k);
}
inline T query(int a, int b, int k, int l, int r) {
push(k);
if (r <= a || b <= l)
return DEFAULT;
if (a <= l && r <= b)
return dat[k];
T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
update_node(k);
if (cmp(lb, rb))
return lb;
return rb;
}
inline void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
inline void update(int a, T x) { update(a, a + 1, x); }
inline T query(int a, int b) { return query(a, b, 0, 0, n); }
inline T query(int a) { return query(a, a + 1); }
};
int bit[300000];
void add(int k, int x) {
k++;
while (k < 300000) {
bit[k] += x;
k += k & -k;
}
}
int sum(int k) {
k++;
int ans = 0;
while (k) {
ans += bit[k];
k -= k & -k;
}
return ans;
}
RUQ_RMQ<P> tree;
int main() {
string s;
int k;
cin >> s >> k;
rep(i, s.size() - 1) add(i + 1, 1);
tree.init(
s.size(), [](P a, P b) { return a < b; }, P(INT_MAX, INT_MAX));
rep(i, s.size()) tree.update(i, P(s[i], i));
string ans;
int a = k;
rep(i, s.size()) {
int l = 1, r = s.size();
while (l != r) {
int t = (l + r) / 2;
if (r - l == 1)
t = r;
if (sum(t - 1) <= k)
l = t;
else
r = t - 1;
}
P p = tree.query(0, l);
ans += p.first;
k -= sum(p.second);
a += sum(p.second);
add(p.second + 1, -1);
tree.update(p.second, P(INT_MAX, i));
P pp = tree.query(p.second);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef pair<int, int> P;
#ifndef MAX
#define MAX 800000
#endif
// Range Update Query+Range Minimum Query
template <class T> class RUQ_RMQ {
public:
int n;
T dat[MAX], lazy[MAX], DEFAULT;
bool (*cmp)(T, T);
void init(
int n_, bool (*c)(T, T) = [](int a, int b) { return a < b; },
T d = INT_MAX) {
cmp = c;
DEFAULT = d;
n = 1;
while (n < n_)
n <<= 1;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = lazy[i] = DEFAULT;
}
}
inline void push(int k) {
if (lazy[k] == DEFAULT)
return;
dat[k] = lazy[k];
if (k < n - 1) {
lazy[k * 2 + 1] = lazy[k];
lazy[k * 2 + 2] = lazy[k];
}
lazy[k] = DEFAULT;
}
inline void update_node(int k) {
if (cmp(dat[k * 2 + 1], dat[k * 2 + 2]))
dat[k] = dat[k * 2 + 1];
else
dat[k] = dat[k * 2 + 2];
}
inline void update(int a, int b, T x, int k, int l, int r) {
push(k);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] = x;
push(k);
return;
}
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
update_node(k);
}
inline T query(int a, int b, int k, int l, int r) {
push(k);
if (r <= a || b <= l)
return DEFAULT;
if (a <= l && r <= b)
return dat[k];
T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
update_node(k);
if (cmp(lb, rb))
return lb;
return rb;
}
inline void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
inline void update(int a, T x) { update(a, a + 1, x); }
inline T query(int a, int b) { return query(a, b, 0, 0, n); }
inline T query(int a) { return query(a, a + 1); }
};
int bit[300000];
void add(int k, int x) {
k++;
while (k < 300000) {
bit[k] += x;
k += k & -k;
}
}
int sum(int k) {
k++;
int ans = 0;
while (k) {
ans += bit[k];
k -= k & -k;
}
return ans;
}
RUQ_RMQ<P> tree;
int main() {
string s;
int k;
cin >> s >> k;
rep(i, s.size() - 1) add(i + 1, 1);
tree.init(
s.size(), [](P a, P b) { return a < b; }, P(INT_MAX, INT_MAX));
rep(i, s.size()) tree.update(i, P(s[i], i));
string ans;
int a = k;
rep(i, s.size()) {
int l = 1, r = s.size();
while (l != r) {
int t = (l + r) / 2;
if (r - l == 1)
t = r;
if (sum(t - 1) <= k)
l = t;
else
r = t - 1;
}
P p = tree.query(0, l);
ans += p.first;
k -= sum(p.second);
a += sum(p.second);
add(p.second + 1, -1);
tree.update(p.second, P(INT_MAX, i));
P pp = tree.query(p.second);
}
cout << ans << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p00362 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <iostream>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
struct LeastCommonAncestor {
public:
LeastCommonAncestor(int n, int root = 0)
: root(root), graph(n), parent(ilogb(n) + 1, vector<int>(n)), depth(n) {}
void add_edge(int a, int b) {
graph[a].push_back(b);
graph[b].push_back(a);
}
void init() {
// dfs(root, -1, 0);
stack<tuple<int, int, int>> st;
st.emplace(root, -1, 0);
while (!st.empty()) {
int v, p, d;
tie(v, p, d) = st.top();
st.pop();
parent[0][v] = p;
depth[v] = d;
for (int to : graph[v]) {
if (to != p) {
// dfs(to, v, d + 1);
st.emplace(to, v, d + 1);
}
}
}
for (int k = 0; k + 1 < parent.size(); ++k) {
for (int v = 0; v < graph.size(); ++v) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int query(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
}
for (int k = 0; k < parent.size(); ++k) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = parent.size() - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
private:
void dfs(int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (int to : graph[v]) {
if (to != p) {
dfs(to, v, d + 1);
}
}
}
private:
int root;
vector<vector<int>> graph;
vector<vector<int>> parent;
vector<int> depth;
};
int n, k;
struct Edge {
Edge() = default;
Edge(int to, int rev, int64_t cost) : to(to), rev(rev), cost(cost) {}
int to, rev;
int64_t cost;
};
struct Query {
int com, x, y;
};
vector<vector<Edge>> tree;
vector<Edge> sub_tree;
vector<int64_t> lazy;
vector<int64_t> sum;
inline void add_edge(vector<vector<Edge>> &graph, int from, int to,
int64_t cost) {
graph[from].emplace_back(to, graph[to].size(), cost);
graph[to].emplace_back(from, graph[from].size() - 1, cost);
}
void set_sub_tree(const vector<int> &use) {
fill(sum.begin(), sum.end(), 0);
// dfs(use, 0, -1, -1, 0, 0, 0);
static stack<tuple<int, int, int, int64_t, int64_t, int64_t>> st;
st.emplace(n / 2, -1, -1, 0, 0, 0);
while (!st.empty()) {
int node, par, prev;
int64_t s, e1_cost, e2_cost;
tie(node, par, prev, s, e1_cost, e2_cost) = st.top();
st.pop();
if (use[node] && prev != -1) {
if (prev == par) {
sub_tree[node].to = prev;
sub_tree[node].cost = e1_cost;
} else {
sub_tree[par].to = prev;
sub_tree[par].cost = e1_cost;
sub_tree[node].to = par;
sub_tree[node].cost = e2_cost;
sum[par] = s;
}
}
if (use[node]) {
for (auto &e : tree[node]) {
if (e.to == par) {
continue;
}
int64_t cost = 0;
st.emplace(e.to, node, node, cost, e.cost, e.cost);
}
} else {
for (auto &e : tree[node]) {
if (e.to == par) {
continue;
}
int64_t cost = s + (use[e.to] ? 0 : (e.cost % k ? e.cost : 0));
st.emplace(e.to, node, prev, cost, e1_cost, e.cost);
}
}
}
}
inline void add(int x, int d) { lazy[x] += d; }
inline int64_t send(int s, int t, int u) {
int64_t res = 0;
while (s != u) {
auto &e = sub_tree[s];
int64_t cost = e.cost + lazy[s] + lazy[e.to];
if (cost % k == 0) {
cost = 0;
}
cost += sum[s];
res += cost;
s = e.to;
}
while (t != u) {
auto &e = sub_tree[t];
int64_t cost = e.cost + lazy[t] + lazy[e.to];
if (cost % k == 0) {
cost = 0;
}
cost += sum[t];
res += cost;
t = e.to;
}
return res;
}
inline void propagate() {
for (int i = 0; i < n; ++i) {
for (auto &e : tree[i]) {
e.cost += lazy[i];
tree[e.to][e.rev].cost += lazy[i];
}
}
fill(lazy.begin(), lazy.end(), 0);
}
int main() {
scanf("%d%d", &n, &k);
tree.assign(n, {});
sub_tree.assign(n, {});
lazy.assign(n, 0);
sum.assign(n, 0);
LeastCommonAncestor lca(n, n / 2);
for (int i = 0; i < n - 1; ++i) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
add_edge(tree, a, b, c);
lca.add_edge(a, b);
}
lca.init();
int q;
scanf("%d", &q);
assert(n <= 100000 && q <= 100000);
vector<Query> query(q);
for (int i = 0; i < q; ++i) {
char com[5];
scanf("%s%d%d", com, &query[i].x, &query[i].y);
query[i].com = (com[0] == 's');
}
int bs = 3 * sqrt(q);
int bn = (q + bs - 1) / bs;
vector<int> lca_res(q);
vector<int> use(n);
for (int i = 0; i < bn; ++i) {
fill(use.begin(), use.end(), 0);
for (int j = i * bs; j < (i + 1) * bs && j < q; ++j) {
if (query[j].com == 1) {
use[query[j].x] = use[query[j].y] = true;
lca_res[j] = lca.query(query[j].x, query[j].y);
use[lca_res[j]] = true;
} else {
use[query[j].x] = true;
}
}
set_sub_tree(use);
for (int j = i * bs; j < (i + 1) * bs && j < q; ++j) {
if (query[j].com == 0) {
add(query[j].x, query[j].y);
} else {
printf("%lld\n", send(query[j].x, query[j].y, lca_res[j]));
}
}
propagate();
}
} | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <iostream>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
struct LeastCommonAncestor {
public:
LeastCommonAncestor(int n, int root = 0)
: root(root), graph(n), parent(ilogb(n) + 1, vector<int>(n)), depth(n) {}
void add_edge(int a, int b) {
graph[a].push_back(b);
graph[b].push_back(a);
}
void init() {
// dfs(root, -1, 0);
stack<tuple<int, int, int>> st;
st.emplace(root, -1, 0);
while (!st.empty()) {
int v, p, d;
tie(v, p, d) = st.top();
st.pop();
parent[0][v] = p;
depth[v] = d;
for (int to : graph[v]) {
if (to != p) {
// dfs(to, v, d + 1);
st.emplace(to, v, d + 1);
}
}
}
for (int k = 0; k + 1 < parent.size(); ++k) {
for (int v = 0; v < graph.size(); ++v) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int query(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
}
for (int k = 0; k < parent.size(); ++k) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = parent.size() - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
private:
void dfs(int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (int to : graph[v]) {
if (to != p) {
dfs(to, v, d + 1);
}
}
}
private:
int root;
vector<vector<int>> graph;
vector<vector<int>> parent;
vector<int> depth;
};
int n, k;
struct Edge {
Edge() = default;
Edge(int to, int rev, int64_t cost) : to(to), rev(rev), cost(cost) {}
int to, rev;
int64_t cost;
};
struct Query {
int com, x, y;
};
vector<vector<Edge>> tree;
vector<Edge> sub_tree;
vector<int64_t> lazy;
vector<int64_t> sum;
inline void add_edge(vector<vector<Edge>> &graph, int from, int to,
int64_t cost) {
graph[from].emplace_back(to, graph[to].size(), cost);
graph[to].emplace_back(from, graph[from].size() - 1, cost);
}
void set_sub_tree(const vector<int> &use) {
fill(sum.begin(), sum.end(), 0);
// dfs(use, 0, -1, -1, 0, 0, 0);
static stack<tuple<int, int, int, int64_t, int64_t, int64_t>> st;
st.emplace(n / 2, -1, -1, 0, 0, 0);
while (!st.empty()) {
int node, par, prev;
int64_t s, e1_cost, e2_cost;
tie(node, par, prev, s, e1_cost, e2_cost) = st.top();
st.pop();
if (use[node] && prev != -1) {
if (prev == par) {
sub_tree[node].to = prev;
sub_tree[node].cost = e1_cost;
} else {
sub_tree[par].to = prev;
sub_tree[par].cost = e1_cost;
sub_tree[node].to = par;
sub_tree[node].cost = e2_cost;
sum[par] = s;
}
}
if (use[node]) {
for (auto &e : tree[node]) {
if (e.to == par) {
continue;
}
int64_t cost = 0;
st.emplace(e.to, node, node, cost, e.cost, e.cost);
}
} else {
for (auto &e : tree[node]) {
if (e.to == par) {
continue;
}
int64_t cost = s + (use[e.to] ? 0 : (e.cost % k ? e.cost : 0));
st.emplace(e.to, node, prev, cost, e1_cost, e.cost);
}
}
}
}
inline void add(int x, int d) { lazy[x] += d; }
inline int64_t send(int s, int t, int u) {
int64_t res = 0;
while (s != u) {
auto &e = sub_tree[s];
int64_t cost = e.cost + lazy[s] + lazy[e.to];
if (cost % k == 0) {
cost = 0;
}
cost += sum[s];
res += cost;
s = e.to;
}
while (t != u) {
auto &e = sub_tree[t];
int64_t cost = e.cost + lazy[t] + lazy[e.to];
if (cost % k == 0) {
cost = 0;
}
cost += sum[t];
res += cost;
t = e.to;
}
return res;
}
inline void propagate() {
for (int i = 0; i < n; ++i) {
if (lazy[i] != 0) {
for (auto &e : tree[i]) {
e.cost += lazy[i];
tree[e.to][e.rev].cost += lazy[i];
}
}
}
fill(lazy.begin(), lazy.end(), 0);
}
int main() {
scanf("%d%d", &n, &k);
tree.assign(n, {});
sub_tree.assign(n, {});
lazy.assign(n, 0);
sum.assign(n, 0);
LeastCommonAncestor lca(n, n / 2);
for (int i = 0; i < n - 1; ++i) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
add_edge(tree, a, b, c);
lca.add_edge(a, b);
}
lca.init();
int q;
scanf("%d", &q);
assert(n <= 100000 && q <= 100000);
vector<Query> query(q);
for (int i = 0; i < q; ++i) {
char com[5];
scanf("%s%d%d", com, &query[i].x, &query[i].y);
query[i].com = (com[0] == 's');
}
int bs = 3 * sqrt(q);
int bn = (q + bs - 1) / bs;
vector<int> lca_res(q);
vector<int> use(n);
for (int i = 0; i < bn; ++i) {
fill(use.begin(), use.end(), 0);
for (int j = i * bs; j < (i + 1) * bs && j < q; ++j) {
if (query[j].com == 1) {
use[query[j].x] = use[query[j].y] = true;
lca_res[j] = lca.query(query[j].x, query[j].y);
use[lca_res[j]] = true;
} else {
use[query[j].x] = true;
}
}
set_sub_tree(use);
for (int j = i * bs; j < (i + 1) * bs && j < q; ++j) {
if (query[j].com == 0) {
add(query[j].x, query[j].y);
} else {
printf("%lld\n", send(query[j].x, query[j].y, lca_res[j]));
}
}
propagate();
}
} | replace | 214 | 217 | 214 | 219 | TLE | |
p00362 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
struct e {
int to, cost;
e(int to, int cost) : to(to), cost(cost) {}
};
struct edge {
int to;
bool edge_type;
long long cost, scost, tcost;
edge() {}
// edge(int to, long long cost) : to(to), cost(cost) {}
edge(int to, long long cost, bool edge_type, long long scost, long long tcost)
: to(to), cost(cost), edge_type(edge_type), scost(scost), tcost(tcost) {}
};
struct query {
bool type; // := add is true, send is false. kore eigo attennnoka
int a, b;
query() {}
query(char s, int a, int b) : a(a), b(b) { type = (s == 'a'); }
};
int n, k, cnt;
vector<e> G[101010];
vector<edge> minG[101010];
query Q[1000];
int depth[101010], euler_tour[202020];
long long add[101010];
bool used[101010];
long long sqrt_int(long long n) {
long long l = 1, r = n;
while (r - l > 1) {
long long m = (l + r) / 2;
if (m * m <= n)
l = m;
else
r = m;
}
return l;
}
void dfs(int v = 0, int p = -1, int d = 0) {
// euler_tour.push_back(v);
euler_tour[cnt++] = v;
depth[v] = d;
for (auto u : G[v]) {
if (u.to == p)
continue;
dfs(u.to, v, d + 1);
// euler_tour.push_back(v);
euler_tour[cnt++] = v;
}
}
inline void dfs2(int v, int from, int p = -1, long long cost = 0, int cnt = 0,
int scost = -1, int tcost = -1) {
// cerr << v << " ( <- " << from << " )" << endl;
if (cnt == 0) {
for (auto u : G[v]) {
if (u.to == p)
continue;
dfs2(u.to, from, v, 0, cnt + 1, u.cost + add[u.to], u.cost + add[v]);
}
} else if (used[v]) {
if (cnt == 1) {
minG[v].push_back(edge(from, scost - add[v], true, -1, -1));
minG[from].push_back(edge(v, scost - add[v], true, -1, -1));
} else {
minG[v].push_back(edge(from, cost, false, tcost, scost));
minG[from].push_back(edge(v, cost, false, scost, tcost));
}
dfs2(v, v, p, 0, 0, -1, -1);
} else {
for (auto u : G[v]) {
if (u.to == p)
continue;
long long edge_cost = add[v] + add[u.to] + u.cost;
if (used[u.to] || edge_cost % k == 0)
edge_cost = 0;
dfs2(u.to, from, v, cost + edge_cost, cnt + 1, scost, u.cost + add[v]);
}
}
}
inline bool dfs3(int s, int to, int p = -1, long long cost = 0) {
if (s == to) {
printf("%d\n", cost);
// cout << cost << endl;
return true;
}
for (auto u : minG[s]) {
int t = u.to;
if (t == p)
continue;
if (u.edge_type) {
long long edge_cost = u.cost + add[s] + add[t];
if (edge_cost % k == 0)
edge_cost = 0;
if (dfs3(t, to, s, cost + edge_cost))
return true;
} else {
long long scost = u.scost + add[s], tcost = u.tcost + add[t];
if (scost % k == 0)
scost = 0;
if (tcost % k == 0)
tcost = 0;
if (dfs3(t, to, s, cost + u.cost + scost + tcost))
return true;
}
}
return false;
}
void debug() {
cout << "minimum graph" << endl;
for (int v = 0; v < n; ++v) {
for (auto u : minG[v])
cout << v << " -> " << u.to << " edge_type : " << u.edge_type << " "
<< u.scost << " + " << u.cost << " + " << u.tcost << endl;
}
}
int main() {
scanf("%d %d", &n, &k);
// cin >> n >> k;
// G.resize(n);
for (int i = 0; i < n - 1; ++i) {
int u, v, c;
scanf("%d %d %d", &u, &v, &c);
// cin >> u >> v >> c;
G[u].push_back(e(v, c));
G[v].push_back(e(u, c));
}
dfs();
int q;
scanf("%d", &q);
// cin >> q;
int root_q = sqrt_int(q);
// int root_q = 300;
int r = (q + root_q - 1) / root_q;
for (int p = 0; p < r; ++p) {
int rr = min(root_q, q - p * root_q);
// vector<query> Q;
memset(used, false, sizeof(used));
// minG.assign(n, vector<edge>());
for (int i = 0; i < n; ++i)
minG[i].clear();
for (int i = 0; i < rr; ++i) {
// string s;
char s[10];
int a, b;
scanf("%s %d %d", s, &a, &b);
// cin >> s >> a >> b;
Q[i] = query(s[0], a, b);
if (Q[i].type) {
used[a] = true;
} else {
used[a] = used[b] = true;
}
}
pair<int, int> mini, root;
mini = root = make_pair(inf, -1);
for (int i = 0; i < cnt; ++i) {
int v = euler_tour[i];
mini = min(mini, make_pair(depth[v], v));
if (used[v]) {
if (mini.second != -1)
used[mini.second] = true;
mini = make_pair(depth[v], v);
root = min(root, make_pair(depth[v], v));
}
}
dfs2(root.second, root.second);
// debug();
for (int i = 0; i < rr; ++i) {
if (Q[i].type) {
add[Q[i].a] += Q[i].b;
} else {
dfs3(Q[i].a, Q[i].b);
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
struct e {
int to, cost;
e(int to, int cost) : to(to), cost(cost) {}
};
struct edge {
int to;
bool edge_type;
long long cost, scost, tcost;
edge() {}
// edge(int to, long long cost) : to(to), cost(cost) {}
edge(int to, long long cost, bool edge_type, long long scost, long long tcost)
: to(to), cost(cost), edge_type(edge_type), scost(scost), tcost(tcost) {}
};
struct query {
bool type; // := add is true, send is false. kore eigo attennnoka
int a, b;
query() {}
query(char s, int a, int b) : a(a), b(b) { type = (s == 'a'); }
};
int n, k, cnt;
vector<e> G[101010];
vector<edge> minG[101010];
query Q[1000];
int depth[101010], euler_tour[202020];
long long add[101010];
bool used[101010];
long long sqrt_int(long long n) {
long long l = 1, r = n;
while (r - l > 1) {
long long m = (l + r) / 2;
if (m * m <= n)
l = m;
else
r = m;
}
return l;
}
inline void dfs(int v = 0, int p = -1, int d = 0) {
// euler_tour.push_back(v);
euler_tour[cnt++] = v;
depth[v] = d;
for (auto u : G[v]) {
if (u.to == p)
continue;
dfs(u.to, v, d + 1);
// euler_tour.push_back(v);
euler_tour[cnt++] = v;
}
}
inline void dfs2(int v, int from, int p = -1, long long cost = 0, int cnt = 0,
int scost = -1, int tcost = -1) {
// cerr << v << " ( <- " << from << " )" << endl;
if (cnt == 0) {
for (auto u : G[v]) {
if (u.to == p)
continue;
dfs2(u.to, from, v, 0, cnt + 1, u.cost + add[u.to], u.cost + add[v]);
}
} else if (used[v]) {
if (cnt == 1) {
minG[v].push_back(edge(from, scost - add[v], true, -1, -1));
minG[from].push_back(edge(v, scost - add[v], true, -1, -1));
} else {
minG[v].push_back(edge(from, cost, false, tcost, scost));
minG[from].push_back(edge(v, cost, false, scost, tcost));
}
dfs2(v, v, p, 0, 0, -1, -1);
} else {
for (auto u : G[v]) {
if (u.to == p)
continue;
long long edge_cost = add[v] + add[u.to] + u.cost;
if (used[u.to] || edge_cost % k == 0)
edge_cost = 0;
dfs2(u.to, from, v, cost + edge_cost, cnt + 1, scost, u.cost + add[v]);
}
}
}
inline bool dfs3(int s, int to, int p = -1, long long cost = 0) {
if (s == to) {
printf("%d\n", cost);
// cout << cost << endl;
return true;
}
for (auto u : minG[s]) {
int t = u.to;
if (t == p)
continue;
if (u.edge_type) {
long long edge_cost = u.cost + add[s] + add[t];
if (edge_cost % k == 0)
edge_cost = 0;
if (dfs3(t, to, s, cost + edge_cost))
return true;
} else {
long long scost = u.scost + add[s], tcost = u.tcost + add[t];
if (scost % k == 0)
scost = 0;
if (tcost % k == 0)
tcost = 0;
if (dfs3(t, to, s, cost + u.cost + scost + tcost))
return true;
}
}
return false;
}
void debug() {
cout << "minimum graph" << endl;
for (int v = 0; v < n; ++v) {
for (auto u : minG[v])
cout << v << " -> " << u.to << " edge_type : " << u.edge_type << " "
<< u.scost << " + " << u.cost << " + " << u.tcost << endl;
}
}
int main() {
scanf("%d %d", &n, &k);
// cin >> n >> k;
// G.resize(n);
for (int i = 0; i < n - 1; ++i) {
int u, v, c;
scanf("%d %d %d", &u, &v, &c);
// cin >> u >> v >> c;
G[u].push_back(e(v, c));
G[v].push_back(e(u, c));
}
dfs();
int q;
scanf("%d", &q);
// cin >> q;
int root_q = sqrt_int(q);
// int root_q = 300;
int r = (q + root_q - 1) / root_q;
for (int p = 0; p < r; ++p) {
int rr = min(root_q, q - p * root_q);
// vector<query> Q;
memset(used, false, sizeof(used));
// minG.assign(n, vector<edge>());
for (int i = 0; i < n; ++i)
minG[i].clear();
for (int i = 0; i < rr; ++i) {
// string s;
char s[10];
int a, b;
scanf("%s %d %d", s, &a, &b);
// cin >> s >> a >> b;
Q[i] = query(s[0], a, b);
if (Q[i].type) {
used[a] = true;
} else {
used[a] = used[b] = true;
}
}
pair<int, int> mini, root;
mini = root = make_pair(inf, -1);
for (int i = 0; i < cnt; ++i) {
int v = euler_tour[i];
mini = min(mini, make_pair(depth[v], v));
if (used[v]) {
if (mini.second != -1)
used[mini.second] = true;
mini = make_pair(depth[v], v);
root = min(root, make_pair(depth[v], v));
}
}
dfs2(root.second, root.second);
// debug();
for (int i = 0; i < rr; ++i) {
if (Q[i].type) {
add[Q[i].a] += Q[i].b;
} else {
dfs3(Q[i].a, Q[i].b);
}
}
}
} | replace | 48 | 49 | 48 | 49 | TLE | |
p00365 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
tuple<int, int, int> a, b, now;
int x, y, z;
cin >> x >> y >> z;
a = tie(x, y, z);
cin >> x >> y >> z;
b = tie(x, y, z);
if (a > b)
swap(a, b);
if (a == b) {
cout << 0 << endl;
return 0;
}
auto inc = [](tuple<int, int, int> &x) {
auto numd = [](int y, int m) {
const int a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (m != 2)
return a[m - 1];
if (y % 400 == 0 || y % 4 == 0 && y % 100)
return 29;
return 28;
};
int y, m, d;
tie(y, m, d) = x;
if (++d > numd(y, m)) {
d = 1;
if (++m > 12)
m = 1, y++;
}
x = tie(y, m, d);
};
auto ok = [](tuple<int, int, int> b, tuple<int, int, int> a) {
if (get<1>(a) == get<1>(b) && get<2>(a) == get<2>(b))
return 1;
if (get<1>(a) == 2 && get<2>(a) == 29 && get<1>(b) == 3 && get<2>(b) == 1 &&
!(get<0>(b) % 400 == 0 || get<0>(b) % 4 == 0 && get<0>(b) % 100))
return 1;
return 0;
};
now = a;
int ya = 0, yb = 0, ans = 0;
while (now < b) {
inc(now);
if (ok(now, a))
ya++;
ans = max(ans, ya - yb);
}
dbg(get<0>(now), get<1>(now), get<2>(now));
rep(it, 365 * 4400) {
inc(now);
if (ok(now, a))
ya++;
if (ok(now, b))
yb++;
ans = max(ans, ya - yb);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
tuple<int, int, int> a, b, now;
int x, y, z;
cin >> x >> y >> z;
a = tie(x, y, z);
cin >> x >> y >> z;
b = tie(x, y, z);
if (a > b)
swap(a, b);
if (a == b) {
cout << 0 << endl;
return 0;
}
auto inc = [](tuple<int, int, int> &x) {
auto numd = [](int y, int m) {
const int a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (m != 2)
return a[m - 1];
if (y % 400 == 0 || y % 4 == 0 && y % 100)
return 29;
return 28;
};
int y, m, d;
tie(y, m, d) = x;
if (++d > numd(y, m)) {
d = 1;
if (++m > 12)
m = 1, y++;
}
x = tie(y, m, d);
};
auto ok = [](tuple<int, int, int> b, tuple<int, int, int> a) {
if (get<1>(a) == get<1>(b) && get<2>(a) == get<2>(b))
return 1;
if (get<1>(a) == 2 && get<2>(a) == 29 && get<1>(b) == 3 && get<2>(b) == 1 &&
!(get<0>(b) % 400 == 0 || get<0>(b) % 4 == 0 && get<0>(b) % 100))
return 1;
return 0;
};
now = a;
int ya = 0, yb = 0, ans = 0;
while (now < b) {
inc(now);
if (ok(now, a))
ya++;
ans = max(ans, ya - yb);
}
// dbg(get<0>(now),get<1>(now),get<2>(now));
rep(it, 365 * 4400) {
inc(now);
if (ok(now, a))
ya++;
if (ok(now, b))
yb++;
ans = max(ans, ya - yb);
}
cout << ans << endl;
return 0;
}
| replace | 112 | 113 | 112 | 113 | 0 | 57: get<0>(now)= 2001 get<1>(now)= 11 get<2>(now)= 3
|
p00367 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
int ax[50], bx[50];
int ay[50], by[50];
int az[50], bz[50];
int input() {
int fi, se;
cin >> fi >> se;
return fi * 60 + se;
}
int main() {
cin >> n;
vector<int> X, Y, Z;
for (int i = 0; i < n; i++) {
ax[i] = input();
bx[i] = input();
ay[i] = input();
by[i] = input();
az[i] = input();
bz[i] = input();
X.push_back(ax[i]);
Y.push_back(ay[i]);
Z.push_back(az[i]);
}
typedef pair<int, int> P;
P t[50];
int maxm = 0;
for (int I = 0; I < (int)X.size(); I++) {
int p = X[I];
for (int J = 0; J < (int)Y.size(); J++) {
int q = Y[J];
int cnt = 0;
for (int i = 0; i < n; i++) {
if (ax[i] <= p && p <= bx[i]) {
if (ay[i] <= q && q <= by[i]) {
t[cnt++] = P(az[i], 1);
t[cnt++] = P(bz[i] + 1, -1);
}
}
}
sort(t, t + cnt);
int v = 0, sum = 0;
for (int i = 0; i < cnt; i++) {
sum += t[i].second;
v = max(v, sum);
}
maxm = max(maxm, v);
}
}
cout << maxm << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n;
int ax[50], bx[50];
int ay[50], by[50];
int az[50], bz[50];
int input() {
int fi, se;
cin >> fi >> se;
return fi * 60 + se;
}
int main() {
cin >> n;
vector<int> X, Y, Z;
for (int i = 0; i < n; i++) {
ax[i] = input();
bx[i] = input();
ay[i] = input();
by[i] = input();
az[i] = input();
bz[i] = input();
X.push_back(ax[i]);
Y.push_back(ay[i]);
Z.push_back(az[i]);
}
typedef pair<int, int> P;
P t[100];
int maxm = 0;
for (int I = 0; I < (int)X.size(); I++) {
int p = X[I];
for (int J = 0; J < (int)Y.size(); J++) {
int q = Y[J];
int cnt = 0;
for (int i = 0; i < n; i++) {
if (ax[i] <= p && p <= bx[i]) {
if (ay[i] <= q && q <= by[i]) {
t[cnt++] = P(az[i], 1);
t[cnt++] = P(bz[i] + 1, -1);
}
}
}
sort(t, t + cnt);
int v = 0, sum = 0;
for (int i = 0; i < cnt; i++) {
sum += t[i].second;
v = max(v, sum);
}
maxm = max(maxm, v);
}
}
cout << maxm << endl;
return 0;
}
| replace | 30 | 31 | 30 | 31 | 0 | |
p00369 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int N;
int A[111111];
signed main() {
string s;
cin >> s;
N = s.size();
rep(i, N) A[i] = s[i] - '0';
int ans = 9;
chmin(ans, *max_element(A, A + N) - *min_element(A, A + N));
int ma = 0, mi = INT_MAX;
for (int i = 0; i < N; i++) {
if (A[i] == 1 && i + 1 < N) {
chmax(ma, A[i + 1] + 10);
i++;
} else {
chmin(mi, A[i]);
}
}
if (ma != 0 && mi != INT_MAX)
chmin(ans, ma - mi);
for (int i = 2; i < N; i++) {
string mi(1, '9' + 1);
string ma(1, '0' - 1);
for (int j = 0; j < N; j += i) {
string s;
for (int k = 0; k < i; k++)
s += (char)(A[j + k] + '0');
if (mi > s)
mi = s;
if (ma < s)
ma = s;
}
if (mi.substr(0, i - 2) != ma.substr(0, i - 2))
continue;
int x = (mi[i - 2] - '0') * 10 + mi[i - 1] - '0';
int y = (ma[i - 2] - '0') * 10 + ma[i - 1] - '0';
chmin(ans, y - x);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int N;
int A[111111];
signed main() {
string s;
cin >> s;
N = s.size();
rep(i, N) A[i] = s[i] - '0';
int ans = 9;
chmin(ans, *max_element(A, A + N) - *min_element(A, A + N));
int ma = 0, mi = INT_MAX;
for (int i = 0; i < N; i++) {
if (A[i] == 1 && i + 1 < N) {
chmax(ma, A[i + 1] + 10);
i++;
} else {
chmin(mi, A[i]);
}
}
if (ma != 0 && mi != INT_MAX)
chmin(ans, ma - mi);
for (int i = 2; i < N; i++) {
if (N % i)
continue;
string mi(1, '9' + 1);
string ma(1, '0' - 1);
for (int j = 0; j < N; j += i) {
string s;
for (int k = 0; k < i; k++)
s += (char)(A[j + k] + '0');
if (mi > s)
mi = s;
if (ma < s)
ma = s;
}
if (mi.substr(0, i - 2) != ma.substr(0, i - 2))
continue;
int x = (mi[i - 2] - '0') * 10 + mi[i - 1] - '0';
int y = (ma[i - 2] - '0') * 10 + ma[i - 1] - '0';
chmin(ans, y - x);
}
cout << ans << endl;
return 0;
} | insert | 50 | 50 | 50 | 52 | TLE | |
p00370 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std {
bool operator<(const P &a, const P &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
inline double cross(const P &a, const P &b) { return imag(conj(a) * b); }
inline double dot(const P &a, const P &b) { return real(conj(a) * b); }
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
typedef vector<P> G;
inline int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > EPS)
return +1; // counter clockwise
if (cross(b, c) < -EPS)
return -1; // clockwise
if (dot(b, c) < -EPS)
return +2; // c--a--b on line
if (norm(b) + EPS < norm(c))
return -2; // a--b--c on line
return 0; // c is between a and b (inclusive)
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) < 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) < 0;
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
P s, t;
G ps;
int x, y, n;
cin >> x >> y;
s = P(x, y);
cin >> x >> y;
t = P(x, y);
cin >> n;
rep(i, n) {
cin >> x >> y;
ps.emplace_back(x, y);
}
vector<vector<double>> d(n, vector<double>(n, INF));
rep(i, n) {
d[i][i] = 0;
d[(i + 1) % n][i] = d[i][(i + 1) % n] = abs(ps[i] - ps[(i + 1) % n]);
}
rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
auto ok = [&](const P &a, const P &b) {
const L l(a, b);
rep(i, n) {
if (intersectSS(l, L(ps[i], ps[(i + 1) % n])))
return 0;
if (ccw(ps[i], l[0], l[1]) == 2)
return 0;
}
return 1;
};
double ans = INF;
rep(i, n) rep(j, n) {
if (!ok(s, ps[i]))
continue;
if (!ok(t, ps[j]))
continue;
ans = min(ans, abs(s - ps[i]) + d[i][j] + abs(t - ps[j]));
}
#if 1
int cnt = 0;
rep(i, n) {
P a = ps[i], b = ps[(i + 1) % n];
if (!(ok(s, a) && ok(s, b) && ok(t, a) && ok(t, b)))
continue;
double lo = 0, hi = 1, l, r;
rep(it, 100) {
l = (2 * lo + hi) / 3;
r = (lo + 2 * hi) / 3;
P p1 = a * (1 - l) + b * l;
P p2 = a * (1 - r) + b * r;
if (abs(p1 - s) + abs(p1 - t) < abs(p2 - s) + abs(p2 - t))
hi = r;
else
lo = l;
}
P p = a * (1 - lo) + b * lo;
ans = min(ans, abs(p - s) + abs(p - t));
assert(++cnt <= 2);
}
#endif
printf("%.20f\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std {
bool operator<(const P &a, const P &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
inline double cross(const P &a, const P &b) { return imag(conj(a) * b); }
inline double dot(const P &a, const P &b) { return real(conj(a) * b); }
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
typedef vector<P> G;
inline int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > EPS)
return +1; // counter clockwise
if (cross(b, c) < -EPS)
return -1; // clockwise
if (dot(b, c) < -EPS)
return +2; // c--a--b on line
if (norm(b) + EPS < norm(c))
return -2; // a--b--c on line
return 0; // c is between a and b (inclusive)
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) < 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) < 0;
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
P s, t;
G ps;
int x, y, n;
cin >> x >> y;
s = P(x, y);
cin >> x >> y;
t = P(x, y);
cin >> n;
rep(i, n) {
cin >> x >> y;
ps.emplace_back(x, y);
}
vector<vector<double>> d(n, vector<double>(n, INF));
rep(i, n) {
d[i][i] = 0;
d[(i + 1) % n][i] = d[i][(i + 1) % n] = abs(ps[i] - ps[(i + 1) % n]);
}
rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
auto ok = [&](const P &a, const P &b) {
const L l(a, b);
rep(i, n) {
if (intersectSS(l, L(ps[i], ps[(i + 1) % n])))
return 0;
if (ccw(ps[i], l[0], l[1]) == 2)
return 0;
}
return 1;
};
double ans = INF;
rep(i, n) rep(j, n) {
if (!ok(s, ps[i]))
continue;
if (!ok(t, ps[j]))
continue;
ans = min(ans, abs(s - ps[i]) + d[i][j] + abs(t - ps[j]));
}
#if 1
int cnt = 0;
rep(i, n) {
P a = ps[i], b = ps[(i + 1) % n];
if (!(ok(s, a) && ok(s, b) && ok(t, a) && ok(t, b)))
continue;
double lo = 0, hi = 1, l, r;
rep(it, 100) {
l = (2 * lo + hi) / 3;
r = (lo + 2 * hi) / 3;
P p1 = a * (1 - l) + b * l;
P p2 = a * (1 - r) + b * r;
if (abs(p1 - s) + abs(p1 - t) < abs(p2 - s) + abs(p2 - t))
hi = r;
else
lo = l;
}
P p = a * (1 - lo) + b * lo;
ans = min(ans, abs(p - s) + abs(p - t));
// assert(++cnt <= 2);
}
#endif
printf("%.20f\n", ans);
return 0;
}
| replace | 151 | 152 | 151 | 152 | 0 | |
p00373 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int w1, w2, h1, h2, sum;
int hash_a[700][700][13], hash_b[700][13];
int cumo_a[700][700][13], cumo_b[700][13];
char s[700][700], t[700][700];
void make_table() {
rep(i, h1) rep(j, w1 - w2 + 1) {
rep(k, w2) {
rep(l, 8) hash_a[i][j][(k * 8) / 64] =
hash_a[i][j][(k * 8) / 64] * 2 + (((s[i][j + k] >> l) & 1) ? 1 : 0);
rep(l, 8) cumo_a[i][j][(k * 8) / 64] =
cumo_a[i][j][(k * 8) / 64] * 2 + (s[i][j + k] == '?' ? 1 : 0);
}
}
rep(i, h2) {
rep(j, w2) {
rep(k, 8) hash_b[i][(j * 8) / 64] =
hash_b[i][(j * 8) / 64] * 2 + (((t[i][j] >> k) & 1) ? 1 : 0);
rep(k, 8) cumo_b[i][(j * 8) / 64] =
cumo_b[i][(j * 8) / 64] * 2 + (t[i][j] == '?' ? 1 : 0);
}
}
}
void count_s() {
rep(i, h1 - h2 + 1) {
rep(j, w1 - w2 + 1) {
rep(k, h2) {
int p1[13] = {}, p2[13] = {}, flag = 0;
rep(l, 13) {
p1[l] = hash_a[i + k][j][l] ^ hash_b[k][l];
p2[l] = cumo_a[i + k][j][l] | cumo_b[k][l];
if ((p1[l] | p2[l]) != p2[l]) {
flag++;
break;
}
}
if (flag)
break;
if (k == h2 - 1)
sum++;
}
}
}
}
signed main() {
cin >> w1 >> h1 >> w2 >> h2;
rep(i, h1) scanf("%s", s[i]);
rep(i, h2) scanf("%s", t[i]);
make_table();
count_s();
cout << sum << endl;
} | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int w1, w2, h1, h2, sum;
int hash_a[800][800][13], hash_b[800][13];
int cumo_a[800][800][13], cumo_b[800][13];
char s[800][800], t[800][700];
void make_table() {
rep(i, h1) rep(j, w1 - w2 + 1) {
rep(k, w2) {
rep(l, 8) hash_a[i][j][(k * 8) / 64] =
hash_a[i][j][(k * 8) / 64] * 2 + (((s[i][j + k] >> l) & 1) ? 1 : 0);
rep(l, 8) cumo_a[i][j][(k * 8) / 64] =
cumo_a[i][j][(k * 8) / 64] * 2 + (s[i][j + k] == '?' ? 1 : 0);
}
}
rep(i, h2) {
rep(j, w2) {
rep(k, 8) hash_b[i][(j * 8) / 64] =
hash_b[i][(j * 8) / 64] * 2 + (((t[i][j] >> k) & 1) ? 1 : 0);
rep(k, 8) cumo_b[i][(j * 8) / 64] =
cumo_b[i][(j * 8) / 64] * 2 + (t[i][j] == '?' ? 1 : 0);
}
}
}
void count_s() {
rep(i, h1 - h2 + 1) {
rep(j, w1 - w2 + 1) {
rep(k, h2) {
int p1[13] = {}, p2[13] = {}, flag = 0;
rep(l, 13) {
p1[l] = hash_a[i + k][j][l] ^ hash_b[k][l];
p2[l] = cumo_a[i + k][j][l] | cumo_b[k][l];
if ((p1[l] | p2[l]) != p2[l]) {
flag++;
break;
}
}
if (flag)
break;
if (k == h2 - 1)
sum++;
}
}
}
}
signed main() {
cin >> w1 >> h1 >> w2 >> h2;
rep(i, h1) scanf("%s", s[i]);
rep(i, h2) scanf("%s", t[i]);
make_table();
count_s();
cout << sum << endl;
} | replace | 6 | 9 | 6 | 9 | 127 | /tmp/0f306e58-bb53-4bf2-b3ff-db2fd7d55ff7.out: error while loading shared libraries: libstdc++.so.6: failed to map segment from shared object
|
p00373 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int w1, w2, h1, h2, sum;
int hash_a[700][700][10], hash_b[700][10];
int cumo_a[700][700][10], cumo_b[700][10];
char s[700][700], t[700][700];
void make_table() {
rep(i, h1) rep(j, w1 - w2 + 1) {
rep(k, w2) {
rep(l, 6) hash_a[i][j][(k * 6) / 60] =
hash_a[i][j][(k * 6) / 60] * 2 + (((s[i][j + k] >> l) & 1) ? 1 : 0);
rep(l, 6) cumo_a[i][j][(k * 6) / 60] =
cumo_a[i][j][(k * 6) / 60] * 2 + (s[i][j + k] == 63 ? 1 : 0);
}
}
rep(i, h2) {
rep(j, w2) {
rep(k, 6) hash_b[i][(j * 6) / 60] =
hash_b[i][(j * 6) / 60] * 2 + (((t[i][j] >> k) & 1) ? 1 : 0);
rep(k, 6) cumo_b[i][(j * 6) / 60] =
cumo_b[i][(j * 6) / 60] * 2 + (t[i][j] == 63 ? 1 : 0);
}
}
}
void count_s() {
rep(i, h1 - h2 + 1) {
rep(j, w1 - w2 + 1) {
rep(k, h2) {
int p1[10] = {}, p2[10] = {};
int flag = 0;
rep(l, 10) {
p1[l] = hash_a[i + k][j][l] ^ hash_b[k][l];
p2[l] = cumo_a[i + k][j][l] | cumo_b[k][l];
if ((p1[l] | p2[l]) != p2[l]) {
flag++;
break;
}
}
if (flag)
break;
if (k == h2 - 1)
sum++;
}
}
}
}
void Za_a_tsu() {
rep(i, h1) rep(j, w1) {
if ('0' <= s[i][j] && s[i][j] <= '9')
s[i][j] = (s[i][j] - '0');
if ('a' <= s[i][j] && s[i][j] <= 'z')
s[i][j] = (s[i][j] - 'a' + 11);
if ('A' <= s[i][j] && s[i][j] <= 'Z')
s[i][j] = (s[i][j] - 'A' + 37);
}
rep(i, h2) rep(j, w2) {
if ('0' <= t[i][j] && t[i][j] <= '9')
t[i][j] = (t[i][j] - '0');
if ('a' <= t[i][j] && t[i][j] <= 'z')
t[i][j] = (t[i][j] - 'a' + 11);
if ('A' <= t[i][j] && t[i][j] <= 'Z')
t[i][j] = (t[i][j] - 'A' + 37);
}
}
signed main() {
cin >> w1 >> h1 >> w2 >> h2;
rep(i, h1) scanf("%s", s[i]);
rep(i, h2) scanf("%s", t[i]);
Za_a_tsu();
make_table();
count_s();
cout << sum << endl;
} | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int w1, w2, h1, h2, sum;
int hash_a[800][800][10], hash_b[800][10];
int cumo_a[800][800][10], cumo_b[800][10];
char s[800][700], t[800][800];
void make_table() {
rep(i, h1) rep(j, w1 - w2 + 1) {
rep(k, w2) {
rep(l, 6) hash_a[i][j][(k * 6) / 60] =
hash_a[i][j][(k * 6) / 60] * 2 + (((s[i][j + k] >> l) & 1) ? 1 : 0);
rep(l, 6) cumo_a[i][j][(k * 6) / 60] =
cumo_a[i][j][(k * 6) / 60] * 2 + (s[i][j + k] == 63 ? 1 : 0);
}
}
rep(i, h2) {
rep(j, w2) {
rep(k, 6) hash_b[i][(j * 6) / 60] =
hash_b[i][(j * 6) / 60] * 2 + (((t[i][j] >> k) & 1) ? 1 : 0);
rep(k, 6) cumo_b[i][(j * 6) / 60] =
cumo_b[i][(j * 6) / 60] * 2 + (t[i][j] == 63 ? 1 : 0);
}
}
}
void count_s() {
rep(i, h1 - h2 + 1) {
rep(j, w1 - w2 + 1) {
rep(k, h2) {
int p1[10] = {}, p2[10] = {};
int flag = 0;
rep(l, 10) {
p1[l] = hash_a[i + k][j][l] ^ hash_b[k][l];
p2[l] = cumo_a[i + k][j][l] | cumo_b[k][l];
if ((p1[l] | p2[l]) != p2[l]) {
flag++;
break;
}
}
if (flag)
break;
if (k == h2 - 1)
sum++;
}
}
}
}
void Za_a_tsu() {
rep(i, h1) rep(j, w1) {
if ('0' <= s[i][j] && s[i][j] <= '9')
s[i][j] = (s[i][j] - '0');
if ('a' <= s[i][j] && s[i][j] <= 'z')
s[i][j] = (s[i][j] - 'a' + 11);
if ('A' <= s[i][j] && s[i][j] <= 'Z')
s[i][j] = (s[i][j] - 'A' + 37);
}
rep(i, h2) rep(j, w2) {
if ('0' <= t[i][j] && t[i][j] <= '9')
t[i][j] = (t[i][j] - '0');
if ('a' <= t[i][j] && t[i][j] <= 'z')
t[i][j] = (t[i][j] - 'a' + 11);
if ('A' <= t[i][j] && t[i][j] <= 'Z')
t[i][j] = (t[i][j] - 'A' + 37);
}
}
signed main() {
cin >> w1 >> h1 >> w2 >> h2;
rep(i, h1) scanf("%s", s[i]);
rep(i, h2) scanf("%s", t[i]);
Za_a_tsu();
make_table();
count_s();
cout << sum << endl;
} | replace | 6 | 9 | 6 | 9 | 0 | |
p00384 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
#define MP make_pair
struct t {
ll r, s1, s2;
t(void) { r = 0, s1 = 0, s2 = 0; }
void up(ll x) {
if (s1 < x)
swap(s1, x);
s2 = max(s2, x);
}
void mn(ll x) {
if (s1 == x) {
s1 = s2;
s2 = 0;
}
}
};
ll n, cs[100005], ans;
vector<ll> g[100005];
map<ll, t> dp[100005];
t dfs(ll v, ll p, ll f) {
if (dp[v].count(p))
return dp[v][p];
t res;
if (p == -1 || f) {
for (ll u : g[v]) {
if (u == p)
continue;
t x = dfs(u, v, f);
x.r -= 2;
x.s1--;
if (x.r > 0) {
res.r += x.r;
res.up(-x.r + x.s1);
} else
res.up(x.s1);
}
res.r += cs[v];
res.s1 += res.r;
res.s2 += res.r;
} else {
res = dfs(v, -1, 0);
t x = dfs(p, v, 0);
x.r -= 2;
x.s1--;
if (x.r > 0) {
res.r -= x.r;
res.mn(res.r + x.s1);
res.s1 -= x.r;
} else
res.mn(res.r + x.s1);
}
return dp[v][p] = res;
}
int main(void) {
scanf("%lld", &n);
ll ma = -INF;
for (int i = 0; i < n; i++) {
scanf("%lld", cs + i);
ma = max(ma, cs[i]);
}
if (ma <= 0) {
printf("%lld\n", ma);
return 0;
}
for (int i = 0; i < n - 1; i++) {
ll a, b;
scanf("%lld%lld", &a, &b);
g[--a].PB(--b);
g[b].PB(a);
}
dfs(0, -1, 1);
for (int i = 0; i < n; i++)
ans = max(ans, dfs(i, -1, 0).s1);
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
#define MP make_pair
struct t {
ll r, s1, s2;
t(void) { r = 0, s1 = 0, s2 = 0; }
void up(ll x) {
if (s1 < x)
swap(s1, x);
s2 = max(s2, x);
}
void mn(ll x) {
if (s1 == x) {
s1 = s2;
s2 = 0;
}
}
};
ll n, cs[100005], ans;
vector<ll> g[100005];
map<ll, t> dp[100005];
t dfs(ll v, ll p, ll f) {
if (dp[v].count(p))
return dp[v][p];
t res;
if (p == -1 || f) {
for (int i = 0; i < g[v].size(); i++) {
ll u = g[v][i];
if (u == p)
continue;
t x = dfs(u, v, f);
x.r -= 2;
x.s1--;
if (x.r > 0) {
res.r += x.r;
res.up(-x.r + x.s1);
} else
res.up(x.s1);
}
res.r += cs[v];
res.s1 += res.r;
res.s2 += res.r;
} else {
res = dfs(v, -1, 0);
t x = dfs(p, v, 0);
x.r -= 2;
x.s1--;
if (x.r > 0) {
res.r -= x.r;
res.mn(res.r + x.s1);
res.s1 -= x.r;
} else
res.mn(res.r + x.s1);
}
return dp[v][p] = res;
}
int main(void) {
scanf("%lld", &n);
ll ma = -INF;
for (int i = 0; i < n; i++) {
scanf("%lld", cs + i);
ma = max(ma, cs[i]);
}
if (ma <= 0) {
printf("%lld\n", ma);
return 0;
}
for (int i = 0; i < n - 1; i++) {
ll a, b;
scanf("%lld%lld", &a, &b);
g[--a].PB(--b);
g[b].PB(a);
}
dfs(0, -1, 1);
for (int i = 0; i < n; i++)
ans = max(ans, dfs(i, -1, 0).s1);
printf("%lld\n", ans);
}
| replace | 34 | 35 | 34 | 36 | TLE | |
p00384 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100010];
vector<int> tree[100010];
int mas[100010];
int n;
bool used[100010] = {};
void makeTree(int m) {
used[m] = true;
for (int i = 0; i < graph[m].size(); i++) {
if (!used[graph[m][i]]) {
tree[m].push_back(graph[m][i]);
makeTree(graph[m][i]);
}
}
return;
}
int dp[100010] = {};
int ep[100010] = {};
int fp[100010] = {};
void dfs(int x) {
dp[x] = mas[x];
ep[x] = 0;
fp[x] = 0;
if (tree[x].size() == 0)
return;
for (int i = 0; i < tree[x].size(); i++) {
dfs(tree[x][i]);
}
bool used[100010] = {};
for (int i = 0; i < tree[x].size(); i++) {
if (dp[tree[x][i]] - 2 >= 0) {
used[tree[x][i]] = true;
dp[x] += dp[tree[x][i]] - 2;
}
}
int kari = 0;
int kari2 = 0;
for (int i = 0; i < tree[x].size(); i++) {
if (used[tree[x][i]]) {
if (ep[tree[x][i]] + 1 > kari) {
kari2 = kari;
kari = ep[tree[x][i]] + 1;
} else if (ep[tree[x][i]] + 1 > kari2) {
kari2 = ep[tree[x][i]] + 1;
}
} else {
if (ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2 > kari) {
kari2 = kari;
kari = ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2;
} else if (ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2 > kari2) {
kari2 = ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2;
}
}
}
if (kari >= 0) {
ep[x] = kari;
}
int kari3 = 0;
for (int i = 0; i < tree[x].size(); i++) {
if (used[tree[x][i]]) {
kari3 = max(kari3, fp[tree[x][i]]);
} else {
kari3 = max(kari3, fp[tree[x][i]] + dp[tree[x][i]] - 2);
}
}
fp[x] = max(kari3, max(kari + kari2, max(kari, kari2)));
return;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> mas[i];
}
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
makeTree(0);
dfs(0);
int ans = INT_MIN;
for (int i = 0; i < n; i++) {
ans = max(ans, dp[i] + fp[i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100010];
vector<int> tree[100010];
int mas[100010];
int n;
bool used[100010] = {};
void makeTree(int m) {
used[m] = true;
for (int i = 0; i < graph[m].size(); i++) {
if (!used[graph[m][i]]) {
tree[m].push_back(graph[m][i]);
makeTree(graph[m][i]);
}
}
return;
}
int dp[100010] = {};
int ep[100010] = {};
int fp[100010] = {};
void dfs(int x) {
dp[x] = mas[x];
ep[x] = 0;
fp[x] = 0;
if (tree[x].size() == 0)
return;
for (int i = 0; i < tree[x].size(); i++) {
dfs(tree[x][i]);
}
// bool used[100010] = {};
memset(used, false, sizeof(used));
for (int i = 0; i < tree[x].size(); i++) {
if (dp[tree[x][i]] - 2 >= 0) {
used[tree[x][i]] = true;
dp[x] += dp[tree[x][i]] - 2;
}
}
int kari = 0;
int kari2 = 0;
for (int i = 0; i < tree[x].size(); i++) {
if (used[tree[x][i]]) {
if (ep[tree[x][i]] + 1 > kari) {
kari2 = kari;
kari = ep[tree[x][i]] + 1;
} else if (ep[tree[x][i]] + 1 > kari2) {
kari2 = ep[tree[x][i]] + 1;
}
} else {
if (ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2 > kari) {
kari2 = kari;
kari = ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2;
} else if (ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2 > kari2) {
kari2 = ep[tree[x][i]] + 1 + dp[tree[x][i]] - 2;
}
}
}
if (kari >= 0) {
ep[x] = kari;
}
int kari3 = 0;
for (int i = 0; i < tree[x].size(); i++) {
if (used[tree[x][i]]) {
kari3 = max(kari3, fp[tree[x][i]]);
} else {
kari3 = max(kari3, fp[tree[x][i]] + dp[tree[x][i]] - 2);
}
}
fp[x] = max(kari3, max(kari + kari2, max(kari, kari2)));
return;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> mas[i];
}
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
makeTree(0);
dfs(0);
int ans = INT_MIN;
for (int i = 0; i < n; i++) {
ans = max(ans, dp[i] + fp[i]);
}
cout << ans << endl;
return 0;
}
| replace | 37 | 38 | 37 | 39 | 0 | |
p00392 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
int par[112345];
int rk[112345];
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
rk[i] = 0;
}
}
int fd(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = fd(par[x]);
}
}
void unite(int x, int y) {
x = fd(x);
y = fd(y);
if (x == y)
return;
if (rk[x] < rk[y]) {
par[x] = y;
} else {
par[y] = x;
if (rk[x] == rk[y])
rk[x]++;
}
}
int main() {
int n;
scanf("%d", &n);
init(112345);
std::vector<int> a(n);
REP(i, n) scanf("%d", &a[i]);
for (int i = 2; i < 112345; ++i) {
int pin = -1;
REP(j, n) {
if (a[j] % i == 0) {
if (pin == -1) {
pin = a[j];
} else {
unite(a[j], pin);
}
}
}
}
std::vector<int> sorted(a);
std::sort(sorted.begin(), sorted.end());
int ans = 1;
REP(i, n) {
if (fd(a[i]) != fd(sorted[i])) {
ans = 0;
}
}
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
int par[112345];
int rk[112345];
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
rk[i] = 0;
}
}
int fd(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = fd(par[x]);
}
}
void unite(int x, int y) {
x = fd(x);
y = fd(y);
if (x == y)
return;
if (rk[x] < rk[y]) {
par[x] = y;
} else {
par[y] = x;
if (rk[x] == rk[y])
rk[x]++;
}
}
int main() {
int n;
scanf("%d", &n);
init(112345);
std::vector<int> a(n);
REP(i, n) scanf("%d", &a[i]);
for (int i = 2; i < 3333; ++i) {
int pin = -1;
REP(j, n) {
if (a[j] % i == 0) {
if (pin == -1) {
pin = a[j];
} else {
unite(a[j], pin);
}
}
}
}
std::vector<int> sorted(a);
std::sort(sorted.begin(), sorted.end());
int ans = 1;
REP(i, n) {
if (fd(a[i]) != fd(sorted[i])) {
ans = 0;
}
}
printf("%d\n", ans);
return 0;
}
| replace | 60 | 61 | 60 | 61 | TLE | |
p00423 | C++ | Time Limit Exceeded | #include <cstdio>
int main() {
int a, b, n;
while (scanf("%d", &n) != 0) {
int asum = 0, bsum = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d", &a, &b);
if (a > b) {
asum += a + b;
} else if (a < b) {
bsum += a + b;
} else {
asum += a;
bsum += b;
}
}
printf("%d %d\n", asum, bsum);
}
return 0;
} | #include <cstdio>
int main() {
int a, b, n;
while (scanf("%d", &n), n) {
int asum = 0, bsum = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d", &a, &b);
if (a > b) {
asum += a + b;
} else if (a < b) {
bsum += a + b;
} else {
asum += a;
bsum += b;
}
}
printf("%d %d\n", asum, bsum);
}
return 0;
} | replace | 3 | 4 | 3 | 4 | TLE | |
p00423 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int maisuu, a[10], b[10];
long long int a_p = 0, b_p = 0;
int anser[2][10];
int hasi;
for (int i = 0; i < 5; i++) {
cin >> maisuu;
if (maisuu == 0) {
break;
}
for (int i2 = 0; i2 < maisuu; i2++) {
cin >> a[i2];
cin >> b[i2];
}
for (int i2 = 0; i2 < maisuu; i2++) {
if (a[i2] < b[i2]) {
b_p += a[i2] + b[i2];
} else if (a[i2] > b[i2]) {
a_p += a[i2] + b[i2];
} else if (a[i2] == b[i2]) {
a_p += a[i2];
b_p += b[i2];
}
}
anser[0][i] = a_p;
anser[1][i] = b_p;
maisuu = 0;
a_p = 0;
b_p = 0;
hasi = i;
}
for (int i = 0; i <= hasi; i++) {
cout << anser[0][i] << " " << anser[1][i] << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int maisuu, a[15000], b[15000];
long long int a_p = 0, b_p = 0;
int anser[2][10];
int hasi;
for (int i = 0; i < 5; i++) {
cin >> maisuu;
if (maisuu == 0) {
break;
}
for (int i2 = 0; i2 < maisuu; i2++) {
cin >> a[i2];
cin >> b[i2];
}
for (int i2 = 0; i2 < maisuu; i2++) {
if (a[i2] < b[i2]) {
b_p += a[i2] + b[i2];
} else if (a[i2] > b[i2]) {
a_p += a[i2] + b[i2];
} else if (a[i2] == b[i2]) {
a_p += a[i2];
b_p += b[i2];
}
}
anser[0][i] = a_p;
anser[1][i] = b_p;
maisuu = 0;
a_p = 0;
b_p = 0;
hasi = i;
}
for (int i = 0; i <= hasi; i++) {
cout << anser[0][i] << " " << anser[1][i] << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00423 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int t;
while (cin >> t && t > 0) {
int p1 = 0, p2 = 0;
while (t > 0) {
int a = 0, b = 0;
cin >> a >> b;
if (a >= 0 && a <= 9 && a >= 0 && a <= 9) {
continue;
}
if (a > b) {
p1 += a + b;
} else if (a < b) {
p2 += a + b;
} else {
p1 += a;
p2 += b;
}
t--;
}
cout << p1 << " " << p2 << endl;
}
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int t;
while (cin >> t && t > 0) {
int p1 = 0, p2 = 0;
while (t > 0) {
int a = 0, b = 0;
cin >> a >> b;
if (a < 0 || a > 9 || a < 0 || a > 9) {
continue;
}
if (a > b) {
p1 += a + b;
} else if (a < b) {
p2 += a + b;
} else {
p1 += a;
p2 += b;
}
t--;
}
cout << p1 << " " << p2 << endl;
}
return 0;
}
| replace | 9 | 10 | 9 | 10 | TLE | |
p00423 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int n[10000000], s1, s2;
int main() {
int p, a, b;
while (true) {
s1 = 0;
s2 = 0;
cin >> p;
for (int i = 0; i < p; i++) {
cin >> a >> b;
if (a > b) {
s1 += a + b;
} else if (b > a) {
s2 += a + b;
} else {
s1 += a;
s2 += b;
}
}
cout << s1 << ' ' << s2 << endl;
}
} | #include <iostream>
using namespace std;
int n[10000000], s1, s2;
int main() {
int p, a, b;
while (true) {
s1 = 0;
s2 = 0;
cin >> p;
if (p == 0) {
break;
}
for (int i = 0; i < p; i++) {
cin >> a >> b;
if (a > b) {
s1 += a + b;
} else if (b > a) {
s2 += a + b;
} else {
s1 += a;
s2 += b;
}
}
cout << s1 << ' ' << s2 << endl;
}
} | insert | 9 | 9 | 9 | 12 | TLE | |
p00423 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
int n;
while (cin >> n, !0) {
int a = 0;
int b = 0;
for (int i = 0; i < n; i++) {
int r, l;
cin >> l >> r;
if (r < l) {
a += r + l;
} else if (r > l) {
b += r + l;
} else if (r == l) {
a += l;
b += r;
}
}
cout << a << " " << b << endl;
}
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
int n;
while (cin >> n) {
if (n == 0)
break;
int a = 0;
int b = 0;
for (int i = 0; i < n; i++) {
int r, l;
cin >> l >> r;
if (r < l) {
a += r + l;
} else if (r > l) {
b += r + l;
} else if (r == l) {
a += l;
b += r;
}
}
cout << a << " " << b << endl;
}
} | replace | 11 | 12 | 11 | 14 | TLE | |
p00423 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))
// #define int ll
using namespace std;
bool test = 0;
/* ?????????????????¬??¨ */
int main() {
int i, j, k, l;
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0)
break;
int score[2] = {0};
for (i = 0; i < n; i++) {
int num[2];
cin >> num[0] >> num[1];
auto sum = num[0] + num[1];
if (num[0] > num[1])
score[0] += sum;
else if (num[0] < num[1])
score[1] += sum;
else {
for (j = 0; j < 2; j++)
score[i] += num[i];
}
}
printf("%d %d\n", score[0], score[1]);
}
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))
// #define int ll
using namespace std;
bool test = 0;
/* ?????????????????¬??¨ */
int main() {
int i, j, k, l;
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0)
break;
int score[2] = {0};
for (i = 0; i < n; i++) {
int num[2];
cin >> num[0] >> num[1];
auto sum = num[0] + num[1];
if (num[0] > num[1])
score[0] += sum;
else if (num[0] < num[1])
score[1] += sum;
else {
for (j = 0; j < 2; j++)
score[j] += num[j];
}
}
printf("%d %d\n", score[0], score[1]);
}
return 0;
} | replace | 42 | 43 | 42 | 43 | 0 | |
p00423 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n, a, b, at, bt;
loop:
scanf("%d\n", &n); // 各人のカード枚数
if (n == 0)
goto end_scope;
at = 0;
bt = 0;
labl_testloop:
scanf("%d %d\n", a, b);
if (a > b)
at += a + b;
else if (a == b) {
at += a;
bt += b;
} else
bt += a + b;
n--;
if (n > 0)
goto labl_testloop;
printf("%d %d\n", at, bt);
goto loop;
end_scope:
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, a, b, at, bt;
loop:
scanf("%d\n", &n); // 各人のカード枚数
if (n == 0)
goto end_scope;
at = 0;
bt = 0;
labl_testloop:
scanf("%d %d\n", &a, &b);
if (a > b)
at += a + b;
else if (a == b) {
at += a;
bt += b;
} else
bt += a + b;
n--;
if (n > 0)
goto labl_testloop;
printf("%d %d\n", at, bt);
goto loop;
end_scope:
return 0;
} | replace | 14 | 15 | 14 | 15 | -11 | |
p00423 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int n, a, b, ap, bp, i;
while (1) {
cin >> n;
ap = bp = 0;
for (i = 0; i < n; i++) {
cin >> a >> b;
if (a > b)
ap += a + b;
else if (b > a)
bp += a + b;
else
ap += a, bp += b;
}
cout << ap << ' ' << bp << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, a, b, ap, bp, i;
while (1) {
cin >> n;
if (n == 0)
break;
ap = bp = 0;
for (i = 0; i < n; i++) {
cin >> a >> b;
if (a > b)
ap += a + b;
else if (b > a)
bp += a + b;
else
ap += a, bp += b;
}
cout << ap << ' ' << bp << endl;
}
return 0;
} | insert | 6 | 6 | 6 | 8 | TLE | |
p00423 | C++ | Time Limit Exceeded | #include <stdio.h>
int main(void) {
int n;
int a[10000];
int b[10000];
int i;
int suma, sumb;
scanf("%d", &n);
while (n != 0) {
suma = 0;
sumb = 0;
for (i = 0; i < n; i++) {
scanf("%d %d", &a[i], &b[i]);
if (a[i] > b[i]) {
suma = suma + a[i] + b[i];
} else if (a[i] < b[i]) {
sumb = sumb + a[i] + b[i];
} else {
suma = suma + a[i];
sumb = sumb + b[i];
}
}
printf("%d %d\n", suma, sumb);
scanf("%d %d", &a[i], &b[i]);
}
return 0;
} | #include <stdio.h>
int main(void) {
int n;
int a[10000];
int b[10000];
int i;
int suma, sumb;
scanf("%d", &n);
while (n != 0) {
suma = 0;
sumb = 0;
for (i = 0; i < n; i++) {
scanf("%d %d", &a[i], &b[i]);
if (a[i] > b[i]) {
suma = suma + a[i] + b[i];
} else if (a[i] < b[i]) {
sumb = sumb + a[i] + b[i];
} else {
suma = suma + a[i];
sumb = sumb + b[i];
}
}
printf("%d %d\n", suma, sumb);
scanf("%d", &n);
}
return 0;
} | replace | 24 | 25 | 24 | 25 | TLE |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.