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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p01126 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x, min, max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) \
(range(x, minX, maxX) && range(y, minY, maxY))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};
int n, m, a;
VVI tbl;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
tbl.clear();
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0)
break;
tbl.resize(n + 1, VI(1001));
rep(i, m) {
int h, p, q;
cin >> h >> p >> q;
tbl[h][p] = q;
tbl[h][q] = p;
}
int pos = a;
rep(i, 1001) {
if (tbl[pos][i] != 0) {
pos = tbl[pos][i];
}
}
cout << pos << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x, min, max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) \
(range(x, minX, maxX) && range(y, minY, maxY))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};
int n, m, a;
VVI tbl;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
tbl.clear();
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0)
break;
tbl.resize(n + 1, VI(1001));
rep(i, m) {
int h, p, q;
cin >> h >> p >> q;
tbl[p][1000 - h] = q;
tbl[q][1000 - h] = p;
}
int pos = a;
rep(i, 1001) {
if (tbl[pos][i] != 0) {
pos = tbl[pos][i];
}
}
cout << pos << endl;
}
return 0;
} | replace | 39 | 41 | 39 | 41 | 0 | |
p01126 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
struct st {
int a, b, c;
};
int main() {
int n, m, a;
while (cin >> n >> m >> a, n) {
vector<st> v;
rep(i, n) {
int h, p, q;
cin >> h >> p >> q;
v.push_back({h, p, q});
}
sort(v.begin(), v.end(), [](st a, st b) { return a.a > b.a; });
int pos = a;
for (st i : v) {
if (i.b == pos)
pos = i.c;
else if (i.c == pos)
pos = i.b;
}
cout << pos << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
struct st {
int a, b, c;
};
int main() {
int n, m, a;
while (cin >> n >> m >> a, n) {
vector<st> v;
rep(i, m) {
int h, p, q;
cin >> h >> p >> q;
v.push_back({h, p, q});
}
sort(v.begin(), v.end(), [](st a, st b) { return a.a > b.a; });
int pos = a;
for (st i : v) {
if (i.b == pos)
pos = i.c;
else if (i.c == pos)
pos = i.b;
}
cout << pos << endl;
}
} | replace | 12 | 13 | 12 | 13 | TLE | |
p01126 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
int n, m, a;
// a,bÌcüÉ©©é¡ü̳Ìê
set<int> rightLine[101];
set<int> leftLine[101];
while (cin >> n >> m >> a && !(n == 0 && m == 0 && a == 0)) {
for (int i = 0; i < 101; i++) {
rightLine[i].clear();
leftLine[i].clear();
}
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
rightLine[p].insert(-h);
leftLine[q].insert(-h);
}
int ch = -1002;
int ct = a;
// S[·éÜÅV~
[g
while (1) {
int t = 1;
int s = 1;
// ©gÌEƶð`FbN
if (ct != 1) {
set<int>::iterator it = leftLine[ct].upper_bound(ch);
if (it != leftLine[ct].end())
t = *it;
}
if (ct != n) {
set<int>::iterator it = rightLine[ct].upper_bound(ch);
if (it != rightLine[ct].end())
s = *it;
}
if (t == 1 && s == 1)
break;
else if (t == 1) {
ch = s;
ct++;
} else if (s == 1) {
ch = t;
ct--;
}
}
cout << ct << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
int n, m, a;
// a,bÌcüÉ©©é¡ü̳Ìê
set<int> rightLine[101];
set<int> leftLine[101];
while (cin >> n >> m >> a && !(n == 0 && m == 0 && a == 0)) {
for (int i = 0; i < 101; i++) {
rightLine[i].clear();
leftLine[i].clear();
}
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
rightLine[p].insert(-h);
leftLine[q].insert(-h);
}
int ch = -1002;
int ct = a;
// S[·éÜÅV~
[g
while (1) {
int t = 1;
int s = 1;
// ©gÌEƶð`FbN
if (ct != 1) {
set<int>::iterator it = leftLine[ct].upper_bound(ch);
if (it != leftLine[ct].end())
t = *it;
}
if (ct != n) {
set<int>::iterator it = rightLine[ct].upper_bound(ch);
if (it != rightLine[ct].end())
s = *it;
}
if (t == 1 && s == 1)
break;
else if (t == 1) {
ch = s;
ct++;
} else if (s == 1) {
ch = t;
ct--;
} else {
if (s > t) {
ch = t;
ct--;
} else {
ch = s;
ct++;
}
}
}
cout << ct << endl;
}
return 0;
} | insert | 47 | 47 | 47 | 55 | TLE | |
p01126 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, a;
while (true) {
cin >> n >> m >> a;
vector<int> amida1(m), amida2(m), amida3(m);
for (int i = 0; i < m; i++) {
cin >> amida1[i] >> amida2[i] >> amida3[i];
}
int maxh, maxpos, pos = a, posh = 869120;
while (true) {
maxh = -1, maxpos = -1;
for (int i = 0; i < m; i++) {
if (amida2[i] == pos) {
if (maxh < amida1[i] && amida1[i] < posh) {
maxh = amida1[i];
maxpos = amida3[i];
}
}
if (amida3[i] == pos) {
if (maxh < amida1[i] && amida1[i] < posh) {
maxh = amida1[i];
maxpos = amida2[i];
}
}
}
if (maxh == -1) {
break;
}
pos = maxpos;
posh = maxh;
}
cout << pos << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, a;
while (true) {
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0) {
break;
}
vector<int> amida1(m), amida2(m), amida3(m);
for (int i = 0; i < m; i++) {
cin >> amida1[i] >> amida2[i] >> amida3[i];
}
int maxh, maxpos, pos = a, posh = 869120;
while (true) {
maxh = -1, maxpos = -1;
for (int i = 0; i < m; i++) {
if (amida2[i] == pos) {
if (maxh < amida1[i] && amida1[i] < posh) {
maxh = amida1[i];
maxpos = amida3[i];
}
}
if (amida3[i] == pos) {
if (maxh < amida1[i] && amida1[i] < posh) {
maxh = amida1[i];
maxpos = amida2[i];
}
}
}
if (maxh == -1) {
break;
}
pos = maxpos;
posh = maxh;
}
cout << pos << endl;
}
return 0;
} | insert | 10 | 10 | 10 | 14 | TLE | |
p01126 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
#define len(x) ((int)(x).size())
#define tmax(a, b, c) max((a), max((b), (c)))
#define tmin(a, b, c) min((a), min((b), (c)))
#define debug(x) cerr << #x << " is " << x << endl;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
int amd[110][1010];
int main() {
while (1) {
int n, m, a;
cin >> n >> m >> a;
if (!n && !m && !a)
break;
memset(amd, 0, sizeof(amd));
int d = 0;
rep(i, 0, m) {
int h, p, q;
cin >> h >> p >> q;
if (p > q)
swap(p, q);
amd[h][p] = 1;
amd[h][q] = 2;
d = max(d, h);
}
while (d) {
// printf("n=%d a=%d amd[n][a]=%d\n",n,a,amd[n][a]);
if (amd[d][a] == 1)
a++;
else if (amd[d][a] == 2)
a--;
d--;
}
cout << a << endl;
}
return 0;
} | #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
#define len(x) ((int)(x).size())
#define tmax(a, b, c) max((a), max((b), (c)))
#define tmin(a, b, c) min((a), min((b), (c)))
#define debug(x) cerr << #x << " is " << x << endl;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
int amd[1010][1010];
int main() {
while (1) {
int n, m, a;
cin >> n >> m >> a;
if (!n && !m && !a)
break;
memset(amd, 0, sizeof(amd));
int d = 0;
rep(i, 0, m) {
int h, p, q;
cin >> h >> p >> q;
if (p > q)
swap(p, q);
amd[h][p] = 1;
amd[h][q] = 2;
d = max(d, h);
}
while (d) {
// printf("n=%d a=%d amd[n][a]=%d\n",n,a,amd[n][a]);
if (amd[d][a] == 1)
a++;
else if (amd[d][a] == 2)
a--;
d--;
}
cout << a << endl;
}
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p01126 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int>> w_line;
signed main() {
int n, m, a;
while (cin >> n >> m >> a, n) {
map<int, int> w_line[1001];
for (int i = 0; i < n; i++) {
int h, p, q;
cin >> h >> p >> q;
w_line[h][p] = q;
w_line[h][q] = p;
}
for (int i = 1000; i >= 1; i--) {
if (w_line[i][a])
a = w_line[i][a];
}
cout << a << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int>> w_line;
signed main() {
int n, m, a;
while (cin >> n >> m >> a, n) {
int w_line[1001][101] = {0};
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
w_line[h][p] = q;
w_line[h][q] = p;
}
for (int i = 1000; i >= 1; i--) {
if (w_line[i][a])
a = w_line[i][a];
}
cout << a << endl;
}
return 0;
}
| replace | 10 | 12 | 10 | 12 | TLE | |
p01126 | C++ | Runtime Error | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
struct ans {
int n;
ans *next;
};
int main() {
//
ans *start = new ans();
start->next = NULL;
ans *end = start, *buf;
//
char s[20];
char *ps;
int i, j;
int n, m, a;
int h, p, q;
int line[100][1000];
int x, y;
while (fgets(s, sizeof(s), stdin)) {
ps = strtok(s, " ");
n = atoi(ps);
ps = strtok(NULL, " ");
m = atoi(ps);
ps = strtok(NULL, " ");
a = atoi(ps) - 1;
if (n == 0 && m == 0 && a == -1)
break;
memset(line, 0, sizeof(line));
for (i = 0; i < m; i++) {
fgets(s, sizeof(s), stdin);
ps = strtok(s, " ");
h = atoi(ps) - 1;
ps = strtok(NULL, " ");
p = atoi(ps) - 1;
ps = strtok(NULL, " ");
q = atoi(ps) - 1;
line[p][h] = (p - q);
line[q][h] = (q - p);
}
x = a;
for (y = 999; y >= 0; y--)
x += line[x][y];
//
buf = new ans();
buf->n = x + 1;
buf->next = NULL;
end->next = buf;
end = buf;
//
}
buf = start->next;
delete start;
while (buf != NULL) {
cout << (buf->n) << endl;
end = buf;
buf = buf->next;
delete end;
}
return 0;
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
struct ans {
int n;
ans *next;
};
int main() {
//
ans *start = new ans();
start->next = NULL;
ans *end = start, *buf;
//
char s[20];
char *ps;
int i, j;
int n, m, a;
int h, p, q;
int line[100][1000];
int x, y;
while (fgets(s, sizeof(s), stdin)) {
ps = strtok(s, " ");
n = atoi(ps);
ps = strtok(NULL, " ");
m = atoi(ps);
ps = strtok(NULL, " ");
a = atoi(ps) - 1;
if (n == 0 && m == 0 && a == -1)
break;
memset(line, 0, sizeof(line));
for (i = 0; i < m; i++) {
fgets(s, sizeof(s), stdin);
ps = strtok(s, " ");
h = atoi(ps) - 1;
ps = strtok(NULL, " ");
p = atoi(ps) - 1;
ps = strtok(NULL, " ");
q = atoi(ps) - 1;
line[p][h] = (q - p);
line[q][h] = (p - q);
}
x = a;
for (y = 999; y >= 0; y--)
x += line[x][y];
//
buf = new ans();
buf->n = x + 1;
buf->next = NULL;
end->next = buf;
end = buf;
//
}
buf = start->next;
delete start;
while (buf != NULL) {
cout << (buf->n) << endl;
end = buf;
buf = buf->next;
delete end;
}
return 0;
} | replace | 43 | 45 | 43 | 45 | 0 | |
p01126 | C++ | Runtime Error | #include <cstring>
#include <iostream>
using namespace std;
int t[1002][1002];
int main() {
int n, m, a;
while (cin >> n >> m >> a, n || m || a) {
memset(t, -1, sizeof(t));
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
t[1000 - h - 1][p - 1] = q - 1;
t[1000 - h - 1][q - 1] = p - 1;
}
a--;
for (int i = 0; i < 1000; i++) {
if (t[i][a] == -1)
continue;
a = t[i][a];
}
cout << a + 1 << endl;
}
} | #include <cstring>
#include <iostream>
using namespace std;
int t[1002][1002];
int main() {
int n, m, a;
while (cin >> n >> m >> a, n || m || a) {
memset(t, -1, sizeof(t));
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
t[1000 - h][p - 1] = q - 1;
t[1000 - h][q - 1] = p - 1;
}
a--;
for (int i = 0; i < 1000; i++) {
if (t[i][a] == -1)
continue;
a = t[i][a];
}
cout << a + 1 << endl;
}
} | replace | 15 | 17 | 15 | 17 | 0 | |
p01126 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
using namespace std;
int main() {
int n, m, a;
while (1) {
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0)
break;
int amida[1000][100] = {0};
int h, p, q, max_h = 0;
for (int i = 0; i < m; i++) {
cin >> h >> p >> q;
amida[h][p] = 1;
amida[h][q] = -1;
if (h > max_h)
max_h = h;
}
pair<int, int> dot;
dot.first = max_h + 1;
dot.second = a;
while (1) {
if (dot.first == 0)
break;
else if (amida[dot.first][dot.second] == 1) {
(dot.second)++;
amida[dot.first][dot.second] = 0;
} else if (amida[dot.first][dot.second] == -1) {
(dot.second)--;
amida[dot.first][dot.second] = 0;
} else {
(dot.first)--;
}
}
cout << dot.second << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
using namespace std;
int main() {
int n, m, a;
while (1) {
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0)
break;
int amida[1001][101] = {0};
int h, p, q, max_h = 0;
for (int i = 0; i < m; i++) {
cin >> h >> p >> q;
amida[h][p] = 1;
amida[h][q] = -1;
if (h > max_h)
max_h = h;
}
pair<int, int> dot;
dot.first = max_h + 1;
dot.second = a;
while (1) {
if (dot.first == 0)
break;
else if (amida[dot.first][dot.second] == 1) {
(dot.second)++;
amida[dot.first][dot.second] = 0;
} else if (amida[dot.first][dot.second] == -1) {
(dot.second)--;
amida[dot.first][dot.second] = 0;
} else {
(dot.first)--;
}
}
cout << dot.second << endl;
}
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p01126 | C++ | Runtime Error |
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2001
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) \
cout << "{ "; \
for (auto nth : list) { \
cout << nth << " "; \
} \
cout << "}" << endl;
using namespace std;
struct Line {
int height;
int from;
int to;
bool operator<(const Line &right) const { return height < right.height; }
};
int main() {
int N, M, A;
while (cin >> N >> M >> A) {
if (N == 0 && M == 0 && A == 0) {
break;
}
vector<Line> lines(M);
vector<int> amida(N + 1, 0);
REP(i, 1, N + 2) { amida[i] = i; }
if (M != 0) {
int H, P, Q;
rep(i, M) {
cin >> H >> P >> Q;
lines[i] = {H, P, Q};
}
sort(ALL(lines));
rep(i, M) {
int p = lines[i].from;
int q = lines[i].to;
swap(amida[p], amida[q]);
}
}
cout << amida[A] << endl;
}
return 0;
} |
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2001
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) \
cout << "{ "; \
for (auto nth : list) { \
cout << nth << " "; \
} \
cout << "}" << endl;
using namespace std;
struct Line {
int height;
int from;
int to;
bool operator<(const Line &right) const { return height < right.height; }
};
int main() {
int N, M, A;
while (cin >> N >> M >> A) {
if (N == 0 && M == 0 && A == 0) {
break;
}
vector<Line> lines(M);
vector<int> amida(N + 1, 0);
rep(i, amida.size()) { amida[i] = i; }
if (M != 0) {
int H, P, Q;
rep(i, M) {
cin >> H >> P >> Q;
lines[i] = {H, P, Q};
}
sort(ALL(lines));
rep(i, M) {
int p = lines[i].from;
int q = lines[i].to;
swap(amida[p], amida[q]);
}
}
cout << amida[A] << endl;
}
return 0;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p01126 | C++ | Time Limit Exceeded | #include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int n, m, a;
while (cin >> n >> m >> a, n) {
vector<vector<pair<int, int>>> line(1001);
for (int i = 0; i < n; i++) {
int h, p, q;
cin >> h >> p >> q;
line[h].push_back(make_pair(p, q));
line[h].push_back(make_pair(q, p));
}
int now = a;
for (int i = 1000; i > 0; i--) {
for (int j = 0; j < line[i].size(); j++) {
if (now == line[i][j].first) {
now = line[i][j].second;
break;
}
}
}
cout << now << endl;
}
} | #include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int n, m, a;
while (cin >> n >> m >> a, n) {
vector<vector<pair<int, int>>> line(1001);
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
line[h].push_back(make_pair(p, q));
line[h].push_back(make_pair(q, p));
}
int now = a;
for (int i = 1000; i > 0; i--) {
for (int j = 0; j < line[i].size(); j++) {
if (now == line[i][j].first) {
now = line[i][j].second;
break;
}
}
}
cout << now << endl;
}
} | replace | 10 | 11 | 10 | 11 | TLE | |
p01126 | C++ | Runtime Error | #include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
class position {
public:
int x, y;
int height;
};
int main() {
int n, m, a;
while (1) {
cin >> n >> m >> a;
if (!n && !m && !a)
break;
int dt[n + 1];
rep(i, n + 1) dt[i] = i;
position p[m];
rep(i, m) cin >> p[i].height >> p[i].x >> p[i].y;
for (int i = 1; i < n - 1; i++) {
for (int j = n - 1; j >= i; j--) {
if (p[j].height < p[j - 1].height) {
position alt = p[j];
p[j] = p[j - 1];
p[j - 1] = alt;
}
}
}
rep(i, m) {
int alt = dt[p[i].x];
dt[p[i].x] = dt[p[i].y];
dt[p[i].y] = alt;
}
cout << dt[a] << endl;
}
return 0;
} | #include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
class position {
public:
int x, y;
int height;
};
int main() {
int n, m, a;
while (1) {
cin >> n >> m >> a;
if (!n && !m && !a)
break;
int dt[n + 1];
rep(i, n + 1) dt[i] = i;
position p[m];
rep(i, m) cin >> p[i].height >> p[i].x >> p[i].y;
for (int i = 1; i < m - 1; i++) {
for (int j = m - 1; j >= i; j--) {
if (p[j].height < p[j - 1].height) {
position alt = p[j];
p[j] = p[j - 1];
p[j - 1] = alt;
}
}
}
rep(i, m) {
int alt = dt[p[i].x];
dt[p[i].x] = dt[p[i].y];
dt[p[i].y] = alt;
}
cout << dt[a] << endl;
}
return 0;
} | replace | 21 | 23 | 21 | 23 | 0 | |
p01126 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int field[1001][101];
while (true) {
int n, m, a;
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0) {
break;
}
memset(field, 0, sizeof(field));
int st = 0;
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
field[h][p] = q;
field[h][q] = p;
st = max(st, h);
}
for (int i = st + 1; i > 0; i--) {
if (field[i][a] != 0) {
a = field[i][a];
}
}
printf("%d\n", a);
}
return 0;
} | #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
int field[1001][101];
while (true) {
int n, m, a;
cin >> n >> m >> a;
if (n == 0 && m == 0 && a == 0) {
break;
}
memset(field, 0, sizeof(field));
int st = 0;
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
field[h][p] = q;
field[h][q] = p;
st = max(st, h);
}
for (int i = st; i > 0; i--) {
if (field[i][a] != 0) {
a = field[i][a];
}
}
printf("%d\n", a);
}
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p01126 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, a, h, p, q;
while (cin >> n >> m >> a, n) {
vector<pair<int, int>> v;
vector<vector<pair<int, int>>> vec;
for (int i = 0; i < n + 2; i++)
vec.push_back(v);
for (int i = 0; i < m; i++) {
cin >> h >> p >> q;
vec[p].push_back(make_pair(h, q));
vec[q].push_back(make_pair(h, p));
}
for (int i = 0; i < n + 2; i++)
sort(vec[i].begin(), vec[i].end());
int mh = 1001;
while (mh > 0) {
while (vec[a][vec[a].size() - 1].first < mh)
mh--;
for (long i = vec[a].size() - 1; i >= 0; i--) {
if (vec[a][i].first == mh) {
a = vec[a][i].second;
break;
} else if (vec[a][i].first < mh)
break;
}
mh--;
}
cout << a << endl;
}
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, a, h, p, q;
while (cin >> n >> m >> a, n) {
vector<pair<int, int>> v;
vector<vector<pair<int, int>>> vec;
for (int i = 0; i < n + 2; i++)
vec.push_back(v);
for (int i = 0; i < m; i++) {
cin >> h >> p >> q;
vec[p].push_back(make_pair(h, q));
vec[q].push_back(make_pair(h, p));
}
for (int i = 0; i < n + 2; i++)
sort(vec[i].begin(), vec[i].end());
int mh = 1001;
while (mh > 0) {
for (long i = vec[a].size() - 1; i >= 0; i--) {
if (vec[a][i].first == mh) {
a = vec[a][i].second;
break;
} else if (vec[a][i].first < mh)
break;
}
mh--;
}
cout << a << endl;
}
} | delete | 21 | 23 | 21 | 21 | 0 | |
p01126 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct line {
int h, p, q;
line() {}
~line() {}
bool operator<(const line &b) const { return h < b.h; }
};
int main() {
int n, m, a;
while (true) {
scanf("%d%d%d", &n, &m, &a);
if ((n | m | a) == 0)
break;
vector<int> amd(n);
for (int i = 0; i < n; i++) {
amd[i] = i + 1;
}
vector<line> ll(n);
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &ll[i].h, &ll[i].p, &ll[i].q);
}
sort(ll.begin(), ll.end());
for (int i = 0; i < m; i++) {
swap(amd[--ll[i].p], amd[--ll[i].q]);
}
printf("%d\n", amd[--a]);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct line {
int h, p, q;
line() {}
~line() {}
bool operator<(const line &b) const { return h < b.h; }
};
int main() {
int n, m, a;
while (true) {
scanf("%d%d%d", &n, &m, &a);
if ((n | m | a) == 0)
break;
vector<int> amd(n);
for (int i = 0; i < n; i++) {
amd[i] = i + 1;
}
vector<line> ll(m);
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &ll[i].h, &ll[i].p, &ll[i].q);
}
sort(ll.begin(), ll.end());
for (int i = 0; i < m; i++) {
swap(amd[--ll[i].p], amd[--ll[i].q]);
}
printf("%d\n", amd[--a]);
}
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p01126 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define mod 1000000007 // 1e9+7
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 201
bool calc() {
int n, m, a, h, p, q;
pair<int, pair<int, int>> v[SIZE];
scanf("%d%d%d", &n, &m, &a);
if (n == 0)
return false;
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &h, &p, &q);
v[i] = {-h, {p, q}};
}
sort(v, v + m);
for (int i = 0; i < m; i++) {
if (a == v[i].second.first)
a = v[i].second.second;
else if (a == v[i].second.second)
a = v[i].second.first;
}
printf("%d\n", a);
return true;
}
int main() {
while (calc())
;
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define mod 1000000007 // 1e9+7
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 1001
bool calc() {
int n, m, a, h, p, q;
pair<int, pair<int, int>> v[SIZE];
scanf("%d%d%d", &n, &m, &a);
if (n == 0)
return false;
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &h, &p, &q);
v[i] = {-h, {p, q}};
}
sort(v, v + m);
for (int i = 0; i < m; i++) {
if (a == v[i].second.first)
a = v[i].second.second;
else if (a == v[i].second.second)
a = v[i].second.first;
}
printf("%d\n", a);
return true;
}
int main() {
while (calc())
;
return 0;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p01126 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int n, m, a;
int h, p, q;
int now_a;
pair<int, pair<int, int>> data[100];
int main() {
while (1) {
// Input
cin >> n >> m >> a;
now_a = a;
if (n + m + a == 0)
break;
for (int i = 0; i < m; i++) {
cin >> h >> p >> q;
data[i] = make_pair(-h, make_pair(p, q));
}
// sort
sort(data, data + m);
//
for (int i = 0; i < m; i++) {
if ((now_a == data[i].second.first) || (now_a == data[i].second.second))
(now_a == data[i].second.first) ? now_a = data[i].second.second
: now_a = data[i].second.first;
}
// Output
cout << now_a << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int n, m, a;
int h, p, q;
int now_a;
pair<int, pair<int, int>> data[1000];
int main() {
while (1) {
// Input
cin >> n >> m >> a;
now_a = a;
if (n + m + a == 0)
break;
for (int i = 0; i < m; i++) {
cin >> h >> p >> q;
data[i] = make_pair(-h, make_pair(p, q));
}
// sort
sort(data, data + m);
//
for (int i = 0; i < m; i++) {
if ((now_a == data[i].second.first) || (now_a == data[i].second.second))
(now_a == data[i].second.first) ? now_a = data[i].second.second
: now_a = data[i].second.first;
}
// Output
cout << now_a << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | TLE | |
p01126 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct amida {
int h, p, q;
};
bool cmp(const amida &x, const amida &y) { return x.h > y.h; }
int main() {
int n, m, a;
while (cin >> n >> m >> a && (n || m || a)) {
vector<amida> b(n);
for (int i = 0; i < m; ++i)
cin >> b[i].h >> b[i].p >> b[i].q;
sort(b.begin(), b.end(), cmp);
for (int i = 0; i < m; ++i) {
if (a == b[i].p)
a = b[i].q;
else if (a == b[i].q)
a = b[i].p;
}
cout << a << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct amida {
int h, p, q;
};
bool cmp(const amida &x, const amida &y) { return x.h > y.h; }
int main() {
int n, m, a;
while (cin >> n >> m >> a && (n || m || a)) {
vector<amida> b(m);
for (int i = 0; i < m; ++i)
cin >> b[i].h >> b[i].p >> b[i].q;
sort(b.begin(), b.end(), cmp);
for (int i = 0; i < m; ++i) {
if (a == b[i].p)
a = b[i].q;
else if (a == b[i].q)
a = b[i].p;
}
cout << a << endl;
}
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p01126 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct Bridge {
int p, q;
};
int n, m, a;
vector<vector<Bridge>> bvec;
void solve() {
for (int i = 1000 - 1; i >= 0; i--) {
for (int j = 0; j < (int)bvec[i].size(); i++) {
Bridge br = bvec[i][j];
if (br.p == a) {
a = br.q;
break;
} else if (br.q == a) {
a = br.p;
break;
}
}
}
cout << a << endl;
}
int main() {
while (1) {
cin >> n >> m >> a;
if (n == 0)
break;
bvec.assign(1000, vector<Bridge>());
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
bvec[h - 1].push_back((Bridge){p, q});
}
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct Bridge {
int p, q;
};
int n, m, a;
vector<vector<Bridge>> bvec;
void solve() {
for (int i = 1000 - 1; i >= 0; i--) {
for (int j = 0; j < (int)bvec[i].size(); j++) {
Bridge br = bvec[i][j];
if (br.p == a) {
a = br.q;
break;
} else if (br.q == a) {
a = br.p;
break;
}
}
}
cout << a << endl;
}
int main() {
while (1) {
cin >> n >> m >> a;
if (n == 0)
break;
bvec.assign(1000, vector<Bridge>());
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
bvec[h - 1].push_back((Bridge){p, q});
}
solve();
}
return 0;
} | replace | 13 | 14 | 13 | 14 | TLE | |
p01126 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a;
while (cin >> n >> m >> a, n || m || a) {
--a;
int kuji[1000][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 1000; j++)
kuji[j][i] = i;
}
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
--h, --p, --q;
kuji[h][p] = q;
kuji[h][q] = p;
}
for (int i = 1000; i >= 0; i--) {
a = kuji[i][a];
}
cout << a + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a;
while (cin >> n >> m >> a, n || m || a) {
--a;
int kuji[1000][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 1000; j++)
kuji[j][i] = i;
}
for (int i = 0; i < m; i++) {
int h, p, q;
cin >> h >> p >> q;
--h, --p, --q;
kuji[h][p] = q;
kuji[h][q] = p;
}
for (int i = 999; i >= 0; i--) {
a = kuji[i][a];
}
cout << a + 1 << endl;
}
return 0;
} | replace | 20 | 21 | 20 | 21 | -11 | |
p01126 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int n, m, a;
int memo[1005][105] = {0};
int main() {
int b, i, j = 0, h, p, q;
while (1) {
cin >> n >> m >> a;
if (n + m + a == 0)
break;
for (b = 0; b < m; b++) {
cin >> h >> p >> q;
memo[h][p] = q;
memo[h][q] = p;
if (j < h)
j = h;
}
for (i = j; i > 0; i--) {
// cout <<" "<< i << " "<<memo[i][a] <<" "<<a <<endl;
if (memo[i][a])
a = memo[i][a];
}
cout << a << endl;
for (h = 1; h <= j; i++)
for (i = 1; i <= n; i++)
memo[h][i] = 0;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, m, a;
int memo[1005][105] = {0};
int main() {
int b, i, j = 0, h, p, q;
while (1) {
cin >> n >> m >> a;
if (n + m + a == 0)
break;
for (b = 0; b < m; b++) {
cin >> h >> p >> q;
memo[h][p] = q;
memo[h][q] = p;
if (j < h)
j = h;
}
for (i = j; i > 0; i--) {
// cout <<" "<< i << " "<<memo[i][a] <<" "<<a <<endl;
if (memo[i][a])
a = memo[i][a];
}
cout << a << endl;
for (h = 1; h <= j; h++)
for (i = 1; i <= n; i++)
memo[h][i] = 0;
}
return 0;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p01127 | C++ | Time Limit Exceeded | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 110
bool solve() {
int h, w;
char c[SIZE][SIZE];
string s;
bool f[26] = {};
scanf("%d%d", &h, &w);
if (h == 0)
return false;
for (int i = 0; i < h; i++) {
scanf("%s", c[i]);
for (int j = 0; j < w; j++) {
if (f[c[i][j] - 'A'] == false) {
f[c[i][j] - 'A'] = true;
s += c[i][j];
}
}
}
sort(s.begin(), s.end());
do {
char copy_c[SIZE][SIZE];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
copy_c[i][j] = c[i][j];
}
}
bool check = true;
for (int p = 0; p < s.size(); p++) {
int min_h = INF, max_h = -1, min_w = INF, max_w = -1;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (copy_c[i][j] == s[p]) {
min_h = min(min_h, i);
max_h = max(max_h, i);
min_w = min(min_w, j);
max_w = max(max_w, j);
}
}
}
for (int i = min_h; i <= max_h; i++) {
for (int j = min_w; j <= max_w; j++) {
if (copy_c[i][j] != s[p] && copy_c[i][j] != '#')
check = false;
copy_c[i][j] = '#';
}
}
}
if (check) {
puts("SAFE");
return true;
}
} while (next_permutation(s.begin(), s.end()));
puts("SUSPICIOUS");
return true;
}
int main() {
int t;
scanf("%d", &t);
while (t--)
solve();
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 110
bool solve() {
int h, w;
char c[SIZE][SIZE];
string s;
bool f[26] = {};
scanf("%d%d", &h, &w);
if (h == 0)
return false;
for (int i = 0; i < h; i++) {
scanf("%s", c[i]);
for (int j = 0; j < w; j++) {
if (c[i][j] != '.' && f[c[i][j] - 'A'] == false) {
f[c[i][j] - 'A'] = true;
s += c[i][j];
}
}
}
sort(s.begin(), s.end());
do {
char copy_c[SIZE][SIZE];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
copy_c[i][j] = c[i][j];
}
}
bool check = true;
for (int p = 0; p < s.size(); p++) {
int min_h = INF, max_h = -1, min_w = INF, max_w = -1;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (copy_c[i][j] == s[p]) {
min_h = min(min_h, i);
max_h = max(max_h, i);
min_w = min(min_w, j);
max_w = max(max_w, j);
}
}
}
for (int i = min_h; i <= max_h; i++) {
for (int j = min_w; j <= max_w; j++) {
if (copy_c[i][j] != s[p] && copy_c[i][j] != '#')
check = false;
copy_c[i][j] = '#';
}
}
}
if (check) {
puts("SAFE");
return true;
}
} while (next_permutation(s.begin(), s.end()));
puts("SUSPICIOUS");
return true;
}
int main() {
int t;
scanf("%d", &t);
while (t--)
solve();
return 0;
} | replace | 42 | 43 | 42 | 43 | TLE | |
p01127 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
while (n--) {
int w, h;
cin >> w >> h;
vector<string> B(h);
loop(h, i) cin >> B[i];
unordered_set<char> alphs;
loop(h, i) loop(w, j) {
char c = B[i][j];
if (c != '.')
alphs.insert(c);
}
vector<char> perm(all(alphs));
sort(all(perm));
int safe = 0;
do {
map<char, int> layer = {{'.', 0}};
loop(perm.size(), i) layer[perm[i]] = i + 1;
for (char c : perm) {
int l = 100, r = 0, t = 100, b = 0;
loop(h, i) loop(w, j) if (B[i][j] == c) {
l = min(j, l);
r = max(j, r);
t = min(i, t);
b = max(i, b);
}
for (int i = t; i <= b; i++) {
for (int j = l; j <= r; j++) {
if (layer[B[i][j]] < layer[c])
goto NG;
}
}
}
safe = 1;
break;
NG:
continue;
} while (next_permutation(all(perm)));
if (safe)
cout << "SAFE" << endl;
else
cout << "SUSPICIOUS" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
while (n--) {
int h, w;
cin >> h >> w;
vector<string> B(h);
loop(h, i) cin >> B[i];
unordered_set<char> alphs;
loop(h, i) loop(w, j) {
char c = B[i][j];
if (c != '.')
alphs.insert(c);
}
vector<char> perm(all(alphs));
sort(all(perm));
int safe = 0;
do {
map<char, int> layer = {{'.', 0}};
loop(perm.size(), i) layer[perm[i]] = i + 1;
for (char c : perm) {
int l = 100, r = 0, t = 100, b = 0;
loop(h, i) loop(w, j) if (B[i][j] == c) {
l = min(j, l);
r = max(j, r);
t = min(i, t);
b = max(i, b);
}
for (int i = t; i <= b; i++) {
for (int j = l; j <= r; j++) {
if (layer[B[i][j]] < layer[c])
goto NG;
}
}
}
safe = 1;
break;
NG:
continue;
} while (next_permutation(all(perm)));
if (safe)
cout << "SAFE" << endl;
else
cout << "SUSPICIOUS" << endl;
}
return 0;
} | replace | 14 | 16 | 14 | 16 | TLE | |
p01127 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int h, w;
bool ans;
void debug(vector<string> s) {
cout << "[debug]" << endl;
for (int y = 0; y < h; y++) {
cout << s[y] << endl;
}
cout << endl;
}
// ツ債カツ湘」ツづ?右ツ可コツづ個催?標ツづーツ陛板つキ
pair<P, P> get_size(const vector<string> &s, char c) {
int max_x = 0, max_y = 0, min_x = 1e+8, min_y = 1e+8;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (s[y][x] == c) {
max_x = max(max_x, x);
max_y = max(max_y, y);
min_x = min(min_x, x);
min_y = min(min_y, y);
}
}
}
return pair<P, P>(P(min_x, min_y), P(max_x, max_y));
}
// ツ陳キツ陛サツ形ツつゥツ陳イツづ猟づゥ
bool is_rect(const vector<string> &s, char c) {
pair<P, P> pp = get_size(s, c);
int min_x = pp.first.first;
int min_y = pp.first.second;
int max_x = pp.second.first;
int max_y = pp.second.second;
// cout << "char c : " << c << " (" << min_x << "," << min_y << ") , (" <<
// max_x << "," << max_y << ")" << endl;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (min_x <= x && min_y <= y && x <= max_x && y <= max_y) {
if (s[y][x] == c || s[y][x] == '*') {
} else {
return false;
}
} else {
if (s[y][x] == c)
return false;
}
}
}
return true;
}
// ツ嘉猟閉ィツづーツ偲ヲツづィツ渉慊つュ
vector<string> remove(vector<string> s, char c) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (s[y][x] == c) {
s[y][x] = '*';
}
}
}
return s;
}
// memo[i] : iツ氾板姪堋づ個嘉猟閉ィツづーツ陳イツづ猟つスツつゥツづ?つ、ツつゥ,
// vc[i] : iツ氾板姪堋づ個嘉猟閉ィツづーツ表ツつキツ閉カツ篠? s :
// w*hツづ個湘ウツ妥? cnt : ツ偲ヲツづィツ渉慊つ「ツつスツ嘉猟閉ィツづ個青?
void solve(vector<bool> memo, vector<char> vc, vector<string> s, int cnt) {
if (ans)
return;
if (cnt == vc.size()) {
ans = true;
return;
}
for (int i = 0; i < vc.size(); i++) {
if (memo[i])
continue;
// debug( s );
char c = vc[i];
if (is_rect(s, c)) {
memo[i] = true;
s = remove(s, c);
// debug( s );
solve(memo, vc, s, cnt + 1);
memo[i] = false;
}
}
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
cin >> w >> h;
vector<string> s;
for (int y = 0; y < h; y++) {
string s_;
cin >> s_;
s.push_back(s_);
}
int f[256] = {0};
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
char c = s[y][x];
if (c >= 'A' && c <= 'Z') {
f[c] = 1;
}
}
}
vector<char> vc;
for (char c = 'A'; c <= 'Z'; c++) {
if (f[c]) {
vc.push_back(c);
}
}
// debug( s );
if (vc.size() == 0) {
cout << "SAFE" << endl;
} else {
ans = false;
vector<bool> memo((int)vc.size(), false);
solve(memo, vc, s, 0);
if (ans) {
cout << "SAFE" << endl;
} else {
cout << "SUSPICIOUS" << endl;
}
}
}
} | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int h, w;
bool ans;
void debug(vector<string> s) {
cout << "[debug]" << endl;
for (int y = 0; y < h; y++) {
cout << s[y] << endl;
}
cout << endl;
}
// ツ債カツ湘」ツづ?右ツ可コツづ個催?標ツづーツ陛板つキ
pair<P, P> get_size(const vector<string> &s, char c) {
int max_x = 0, max_y = 0, min_x = 1e+8, min_y = 1e+8;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (s[y][x] == c) {
max_x = max(max_x, x);
max_y = max(max_y, y);
min_x = min(min_x, x);
min_y = min(min_y, y);
}
}
}
return pair<P, P>(P(min_x, min_y), P(max_x, max_y));
}
// ツ陳キツ陛サツ形ツつゥツ陳イツづ猟づゥ
bool is_rect(const vector<string> &s, char c) {
pair<P, P> pp = get_size(s, c);
int min_x = pp.first.first;
int min_y = pp.first.second;
int max_x = pp.second.first;
int max_y = pp.second.second;
// cout << "char c : " << c << " (" << min_x << "," << min_y << ") , (" <<
// max_x << "," << max_y << ")" << endl;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (min_x <= x && min_y <= y && x <= max_x && y <= max_y) {
if (s[y][x] == c || s[y][x] == '*') {
} else {
return false;
}
} else {
if (s[y][x] == c)
return false;
}
}
}
return true;
}
// ツ嘉猟閉ィツづーツ偲ヲツづィツ渉慊つュ
vector<string> remove(vector<string> s, char c) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (s[y][x] == c) {
s[y][x] = '*';
}
}
}
return s;
}
// memo[i] : iツ氾板姪堋づ個嘉猟閉ィツづーツ陳イツづ猟つスツつゥツづ?つ、ツつゥ,
// vc[i] : iツ氾板姪堋づ個嘉猟閉ィツづーツ表ツつキツ閉カツ篠? s :
// w*hツづ個湘ウツ妥? cnt : ツ偲ヲツづィツ渉慊つ「ツつスツ嘉猟閉ィツづ個青?
void solve(vector<bool> memo, vector<char> vc, vector<string> s, int cnt) {
if (ans)
return;
if (cnt == vc.size()) {
ans = true;
return;
}
for (int i = 0; i < vc.size(); i++) {
if (memo[i])
continue;
// debug( s );
char c = vc[i];
if (is_rect(s, c)) {
memo[i] = true;
s = remove(s, c);
// debug( s );
solve(memo, vc, s, cnt + 1);
memo[i] = false;
}
}
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
cin >> h >> w;
vector<string> s;
for (int y = 0; y < h; y++) {
string s_;
cin >> s_;
s.push_back(s_);
}
int f[256] = {0};
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
char c = s[y][x];
if (c >= 'A' && c <= 'Z') {
f[c] = 1;
}
}
}
vector<char> vc;
for (char c = 'A'; c <= 'Z'; c++) {
if (f[c]) {
vc.push_back(c);
}
}
// debug( s );
if (vc.size() == 0) {
cout << "SAFE" << endl;
} else {
ans = false;
vector<bool> memo((int)vc.size(), false);
solve(memo, vc, s, 0);
if (ans) {
cout << "SAFE" << endl;
} else {
cout << "SUSPICIOUS" << endl;
}
}
}
} | replace | 102 | 103 | 102 | 103 | 0 | |
p01128 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <iostream>
#include <utility>
#include <vector>
#define X real()
#define Y imag()
#define EPS (1e-10)
using namespace std;
typedef complex<double> P;
typedef pair<P, P> L;
namespace std {
bool operator<(const P &a, const P &b) {
return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std
double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }
double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }
P intersection(L a, L b) {
//??´???a??¨??´???b?????????
return a.first + cross(b.second - b.first, a.first - b.first) /
(-cross(b.second - b.first, a.second - b.first) +
cross(b.second - b.first, a.first - b.first)) *
(a.second - a.first);
}
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > EPS)
return +1;
if (cross(b, c) < -EPS)
return -1;
if (dot(b, c) < 0)
return +2;
if (abs(b - a) + EPS < abs(c - a))
return -2;
return 0;
}
bool is_cross(L a, L b) {
if (ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second) <= 0 &&
ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second) <= 0)
return true;
return false;
}
int main() {
int N;
cin >> N;
double x_s, y_s, x_t, y_t;
for (int i = 0; i < N; ++i) {
cin >> x_s >> y_s >> x_t >> y_t;
P a = P(x_s, y_s), b = P(x_t, y_t);
L S = L(a, b);
int n, o, l;
cin >> n;
vector<pair<P, int>> cp;
for (int i = 0; i < n; ++i) {
cin >> x_s >> y_s >> x_t >> y_t >> o >> l;
L T = L(P(x_s, y_s), P(x_t, y_t));
if (is_cross(S, T))
cp.push_back(make_pair(intersection(S, T), o ^ l));
}
sort(cp.begin(), cp.end());
int t = cp[0].second, ans = 0;
for (int i = 1; i < (int)cp.size(); ++i) {
if (t != cp[i].second) {
++ans;
t = cp[i].second;
}
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <complex>
#include <iostream>
#include <utility>
#include <vector>
#define X real()
#define Y imag()
#define EPS (1e-10)
using namespace std;
typedef complex<double> P;
typedef pair<P, P> L;
namespace std {
bool operator<(const P &a, const P &b) {
return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std
double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }
double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }
P intersection(L a, L b) {
//??´???a??¨??´???b?????????
return a.first + cross(b.second - b.first, a.first - b.first) /
(-cross(b.second - b.first, a.second - b.first) +
cross(b.second - b.first, a.first - b.first)) *
(a.second - a.first);
}
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > EPS)
return +1;
if (cross(b, c) < -EPS)
return -1;
if (dot(b, c) < 0)
return +2;
if (abs(b - a) + EPS < abs(c - a))
return -2;
return 0;
}
bool is_cross(L a, L b) {
if (ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second) <= 0 &&
ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second) <= 0)
return true;
return false;
}
int main() {
int N;
cin >> N;
double x_s, y_s, x_t, y_t;
for (int i = 0; i < N; ++i) {
cin >> x_s >> y_s >> x_t >> y_t;
P a = P(x_s, y_s), b = P(x_t, y_t);
L S = L(a, b);
int n, o, l;
cin >> n;
vector<pair<P, int>> cp;
for (int i = 0; i < n; ++i) {
cin >> x_s >> y_s >> x_t >> y_t >> o >> l;
L T = L(P(x_s, y_s), P(x_t, y_t));
if (is_cross(S, T))
cp.push_back(make_pair(intersection(S, T), o ^ l));
}
sort(cp.begin(), cp.end());
if (!cp.size()) {
cout << 0 << endl;
continue;
}
int t = cp[0].second, ans = 0;
for (int i = 1; i < (int)cp.size(); ++i) {
if (t != cp[i].second) {
++ans;
t = cp[i].second;
}
}
cout << ans << endl;
}
return 0;
} | insert | 69 | 69 | 69 | 73 | 0 | |
p01128 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cassert>
#include <complex>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
const double EPS = 1e-10;
template <class T> bool eq(const T &a, const T &b) { return abs(a - b) < EPS; }
typedef complex<double> point;
double cross(const point &a, const point &b) { return imag(conj(a) * b); }
double dot(const point &a, const point &b) { return real(conj(a) * b); }
int ccw(point a, point b, point c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0; // a--c--b on line or a----bc
}
typedef array<point, 2> line;
bool intersectSS(const line &s, const line &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;
}
point crosspoint(const line &l, const line &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (eq(A, 0.) && eq(B, 0.))
return m[0]; // same line
if (eq(A, 0.))
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
line read_line() {
line res;
for (auto &p : res) {
int x, y;
cin >> x >> y;
p = point(x, y);
}
return res;
}
int solve() {
line new_road = read_line();
int n;
cin >> n;
typedef tuple<point, bool, bool> pinfo;
vector<pinfo> points;
for (int i = 0; i < n; i++) {
line l = read_line();
bool own, ground;
cin >> own >> ground;
if (intersectSS(new_road, l)) {
points.emplace_back(crosspoint(new_road, l), own, ground);
}
}
// cout << points.size() << endl;
sort(points.begin(), points.end(),
[&new_road](const pinfo &a, const pinfo &b) {
return abs(get<0>(a) - new_road[0]) < abs(get<0>(b) - new_road[0]);
});
bool cur = get<1>(points[0]) ? get<2>(points[0]) : !get<2>(points[0]);
int cnt = 0;
for (int i = 1; i < points.size(); i++) {
if ((get<1>(points[i]) && cur != get<2>(points[i])) ||
(!get<1>(points[i]) && cur == get<2>(points[i]))) {
cur = !cur;
cnt++;
// cout << i << endl;
}
}
return cnt;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << solve() << endl;
}
return 0;
} | #include <algorithm>
#include <array>
#include <cassert>
#include <complex>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
const double EPS = 1e-10;
template <class T> bool eq(const T &a, const T &b) { return abs(a - b) < EPS; }
typedef complex<double> point;
double cross(const point &a, const point &b) { return imag(conj(a) * b); }
double dot(const point &a, const point &b) { return real(conj(a) * b); }
int ccw(point a, point b, point c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0; // a--c--b on line or a----bc
}
typedef array<point, 2> line;
bool intersectSS(const line &s, const line &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;
}
point crosspoint(const line &l, const line &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (eq(A, 0.) && eq(B, 0.))
return m[0]; // same line
if (eq(A, 0.))
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
line read_line() {
line res;
for (auto &p : res) {
int x, y;
cin >> x >> y;
p = point(x, y);
}
return res;
}
int solve() {
line new_road = read_line();
int n;
cin >> n;
typedef tuple<point, bool, bool> pinfo;
vector<pinfo> points;
for (int i = 0; i < n; i++) {
line l = read_line();
bool own, ground;
cin >> own >> ground;
if (intersectSS(new_road, l)) {
points.emplace_back(crosspoint(new_road, l), own, ground);
}
}
// cout << points.size() << endl;
sort(points.begin(), points.end(),
[&new_road](const pinfo &a, const pinfo &b) {
return abs(get<0>(a) - new_road[0]) < abs(get<0>(b) - new_road[0]);
});
if (points.empty())
return 0;
bool cur = get<1>(points[0]) ? get<2>(points[0]) : !get<2>(points[0]);
int cnt = 0;
for (int i = 1; i < points.size(); i++) {
if ((get<1>(points[i]) && cur != get<2>(points[i])) ||
(!get<1>(points[i]) && cur == get<2>(points[i]))) {
cur = !cur;
cnt++;
// cout << i << endl;
}
}
return cnt;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << solve() << endl;
}
return 0;
} | insert | 73 | 73 | 73 | 75 | 0 | |
p01128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e12;
struct L {
P a, b, v;
L() {}
L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
L(double _ax, double _ay, double _bx, double _by)
: L(P(_ax, _ay), P(_bx, _by)) {}
};
double cross(P a, P b) { return imag(conj(a) * b); }
double dot(P a, P b) { return real(conj(a) * b); }
int ccw(P p0, P p1, P p2) {
if (cross(p1 - p0, p2 - p0) > 0)
return +1; // counter-clockwise
if (cross(p1 - p0, p2 - p0) < 0)
return -1; // clockwise
if (dot(p1 - p0, p2 - p0) < 0)
return +2; // online_back
if (dot(p0 - p1, p2 - p1) < 0)
return -2; // online_front
return 0; // on_segment
}
bool intersectSS(L l1, L l2) {
return (ccw(l1.a, l1.b, l2.a) * ccw(l1.a, l1.b, l2.b) <= 0 &&
ccw(l2.a, l2.b, l1.a) * ccw(l2.a, l2.b, l1.b) <= 0);
}
double crosspointSS(L l1, L l2) {
double d1 = abs(cross(l2.v, l1.a - l2.a));
double d2 = abs(cross(l2.v, l1.b - l2.a));
double t = d1 / (d1 + d2);
// return l1.a + t * l1.v;
return t;
}
L readL() {
double xa, ya, xb, yb;
cin >> xa >> ya >> xb >> yb;
return L(xa, ya, xb, yb);
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int T;
cin >> T;
rep(_, T) {
L blue = readL();
int n;
cin >> n;
vector<L> lines(n);
V layer(n);
rep(i, n) {
lines[i] = readL();
int o, l;
cin >> o >> l;
layer[i] = l;
if (o == 0)
layer[i] ^= 1;
}
// rep(i, n) {
// cout << layer[i] << " ";
// }
// cout << endl;
vector<pair<double, int>>
v; // ?????????????????????????????????????????????????????????t??¨?????????????????????
rep(i, n) {
if (!intersectSS(blue, lines[i]))
continue;
v.emplace_back(make_pair(crosspointSS(blue, lines[i]), i));
// printf("%.5f %d\n", v.back().first, v.back().second);
}
sort(all(v));
int ans = 0;
rep(i, v.size() - 1) {
if (layer[v[i].second] != layer[v[i + 1].second]) {
ans++;
}
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e12;
struct L {
P a, b, v;
L() {}
L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
L(double _ax, double _ay, double _bx, double _by)
: L(P(_ax, _ay), P(_bx, _by)) {}
};
double cross(P a, P b) { return imag(conj(a) * b); }
double dot(P a, P b) { return real(conj(a) * b); }
int ccw(P p0, P p1, P p2) {
if (cross(p1 - p0, p2 - p0) > 0)
return +1; // counter-clockwise
if (cross(p1 - p0, p2 - p0) < 0)
return -1; // clockwise
if (dot(p1 - p0, p2 - p0) < 0)
return +2; // online_back
if (dot(p0 - p1, p2 - p1) < 0)
return -2; // online_front
return 0; // on_segment
}
bool intersectSS(L l1, L l2) {
return (ccw(l1.a, l1.b, l2.a) * ccw(l1.a, l1.b, l2.b) <= 0 &&
ccw(l2.a, l2.b, l1.a) * ccw(l2.a, l2.b, l1.b) <= 0);
}
double crosspointSS(L l1, L l2) {
double d1 = abs(cross(l2.v, l1.a - l2.a));
double d2 = abs(cross(l2.v, l1.b - l2.a));
double t = d1 / (d1 + d2);
// return l1.a + t * l1.v;
return t;
}
L readL() {
double xa, ya, xb, yb;
cin >> xa >> ya >> xb >> yb;
return L(xa, ya, xb, yb);
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int T;
cin >> T;
rep(_, T) {
L blue = readL();
int n;
cin >> n;
vector<L> lines(n);
V layer(n);
rep(i, n) {
lines[i] = readL();
int o, l;
cin >> o >> l;
layer[i] = l;
if (o == 0)
layer[i] ^= 1;
}
// rep(i, n) {
// cout << layer[i] << " ";
// }
// cout << endl;
vector<pair<double, int>>
v; // ?????????????????????????????????????????????????????????t??¨?????????????????????
rep(i, n) {
if (!intersectSS(blue, lines[i]))
continue;
v.emplace_back(make_pair(crosspointSS(blue, lines[i]), i));
// printf("%.5f %d\n", v.back().first, v.back().second);
}
sort(all(v));
int ans = 0;
rep(i, (int)v.size() - 1) {
if (layer[v[i].second] != layer[v[i + 1].second]) {
ans++;
}
}
cout << ans << endl;
}
} | replace | 102 | 103 | 102 | 103 | 0 | |
p01128 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef pair<double, int> pdi;
struct point {
int x, y;
};
struct line {
point p, q;
};
int T, N, O[110], L[110];
line A, S[110];
bool intersect(line l1, line l2) {
double ax = l1.p.x, ay = l1.p.y;
double bx = l1.q.x, by = l1.q.y;
double cx = l2.p.x, cy = l2.p.y;
double dx = l2.q.x, dy = l2.q.y;
double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
return tc * td < 0 && ta * tb < 0;
}
double distance(line l, point p) {
double ux = l.q.x - l.p.x;
double uy = l.q.y - l.p.y;
double vx = p.x - l.p.x;
double vy = p.y - l.p.y;
double cross = abs(ux * vy - uy * vx);
double ul = sqrt(ux * ux + uy * uy);
return cross / ul;
}
int main(void) {
cin >> T;
while (T--) {
cin >> A.p.x >> A.p.y >> A.q.x >> A.q.y;
cin >> N;
REP(i, 0, N)
cin >> S[i].p.x >> S[i].p.y >> S[i].q.x >> S[i].q.y >> O[i] >> L[i];
vector<pdi> E;
REP(i, 0, N) if (intersect(A, S[i])) {
double da = distance(S[i], A.p);
double db = distance(S[i], A.q);
double d = da / (da + db);
E.push_back(pdi(d, i));
}
sort(E.begin(), E.end());
vector<int> g;
REP(i, 0, E.size()) {
int k = E[i].second;
g.push_back(O[k] == 1 ? L[k] : (L[k] ^ 1));
}
int ans = 0;
REP(i, 0, g.size() - 1) if (g[i] != g[i + 1]) ans++;
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef pair<double, int> pdi;
struct point {
int x, y;
};
struct line {
point p, q;
};
int T, N, O[110], L[110];
line A, S[110];
bool intersect(line l1, line l2) {
double ax = l1.p.x, ay = l1.p.y;
double bx = l1.q.x, by = l1.q.y;
double cx = l2.p.x, cy = l2.p.y;
double dx = l2.q.x, dy = l2.q.y;
double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
return tc * td < 0 && ta * tb < 0;
}
double distance(line l, point p) {
double ux = l.q.x - l.p.x;
double uy = l.q.y - l.p.y;
double vx = p.x - l.p.x;
double vy = p.y - l.p.y;
double cross = abs(ux * vy - uy * vx);
double ul = sqrt(ux * ux + uy * uy);
return cross / ul;
}
int main(void) {
cin >> T;
while (T--) {
cin >> A.p.x >> A.p.y >> A.q.x >> A.q.y;
cin >> N;
REP(i, 0, N)
cin >> S[i].p.x >> S[i].p.y >> S[i].q.x >> S[i].q.y >> O[i] >> L[i];
vector<pdi> E;
REP(i, 0, N) if (intersect(A, S[i])) {
double da = distance(S[i], A.p);
double db = distance(S[i], A.q);
double d = da / (da + db);
E.push_back(pdi(d, i));
}
sort(E.begin(), E.end());
vector<int> g;
REP(i, 0, E.size()) {
int k = E[i].second;
g.push_back(O[k] == 1 ? L[k] : (L[k] ^ 1));
}
int ans = 0;
REP(i, 1, (g.size())) if (g[i - 1] != g[i]) ans++;
cout << ans << endl;
}
return 0;
} | replace | 65 | 66 | 65 | 66 | 0 | |
p01128 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstdio>
#include <vector>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef complex<double> Point;
const double EPS = 1e-9;
class Line : public vector<Point> {
public:
Line() {}
Line(const Point &a, const Point &b) { pb(a), pb(b); }
};
class Segment : public Line {
public:
Segment() {}
Segment(const Point &a, const Point &b) : Line(a, b) {}
};
double dot(const Point &a, const Point &b) {
return real(a) * real(b) + imag(a) * imag(b);
}
double cross(const Point &a, const Point &b) {
return real(a) * imag(b) - imag(a) * real(b);
}
enum { CCW = 1, CW = -1, ON = 0 };
int ccw(const Point &a, Point b, Point c) {
b -= a, c -= a;
double rotdir = cross(b, c);
if (rotdir > EPS)
return CCW;
if (rotdir < -EPS)
return CW;
return ON;
}
inline void calc_abc(const Line &l, double &a, double &b,
double &c) { // l : ax+by+c=0
a = imag(l[0]) - imag(l[1]);
b = real(l[1]) - real(l[0]);
c = cross(l[0], l[1]);
}
bool intersect(const Segment &s, const Segment &t, Point *p = NULL) {
if (max(real(s[0]), real(s[1])) < min(real(t[0]), real(t[1])) - EPS ||
max(real(t[0]), real(t[1])) < min(real(s[0]), real(s[1])) - EPS ||
max(imag(s[0]), imag(s[1])) < min(imag(t[0]), imag(t[1])) - EPS ||
max(imag(t[0]), imag(t[1])) < min(imag(s[0]), imag(s[1])) - EPS)
return false;
if (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) {
if (p) {
double a1, b1, c1, a2, b2, c2;
calc_abc(s, a1, b1, c1);
calc_abc(t, a2, b2, c2);
double det = a1 * b2 - a2 * b1;
if (abs(det) < EPS) { // s is parallel to t
Point q[3] = {s[0], s[1], t[0]};
rep(i, 3) {
if (dot(q[i] - s[0], q[i] - s[1]) < EPS &&
dot(q[i] - t[0], q[i] - t[1]) < EPS) {
*p = q[i];
break;
}
}
} else
*p = Point(b1 * c2 - b2 * c1, a2 * c1 - a1 * c2) / det;
}
return true;
}
return false;
}
int n;
Point A, B;
Segment AB, S[100];
bool own[100], loc[100];
int solve() {
vector<pair<double, int>> pts;
rep(i, n) {
Point Q;
if (intersect(AB, S[i], &Q))
pts.pb(mp(abs(A - Q), i));
}
sort(pts.begin(), pts.end());
int cnt = 0, id = pts[0].second;
bool now = (own[id] ? loc[id] : !loc[id]);
for (int i = 1; i < pts.size(); i++) {
id = pts[i].second;
if (own[id]) {
if (now != loc[id]) {
cnt++;
now = !now;
}
} else {
if (now == loc[id]) {
cnt++;
now = !now;
}
}
}
return cnt;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int xa, ya, xb, yb;
scanf("%d%d%d%d%d", &xa, &ya, &xb, &yb, &n);
A = Point(xa, ya);
B = Point(xb, yb);
AB = Segment(A, B);
rep(i, n) {
int x1, y1, x2, y2, o, l;
scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &o, &l);
S[i] = Segment(Point(x1, y1), Point(x2, y2));
own[i] = o;
loc[i] = l;
}
printf("%d\n", solve());
}
return 0;
} | #include <algorithm>
#include <complex>
#include <cstdio>
#include <vector>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef complex<double> Point;
const double EPS = 1e-9;
class Line : public vector<Point> {
public:
Line() {}
Line(const Point &a, const Point &b) { pb(a), pb(b); }
};
class Segment : public Line {
public:
Segment() {}
Segment(const Point &a, const Point &b) : Line(a, b) {}
};
double dot(const Point &a, const Point &b) {
return real(a) * real(b) + imag(a) * imag(b);
}
double cross(const Point &a, const Point &b) {
return real(a) * imag(b) - imag(a) * real(b);
}
enum { CCW = 1, CW = -1, ON = 0 };
int ccw(const Point &a, Point b, Point c) {
b -= a, c -= a;
double rotdir = cross(b, c);
if (rotdir > EPS)
return CCW;
if (rotdir < -EPS)
return CW;
return ON;
}
inline void calc_abc(const Line &l, double &a, double &b,
double &c) { // l : ax+by+c=0
a = imag(l[0]) - imag(l[1]);
b = real(l[1]) - real(l[0]);
c = cross(l[0], l[1]);
}
bool intersect(const Segment &s, const Segment &t, Point *p = NULL) {
if (max(real(s[0]), real(s[1])) < min(real(t[0]), real(t[1])) - EPS ||
max(real(t[0]), real(t[1])) < min(real(s[0]), real(s[1])) - EPS ||
max(imag(s[0]), imag(s[1])) < min(imag(t[0]), imag(t[1])) - EPS ||
max(imag(t[0]), imag(t[1])) < min(imag(s[0]), imag(s[1])) - EPS)
return false;
if (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) {
if (p) {
double a1, b1, c1, a2, b2, c2;
calc_abc(s, a1, b1, c1);
calc_abc(t, a2, b2, c2);
double det = a1 * b2 - a2 * b1;
if (abs(det) < EPS) { // s is parallel to t
Point q[3] = {s[0], s[1], t[0]};
rep(i, 3) {
if (dot(q[i] - s[0], q[i] - s[1]) < EPS &&
dot(q[i] - t[0], q[i] - t[1]) < EPS) {
*p = q[i];
break;
}
}
} else
*p = Point(b1 * c2 - b2 * c1, a2 * c1 - a1 * c2) / det;
}
return true;
}
return false;
}
int n;
Point A, B;
Segment AB, S[100];
bool own[100], loc[100];
int solve() {
vector<pair<double, int>> pts;
rep(i, n) {
Point Q;
if (intersect(AB, S[i], &Q))
pts.pb(mp(abs(A - Q), i));
}
if (pts.size() == 0)
return 0;
sort(pts.begin(), pts.end());
int cnt = 0, id = pts[0].second;
bool now = (own[id] ? loc[id] : !loc[id]);
for (int i = 1; i < pts.size(); i++) {
id = pts[i].second;
if (own[id]) {
if (now != loc[id]) {
cnt++;
now = !now;
}
} else {
if (now == loc[id]) {
cnt++;
now = !now;
}
}
}
return cnt;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int xa, ya, xb, yb;
scanf("%d%d%d%d%d", &xa, &ya, &xb, &yb, &n);
A = Point(xa, ya);
B = Point(xb, yb);
AB = Segment(A, B);
rep(i, n) {
int x1, y1, x2, y2, o, l;
scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &o, &l);
S[i] = Segment(Point(x1, y1), Point(x2, y2));
own[i] = o;
loc[i] = l;
}
printf("%d\n", solve());
}
return 0;
} | insert | 96 | 96 | 96 | 98 | 0 | |
p01128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
// ???/????????????
struct Point {
double x, y;
Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(x * a, y * a); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
// ??????/??´???
struct Segment {
Point p1, p2;
};
typedef Segment Line;
// ????????????????????????
double norm(Vector v) { return v.x * v.x + v.y * v.y; }
// ?????????????????§??????
double abs(Vector v) { return sqrt(norm(v)); }
// ?????????????????????
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
// ??????????????????????????§??????
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
// ??´?????????
bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); }
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
bool isOrthogonal(Segment s1, Segment s2) {
return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
// ????????????
bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); }
bool isParallel(Point a1, Point a2, Point b1, Point b2) {
return isParallel(a1 - a2, b1 - b2);
}
bool isParallel(Segment s1, Segment s2) {
return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
// ?°???±
Point project(Segment s, Point p) {
Vector base = s.p2 - s.p1;
double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
// ????°?
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
// ???????¨???????
int ccw(Point p0, Point p1, Point p2) {
Vector a = p1 - p0;
Vector b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
// ????????????
bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
// ?????????????????¢
double getDistance(Point a, Point b) { return abs(a - b); }
// ??´?????¨?????¨????????¢
double getDistanceLP(Line l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
// ????????¨?????¨????????¢
double getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return abs(p - s.p2);
return getDistanceLP(s, p);
}
// ????????????????????¢
double getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
// ???????????????
Point getCrossPoint(Segment s1, Segment s2) {
Vector base = s2.p2 - s2.p1;
double d1 = abs(cross(base, s1.p1 - s2.p1));
double d2 = abs(cross(base, s1.p2 - s2.p1));
double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
typedef pair<double, int> P;
int main() {
int T;
cin >> T;
while (T--) {
Segment ab;
cin >> ab.p1.x >> ab.p1.y >> ab.p2.x >> ab.p2.y;
int n;
cin >> n;
vector<Segment> s(n);
vector<int> o(n), l(n);
for (int i = 0; i < n; i++) {
cin >> s[i].p1.x >> s[i].p1.y >> s[i].p2.x >> s[i].p2.y >> o[i] >> l[i];
}
vector<P> isct_s;
for (int i = 0; i < n; i++) {
if (!intersect(ab, s[i]) || isParallel(ab, s[i]))
continue;
double dist = getDistance(ab.p1, getCrossPoint(ab, s[i]));
isct_s.push_back(P(dist, i));
}
sort(isct_s.begin(), isct_s.end());
int level =
(o[isct_s[0].second] ? l[isct_s[0].second] : !l[isct_s[0].second]);
int ans = 0;
for (int i = 1; i < isct_s.size(); i++) {
if (o[isct_s[i].second] == 1 && level != l[isct_s[i].second] ||
o[isct_s[i].second] == 0 && level == l[isct_s[i].second])
ans++, level = !level;
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
// ???/????????????
struct Point {
double x, y;
Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(x * a, y * a); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
// ??????/??´???
struct Segment {
Point p1, p2;
};
typedef Segment Line;
// ????????????????????????
double norm(Vector v) { return v.x * v.x + v.y * v.y; }
// ?????????????????§??????
double abs(Vector v) { return sqrt(norm(v)); }
// ?????????????????????
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
// ??????????????????????????§??????
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
// ??´?????????
bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); }
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
bool isOrthogonal(Segment s1, Segment s2) {
return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
// ????????????
bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); }
bool isParallel(Point a1, Point a2, Point b1, Point b2) {
return isParallel(a1 - a2, b1 - b2);
}
bool isParallel(Segment s1, Segment s2) {
return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
// ?°???±
Point project(Segment s, Point p) {
Vector base = s.p2 - s.p1;
double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
// ????°?
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
// ???????¨???????
int ccw(Point p0, Point p1, Point p2) {
Vector a = p1 - p0;
Vector b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
// ????????????
bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
// ?????????????????¢
double getDistance(Point a, Point b) { return abs(a - b); }
// ??´?????¨?????¨????????¢
double getDistanceLP(Line l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
// ????????¨?????¨????????¢
double getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return abs(p - s.p2);
return getDistanceLP(s, p);
}
// ????????????????????¢
double getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
// ???????????????
Point getCrossPoint(Segment s1, Segment s2) {
Vector base = s2.p2 - s2.p1;
double d1 = abs(cross(base, s1.p1 - s2.p1));
double d2 = abs(cross(base, s1.p2 - s2.p1));
double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
typedef pair<double, int> P;
int main() {
int T;
cin >> T;
while (T--) {
Segment ab;
cin >> ab.p1.x >> ab.p1.y >> ab.p2.x >> ab.p2.y;
int n;
cin >> n;
vector<Segment> s(n);
vector<int> o(n), l(n);
for (int i = 0; i < n; i++) {
cin >> s[i].p1.x >> s[i].p1.y >> s[i].p2.x >> s[i].p2.y >> o[i] >> l[i];
}
vector<P> isct_s;
for (int i = 0; i < n; i++) {
if (!intersect(ab, s[i]) || isParallel(ab, s[i]))
continue;
double dist = getDistance(ab.p1, getCrossPoint(ab, s[i]));
isct_s.push_back(P(dist, i));
}
sort(isct_s.begin(), isct_s.end());
if (isct_s.empty()) {
cout << 0 << endl;
continue;
}
int level =
(o[isct_s[0].second] ? l[isct_s[0].second] : !l[isct_s[0].second]);
int ans = 0;
for (int i = 1; i < isct_s.size(); i++) {
if (o[isct_s[i].second] == 1 && level != l[isct_s[i].second] ||
o[isct_s[i].second] == 0 && level == l[isct_s[i].second])
ans++, level = !level;
}
cout << ans << endl;
}
return 0;
} | insert | 148 | 148 | 148 | 153 | 0 | |
p01128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
const double EPS = 1e-8;
const double INF = 1e12;
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
double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }
struct L : public vector<P> {
L() {}
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0;
}
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;
}
P crosspoint(const L &l, const L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
if (abs(A) < EPS)
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
L ab;
int n;
L st[100];
int o[100], l[100];
void init() {
double x, y;
cin >> x >> y;
P a(x, y);
cin >> x >> y;
P b(x, y);
ab = L(a, b);
cin >> n;
rep(i, 0, n) {
cin >> x >> y;
P s(x, y);
cin >> x >> y;
P t(x, y);
st[i] = L(s, t);
cin >> o[i] >> l[i];
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int dn;
cin >> dn;
rep(_dn, 0, dn) {
init();
vector<pair<double, int>> v;
rep(i, 0, n) {
if (!intersectSS(ab, st[i]))
continue;
P c = crosspoint(ab, st[i]);
double d = abs(c - ab[0]);
int p;
if (o[i] == 0)
p = 1 - l[i];
else
p = l[i];
v.push_back(make_pair(d, p));
}
sort(v.begin(), v.end());
int ans = 0;
rep(i, 0, v.size() - 1) {
if (v[i].second != v[i + 1].second)
ans++;
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
const double EPS = 1e-8;
const double INF = 1e12;
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
double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }
struct L : public vector<P> {
L() {}
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0;
}
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;
}
P crosspoint(const L &l, const L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
if (abs(A) < EPS)
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
L ab;
int n;
L st[100];
int o[100], l[100];
void init() {
double x, y;
cin >> x >> y;
P a(x, y);
cin >> x >> y;
P b(x, y);
ab = L(a, b);
cin >> n;
rep(i, 0, n) {
cin >> x >> y;
P s(x, y);
cin >> x >> y;
P t(x, y);
st[i] = L(s, t);
cin >> o[i] >> l[i];
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int dn;
cin >> dn;
rep(_dn, 0, dn) {
init();
vector<pair<double, int>> v;
rep(i, 0, n) {
if (!intersectSS(ab, st[i]))
continue;
P c = crosspoint(ab, st[i]);
double d = abs(c - ab[0]);
int p;
if (o[i] == 0)
p = 1 - l[i];
else
p = l[i];
v.push_back(make_pair(d, p));
}
if (v.size() == 0) {
cout << 0 << endl;
continue;
}
sort(v.begin(), v.end());
int ans = 0;
rep(i, 0, v.size() - 1) {
if (v[i].second != v[i + 1].second)
ans++;
}
cout << ans << endl;
}
} | insert | 104 | 104 | 104 | 109 | 0 | |
p01128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r), end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define vvl(v, w, h, init) vector<vector<ll>> v(w, vector<ll>(h, init))
#define mp(a, b) make_pair(a, b)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P; //????´???°????????¢?????????????????¨?§£???
namespace std {
bool operator<(const P &a, const P &b) { // x????????????
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool sorty(const P &a, const P &b) { // y????????????
return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool same(const P &a, const P &b) {
P p = a - b;
if (abs(real(p)) < EPS && abs(imag(p)) < EPS) {
return true;
}
return false;
}
} // namespace std
double cross(const P &a, const P &b) { //??????
return imag(conj(a) * b);
}
double dot(const P &a, const P &b) { //??????
return real(conj(a) * b);
}
class L { // line
public:
vector<P> l;
P v;
L(){};
L(const P &a, const P &b) {
l.push_back(a);
l.push_back(b);
v = (b - a);
}
L(double a, double b, double c, double d) {
l.push_back(P(a, b)), l.push_back(P(c, d));
}
P &operator[](const int i) { return l[i]; }
void readL() {
double a, b, c, d;
cin >> a >> b >> c >> d;
l.clear();
l.push_back(P(a, b)), l.push_back(P(c, d));
}
};
typedef vector<P> G;
G readG(int n) {
double x, y;
G g;
rep(i, n) {
cin >> x >> y;
g.push_back(P(x, y));
}
return g;
}
struct C { //???
P p;
double r;
C(){};
C(const P &p, double r) : p(p), r(r) {}
};
int ccw(P a, P b, P c) { // 3????????????????????§????????§??????????????????
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0; // a--c--b on line
}
int linejudge(L &ab, L &cd) { // 2??´???????????¢???
P a = ab[1] - ab[0], b = cd[1] - cd[0];
if (abs(cross(a, b)) < EPS) { // Parallel
return 2;
} else if (abs(dot(a, b)) < EPS) { // Orthogonal
return 1;
}
return 0;
}
// L:line,S:segment,P:point
bool intersectLL(L &l, L &m) {
return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line
}
bool intersectLS(L &l, L &s) {
return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
cross(l[1] - l[0], s[1] - l[0]) <
EPS; // s[1] is right of l
}
bool intersectLP(L &l, P &p) { return abs(cross(l[1] - p, l[0] - p)) < EPS; }
bool intersectSS(L &s, 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;
}
bool intersectSP(L &s, P &p) {
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
EPS; // triangle inequality
}
// L & P intersection
P projection(L &l, P &p) {
double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
return l[0] + t * (l[0] - l[1]);
}
// L????????????P???????°????
P reflection(L &l, P &p) { return p + 2.0 * (projection(l, p) - p); }
double distanceLP(L &l, P &p) { return abs(p - projection(l, p)); }
double distanceLL(L &l, L &m) {
return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(L &l, L &s) {
if (intersectLS(l, s))
return 0;
return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(L &s, P &p) {
P r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(L &s, L &t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
double distancePP(P &p, P &q) { return abs(p - q); }
P crosspoint(L &l, L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
if (abs(A) < EPS)
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
P verticalvector(P &a, P &b) { // 2???????????????????????????????????????
if (a.real() == b.real()) {
return {1.0, 0};
}
if (a.imag() == b.imag()) {
return {0, 1.0};
}
P p = a - b;
P res = {-p.imag(), p.real()};
return res / abs(p);
}
// a < b : -1, a > b : 1, a == b : 0
inline int sgn(double a, double b = 0) {
return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;
}
P crosspointSS(L &l1, L &l2) {
double d1 = abs(cross(l2.v, l1[0] - l2[0])); // l1.a - l2.b???
double d2 = abs(cross(l2.v, l1[1] - l2[0]));
double t = d1 / (d1 + d2);
return l1[0] + t * l1.v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, x, y, x2, y2;
cin >> n;
int o, h;
rep(i, n) {
cin >> x >> y >> x2 >> y2;
P a(x, y), b(x2, y2);
L l(a, b);
if (b < a)
l = L(b, a);
cin >> m;
vector<pair<P, pair<int, int>>> ab; // a[i](crosspoint,h)
rep(j, m) {
cin >> x >> y >> x2 >> y2;
P a(x, y), b(x2, y2);
L t(a, b);
if (b < a)
t = L(b, a);
cin >> o >> h;
if (intersectSS(l, t)) {
P p = crosspointSS(l, t);
ab.push_back(mp(p, mp(o, h)));
}
}
sort(all(ab));
int s = 0;
if (ab[0].se.se) {
s = ab[0].se.fi;
} else {
s = !ab[0].se.fi;
}
int cnt = 0, u = 1;
REP(u, 1, ab.size()) {
o = ab[u].se.fi, h = ab[u].se.se;
if (o && s != h) {
++cnt;
s = h;
} else if (!o && s == h) {
++cnt;
s = !h;
}
}
cout << cnt << endl;
// ???????????¨??´?????¨????????¨????????????????????????
// ???????§??????¨????????¨?????????????????¢???????°??????????????????????????????°????????¶?????????????????????????????????????????????
// ????????????????????????????????¨??¶?????????????????????h = !h???ans++
// ??????????????¨??¶???????????????
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r), end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define vvl(v, w, h, init) vector<vector<ll>> v(w, vector<ll>(h, init))
#define mp(a, b) make_pair(a, b)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P; //????´???°????????¢?????????????????¨?§£???
namespace std {
bool operator<(const P &a, const P &b) { // x????????????
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool sorty(const P &a, const P &b) { // y????????????
return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool same(const P &a, const P &b) {
P p = a - b;
if (abs(real(p)) < EPS && abs(imag(p)) < EPS) {
return true;
}
return false;
}
} // namespace std
double cross(const P &a, const P &b) { //??????
return imag(conj(a) * b);
}
double dot(const P &a, const P &b) { //??????
return real(conj(a) * b);
}
class L { // line
public:
vector<P> l;
P v;
L(){};
L(const P &a, const P &b) {
l.push_back(a);
l.push_back(b);
v = (b - a);
}
L(double a, double b, double c, double d) {
l.push_back(P(a, b)), l.push_back(P(c, d));
}
P &operator[](const int i) { return l[i]; }
void readL() {
double a, b, c, d;
cin >> a >> b >> c >> d;
l.clear();
l.push_back(P(a, b)), l.push_back(P(c, d));
}
};
typedef vector<P> G;
G readG(int n) {
double x, y;
G g;
rep(i, n) {
cin >> x >> y;
g.push_back(P(x, y));
}
return g;
}
struct C { //???
P p;
double r;
C(){};
C(const P &p, double r) : p(p), r(r) {}
};
int ccw(P a, P b, P c) { // 3????????????????????§????????§??????????????????
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0; // a--c--b on line
}
int linejudge(L &ab, L &cd) { // 2??´???????????¢???
P a = ab[1] - ab[0], b = cd[1] - cd[0];
if (abs(cross(a, b)) < EPS) { // Parallel
return 2;
} else if (abs(dot(a, b)) < EPS) { // Orthogonal
return 1;
}
return 0;
}
// L:line,S:segment,P:point
bool intersectLL(L &l, L &m) {
return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line
}
bool intersectLS(L &l, L &s) {
return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
cross(l[1] - l[0], s[1] - l[0]) <
EPS; // s[1] is right of l
}
bool intersectLP(L &l, P &p) { return abs(cross(l[1] - p, l[0] - p)) < EPS; }
bool intersectSS(L &s, 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;
}
bool intersectSP(L &s, P &p) {
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
EPS; // triangle inequality
}
// L & P intersection
P projection(L &l, P &p) {
double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
return l[0] + t * (l[0] - l[1]);
}
// L????????????P???????°????
P reflection(L &l, P &p) { return p + 2.0 * (projection(l, p) - p); }
double distanceLP(L &l, P &p) { return abs(p - projection(l, p)); }
double distanceLL(L &l, L &m) {
return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(L &l, L &s) {
if (intersectLS(l, s))
return 0;
return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(L &s, P &p) {
P r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(L &s, L &t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
double distancePP(P &p, P &q) { return abs(p - q); }
P crosspoint(L &l, L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
if (abs(A) < EPS)
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
P verticalvector(P &a, P &b) { // 2???????????????????????????????????????
if (a.real() == b.real()) {
return {1.0, 0};
}
if (a.imag() == b.imag()) {
return {0, 1.0};
}
P p = a - b;
P res = {-p.imag(), p.real()};
return res / abs(p);
}
// a < b : -1, a > b : 1, a == b : 0
inline int sgn(double a, double b = 0) {
return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;
}
P crosspointSS(L &l1, L &l2) {
double d1 = abs(cross(l2.v, l1[0] - l2[0])); // l1.a - l2.b???
double d2 = abs(cross(l2.v, l1[1] - l2[0]));
double t = d1 / (d1 + d2);
return l1[0] + t * l1.v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, x, y, x2, y2;
cin >> n;
int o, h;
rep(i, n) {
cin >> x >> y >> x2 >> y2;
P a(x, y), b(x2, y2);
L l(a, b);
if (b < a)
l = L(b, a);
cin >> m;
vector<pair<P, pair<int, int>>> ab; // a[i](crosspoint,h)
rep(j, m) {
cin >> x >> y >> x2 >> y2;
P a(x, y), b(x2, y2);
L t(a, b);
if (b < a)
t = L(b, a);
cin >> o >> h;
if (intersectSS(l, t)) {
P p = crosspointSS(l, t);
ab.push_back(mp(p, mp(o, h)));
}
}
sort(all(ab));
int cnt = 0;
if (ab.size()) {
int s = 0;
if (ab[0].se.se) {
s = ab[0].se.fi;
} else {
s = !ab[0].se.fi;
}
REP(u, 1, ab.size()) {
o = ab[u].se.fi, h = ab[u].se.se;
if (o && s != h) {
++cnt;
s = h;
} else if (!o && s == h) {
++cnt;
s = !h;
}
}
}
cout << cnt << endl;
// ???????????¨??´?????¨????????¨????????????????????????
// ???????§??????¨????????¨?????????????????¢???????°??????????????????????????????°????????¶?????????????????????????????????????????????
// ????????????????????????????????¨??¶?????????????????????h = !h???ans++
// ??????????????¨??¶???????????????
}
return 0;
} | replace | 218 | 233 | 218 | 235 | 0 | |
p01130 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
#define INF 10000001
#define MAX_SIZE 101
long long g_d[MAX_SIZE][MAX_SIZE];
void warshall_floyd(int v) {
for (int k = 0; k < v; ++k) {
for (int i = 0; i < v; ++i) {
for (int j = 0; j < v; ++j) {
g_d[i][j] = min(g_d[i][j], g_d[i][k] + g_d[k][j]);
}
}
}
}
int main() {
freopen("Text.txt", "r", stdin);
while (true) {
int n, m, s, g1, g2;
cin >> n >> m >> s >> g1 >> g2;
--s;
--g1;
--g2;
if (n == 0)
break;
fill(g_d[0], g_d[0] + MAX_SIZE * MAX_SIZE, INF);
for (int i = 0; i < MAX_SIZE; ++i) {
g_d[i][i] = 0;
}
for (int i = 0; i < m; ++i) {
int b1, b2;
cin >> b1 >> b2;
--b1;
--b2;
cin >> g_d[b1][b2];
}
warshall_floyd(n);
long long cost = INF;
for (int i = 0; i < n; ++i) {
cost = min(cost, g_d[s][i] + g_d[i][g1] + g_d[i][g2]);
}
cout << cost << endl;
}
} | #include <algorithm>
#include <iostream>
using namespace std;
#define INF 10000001
#define MAX_SIZE 101
long long g_d[MAX_SIZE][MAX_SIZE];
void warshall_floyd(int v) {
for (int k = 0; k < v; ++k) {
for (int i = 0; i < v; ++i) {
for (int j = 0; j < v; ++j) {
g_d[i][j] = min(g_d[i][j], g_d[i][k] + g_d[k][j]);
}
}
}
}
int main() {
while (true) {
int n, m, s, g1, g2;
cin >> n >> m >> s >> g1 >> g2;
--s;
--g1;
--g2;
if (n == 0)
break;
fill(g_d[0], g_d[0] + MAX_SIZE * MAX_SIZE, INF);
for (int i = 0; i < MAX_SIZE; ++i) {
g_d[i][i] = 0;
}
for (int i = 0; i < m; ++i) {
int b1, b2;
cin >> b1 >> b2;
--b1;
--b2;
cin >> g_d[b1][b2];
}
warshall_floyd(n);
long long cost = INF;
for (int i = 0; i < n; ++i) {
cost = min(cost, g_d[s][i] + g_d[i][g1] + g_d[i][g2]);
}
cout << cost << endl;
}
} | delete | 19 | 20 | 19 | 19 | TLE | |
p01130 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
const int MAX = 100;
const int INF = (1 << 10);
int main() {
int n, m;
int s, g1, g2;
int pipe[MAX][MAX];
while (1) {
scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2);
if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
break;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
pipe[i][j] = INF;
}
pipe[i][i] = 0;
}
for (int i = 0; i < m; i++) {
int b1, b2, c;
scanf("%d%d%d", &b1, &b2, &c);
pipe[b1][b2] = c;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
pipe[j][k] = min(pipe[j][k], pipe[j][i] + pipe[i][k]);
}
}
}
int ans = INF;
for (int i = 1; i <= n; i++) {
ans = min(ans, pipe[s][i] + pipe[i][g1] + pipe[i][g2]);
}
printf("%d\n", ans);
}
} | #include <algorithm>
#include <cstdio>
using namespace std;
const int MAX = 101;
const int INF = (1 << 21);
int main() {
int n, m;
int s, g1, g2;
int pipe[MAX][MAX];
while (1) {
scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2);
if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
break;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
pipe[i][j] = INF;
}
pipe[i][i] = 0;
}
for (int i = 0; i < m; i++) {
int b1, b2, c;
scanf("%d%d%d", &b1, &b2, &c);
pipe[b1][b2] = c;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
pipe[j][k] = min(pipe[j][k], pipe[j][i] + pipe[i][k]);
}
}
}
int ans = INF;
for (int i = 1; i <= n; i++) {
ans = min(ans, pipe[s][i] + pipe[i][g1] + pipe[i][g2]);
}
printf("%d\n", ans);
}
} | replace | 4 | 6 | 4 | 6 | 0 | |
p01130 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T> inline void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
constexpr int MAX_N = 100;
constexpr int INF = (1 << 29);
int dist[MAX_N][MAX_N];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2 && n;) {
--s;
--g1;
--g2;
fill_n((int *)dist, sizeof(dist) / sizeof(int), INF);
for (int i = 0; i < m; ++i) {
int from, to, cost;
cin >> from >> to >> cost;
dist[from - 1][to - 1] = cost;
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
chmin(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
int ans = INF;
for (int i = 0; i < n; ++i) {
chmin(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
}
assert(ans != INF);
cout << ans << endl;
}
return EXIT_SUCCESS;
} | #include <bits/stdc++.h>
using namespace std;
template <class T> inline void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
constexpr int MAX_N = 100;
constexpr int INF = (1 << 29);
int dist[MAX_N][MAX_N];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2 && n;) {
--s;
--g1;
--g2;
fill_n((int *)dist, sizeof(dist) / sizeof(int), INF);
for (int i = 0; i < n; ++i) {
dist[i][i] = 0;
}
for (int i = 0; i < m; ++i) {
int from, to, cost;
cin >> from >> to >> cost;
dist[from - 1][to - 1] = cost;
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
chmin(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
int ans = INF;
for (int i = 0; i < n; ++i) {
chmin(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
}
assert(ans != INF);
cout << ans << endl;
}
return EXIT_SUCCESS;
} | insert | 21 | 21 | 21 | 25 | 0 | |
p01131 | C++ | Runtime Error | #include <stdio.h>
#include <string>
using namespace std;
string table[] = {"", ".,!? ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"};
char str[128];
int main() {
int a;
scanf("%d", &a);
while (a--) {
scanf("%s", str);
int renzoku = 0;
char now = '0';
for (int i = 0; str[i]; i++) {
if (now != str[i]) {
if (now != '0') {
printf("%c",
table[now - '0'][(renzoku - 1) % table[now - '0'].size()]);
}
renzoku = 1;
now = str[i];
} else
renzoku++;
}
printf("\n");
}
} | #include <stdio.h>
#include <string>
using namespace std;
string table[] = {"", ".,!? ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"};
char str[1280];
int main() {
int a;
scanf("%d", &a);
while (a--) {
scanf("%s", str);
int renzoku = 0;
char now = '0';
for (int i = 0; str[i]; i++) {
if (now != str[i]) {
if (now != '0') {
printf("%c",
table[now - '0'][(renzoku - 1) % table[now - '0'].size()]);
}
renzoku = 1;
now = str[i];
} else
renzoku++;
}
printf("\n");
}
} | replace | 5 | 6 | 5 | 6 | 0 | |
p01131 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
char bt[9][8] = {".,!? ", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
int main() {
int N;
for (scanf("%d", &N); N--;) {
char mes[128];
scanf(" %s", mes);
int len = strlen(mes);
int prv = 0, count = 0;
for (int i = 0; i < len; i++) {
if (mes[i] == '0') {
if (prv > 0) {
--prv;
printf("%c", bt[prv][--count % strlen(bt[prv])]);
}
count = 0;
} else {
count++;
}
prv = mes[i] - '0';
}
if (prv > 0) {
--prv;
printf("%c", bt[prv][--count % strlen(bt[prv])]);
}
puts("");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
char bt[9][8] = {".,!? ", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
int main() {
int N;
for (scanf("%d", &N); N--;) {
char mes[1280];
scanf(" %s", mes);
int len = strlen(mes);
int prv = 0, count = 0;
for (int i = 0; i < len; i++) {
if (mes[i] == '0') {
if (prv > 0) {
--prv;
printf("%c", bt[prv][--count % strlen(bt[prv])]);
}
count = 0;
} else {
count++;
}
prv = mes[i] - '0';
}
if (prv > 0) {
--prv;
printf("%c", bt[prv][--count % strlen(bt[prv])]);
}
puts("");
}
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p01131 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string bottan[] = {
"",
".,!? ", // 1
"abc", // 2
"def", // 3
"ghi", // 4
"jkl", // 5
"mno", // 6
"pqrs", // 7
"tuv", // 8
"wxyz", // 9
};
int cnt[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};
cin >> n;
while (n--) {
string str;
cin >> str;
int len = str.size();
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < len; i++) {
if (str[i] == '0') {
if (cnt1 != 0) {
if (cnt2 % cnt[cnt1] == 0) {
cout << bottan[cnt1][cnt[cnt1] - 1];
} else {
cout << bottan[cnt1][cnt2 % cnt[cnt1] - 1];
}
}
cnt1 = 0;
cnt2 = 0;
} else {
if (cnt1 == 0) {
cnt1 = str[i] - '0';
cnt2++;
} else {
cnt2++;
}
}
}
cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string bottan[] = {
"",
".,!? ", // 1
"abc", // 2
"def", // 3
"ghi", // 4
"jkl", // 5
"mno", // 6
"pqrs", // 7
"tuv", // 8
"wxyz", // 9
};
int cnt[] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};
cin >> n;
while (n--) {
string str;
cin >> str;
int len = str.size();
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < len; i++) {
if (str[i] == '0') {
if (cnt1 != 0) {
if (cnt2 % cnt[cnt1] == 0) {
cout << bottan[cnt1][cnt[cnt1] - 1];
} else {
cout << bottan[cnt1][cnt2 % cnt[cnt1] - 1];
}
}
cnt1 = 0;
cnt2 = 0;
} else {
if (cnt1 == 0) {
cnt1 = str[i] - '0';
cnt2++;
} else {
cnt2++;
}
}
}
cout << endl;
}
} | replace | 17 | 18 | 17 | 18 | -8 | |
p01131 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
int m;
cin >> m;
REP(i, m) {
string str;
int num[1000] = {0};
char now;
int out = 0;
char one[5] = {'.', ',', '!', '?', ' '};
cin >> str;
int hoge = str.size();
REP(i, hoge) { num[i] = str[i] - '0'; };
REP(c, hoge) {
int k = 0;
if (num[c] == 1) {
while (num[c] == 1) {
k++;
c++;
}
out = (k + 4) % 5;
cout << one[out];
} else if (num[c] == 2) {
while (num[c] == 2) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'a' + out;
cout << now;
} else if (num[c] == 3) {
while (num[c] == 3) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'd' + out;
cout << now;
} else if (num[c] == 4) {
while (num[c] == 4) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'g' + out;
cout << now;
} else if (num[c] == 5) {
while (num[c] == 5) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'j' + out;
cout << now;
} else if (num[c] == 6) {
while (num[c] == 6) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'm' + out;
cout << now;
} else if (num[c] == 7) {
while (num[c] == 7) {
k++;
c++;
}
out = (k + 3) % 4;
now = 'p' + out;
cout << now;
} else if (num[c] == 8) {
while (num[c] == 8) {
k++;
c++;
}
out = (k + 2) % 3;
now = 't' + out;
cout << now;
} else if (num[c] == 9) {
while (num[c] == 9) {
k++;
c++;
}
out = (k + 3) % 4;
now = 'w' + out;
cout << now;
}
}
cout << endl;
}
}
| #include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
int m;
cin >> m;
REP(i, m) {
string str;
int num[5000] = {0};
char now;
int out = 0;
char one[5] = {'.', ',', '!', '?', ' '};
cin >> str;
int hoge = str.size();
REP(i, hoge) { num[i] = str[i] - '0'; };
REP(c, hoge) {
int k = 0;
if (num[c] == 1) {
while (num[c] == 1) {
k++;
c++;
}
out = (k + 4) % 5;
cout << one[out];
} else if (num[c] == 2) {
while (num[c] == 2) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'a' + out;
cout << now;
} else if (num[c] == 3) {
while (num[c] == 3) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'd' + out;
cout << now;
} else if (num[c] == 4) {
while (num[c] == 4) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'g' + out;
cout << now;
} else if (num[c] == 5) {
while (num[c] == 5) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'j' + out;
cout << now;
} else if (num[c] == 6) {
while (num[c] == 6) {
k++;
c++;
}
out = (k + 2) % 3;
now = 'm' + out;
cout << now;
} else if (num[c] == 7) {
while (num[c] == 7) {
k++;
c++;
}
out = (k + 3) % 4;
now = 'p' + out;
cout << now;
} else if (num[c] == 8) {
while (num[c] == 8) {
k++;
c++;
}
out = (k + 2) % 3;
now = 't' + out;
cout << now;
} else if (num[c] == 9) {
while (num[c] == 9) {
k++;
c++;
}
out = (k + 3) % 4;
now = 'w' + out;
cout << now;
}
}
cout << endl;
}
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p01131 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
const string button[] = {
"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz",
};
void solve() {
string line;
cin >> line;
char pre;
int count = -1;
for (unsigned i = 0; i < line.size(); ++i) {
if (line[i] == '0') {
int key = pre - '0';
if (key == 0)
continue;
int index = count % button[key].size();
cout << button[key][index];
count = -2;
}
count++;
pre = line[i];
}
cout << endl;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
solve();
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
const string button[] = {
"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz",
};
void solve() {
string line;
cin >> line;
char pre = '0';
int count = -1;
for (unsigned i = 0; i < line.size(); ++i) {
if (line[i] == '0') {
int key = pre - '0';
if (key == 0)
continue;
int index = count % button[key].size();
cout << button[key][index];
count = -2;
}
count++;
pre = line[i];
}
cout << endl;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
solve();
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p01131 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define all(i) i.begin(), i.end()
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int num = 0;
cin >> num;
string dat[12] = {"", ".,!? ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"};
rep(i, num) {
string str;
cin >> str;
vector<int> hit(10, 0);
rep(j, (int)str.size()) {
hit[str[j] - '0'] += 1;
if (j == 0 || str[j - 1] == '0') {
} else if (str[j] == '0') {
int tmp = str[j - 1] - '0', n = hit[tmp];
while (n <= (int)dat[tmp].size()) {
n -= (int)dat[tmp].size();
}
printf("%c", dat[tmp][n - 1]);
rep(i, 10) { hit[i] = 0; }
}
}
printf("\n");
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define all(i) i.begin(), i.end()
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int num = 0;
cin >> num;
string dat[12] = {"", ".,!? ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"};
rep(i, num) {
string str;
cin >> str;
vector<int> hit(10, 0);
rep(j, (int)str.size()) {
hit[str[j] - '0'] += 1;
if (j == 0 || str[j - 1] == '0') {
} else if (str[j] == '0') {
int tmp = str[j - 1] - '0', n = hit[tmp];
while (1) {
if (n <= (int)dat[tmp].size()) {
break;
}
n -= (int)dat[tmp].size();
}
printf("%c", dat[tmp][n - 1]);
rep(i, 10) { hit[i] = 0; }
}
}
printf("\n");
}
return 0;
} | replace | 25 | 26 | 25 | 29 | TLE | |
p01131 | C++ | Runtime Error | #include <cstdio>
using namespace std;
int main() {
char *dic[] = {"", ".,!? ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"};
int len[] = {-1, 5, 3, 3, 3, 3, 3, 4, 3, 4};
int n;
scanf("%d", &n);
while (n--) {
char s[80];
scanf("%s", s);
char bef = '@';
int cnt = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == '0') {
if (cnt > 0)
putchar(dic[bef - '0'][(cnt - 1) % len[bef - '0']]);
cnt = 0;
bef = '@';
} else {
cnt++;
bef = s[i];
}
}
putchar('\n');
}
return 0;
} | #include <cstdio>
using namespace std;
int main() {
char *dic[] = {"", ".,!? ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"};
int len[] = {-1, 5, 3, 3, 3, 3, 3, 4, 3, 4};
int n;
scanf("%d", &n);
while (n--) {
char s[1025];
scanf("%s", s);
char bef = '@';
int cnt = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == '0') {
if (cnt > 0)
putchar(dic[bef - '0'][(cnt - 1) % len[bef - '0']]);
cnt = 0;
bef = '@';
} else {
cnt++;
bef = s[i];
}
}
putchar('\n');
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p01131 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
struct Data {
char c;
int n;
};
int main(void) {
int n;
cin >> n;
string str;
string c[] = {".,!? ", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
while (n--) {
cin >> str;
Data a[100];
char ch = 'A';
int t = -1;
for (int i = 0; i < str.size(); i++) {
if (ch == str[i]) {
a[t].n++;
} else {
ch = str[i];
t++;
a[t].c = ch;
a[t].n = 1;
}
}
t++;
for (int i = 0; i < t; i++) {
if (a[i].c == '0')
continue;
cout << c[a[i].c - '0' - 1][(a[i].n - 1) % c[a[i].c - '0' - 1].size()];
}
cout << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
struct Data {
char c;
int n;
};
int main(void) {
int n;
cin >> n;
string str;
string c[] = {".,!? ", "abc", "def", "ghi", "jkl",
"mno", "pqrs", "tuv", "wxyz"};
while (n--) {
cin >> str;
Data a[1200];
char ch = 'A';
int t = -1;
for (int i = 0; i < str.size(); i++) {
if (ch == str[i]) {
a[t].n++;
} else {
ch = str[i];
t++;
a[t].c = ch;
a[t].n = 1;
}
}
t++;
for (int i = 0; i < t; i++) {
if (a[i].c == '0')
continue;
cout << c[a[i].c - '0' - 1][(a[i].n - 1) % c[a[i].c - '0' - 1].size()];
}
cout << endl;
}
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p01132 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n[1000], c10[1000], c50[1000], c100[1000], c500[1000], i = 0;
while (1) {
cin >> n[i];
if (n[i] == 0)
break;
cin >> c10[i] >> c50[i] >> c100[i] >> c500[i];
i++;
}
for (int j = 0; j < i; j++) {
int m, k10, k50, k100, k500;
m = c10[j] * 10 + c50[j] * 50 + c100[j] * 100 + c500[j] * 500 - n[j];
k500 = c500[j] - m / 500;
if (k500 < 0)
k500 = 0;
m -= 500 * (m / 500);
k100 = c100[j] - m / 100;
if (k100 < 0)
k100 = 0;
m -= 100 * (m / 100);
k50 = c50[j] - m / 50;
if (k50 < 0)
k50 = 0;
m -= 50 * (m / 50);
k10 = c10[j] - m / 10;
if (k10 < 0)
k10 = 0;
m -= 10 * (m / 10);
if (k10 > 0)
cout << 10 << " " << k10 << endl;
if (k50 > 0)
cout << 50 << " " << k50 << endl;
if (k100 > 0)
cout << 100 << " " << k100 << endl;
if (k500 > 0)
cout << 500 << " " << k500 << endl;
if (j < i - 1)
cout << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n[10000], c10[10000], c50[10000], c100[10000], c500[10000], i = 0;
while (1) {
cin >> n[i];
if (n[i] == 0)
break;
cin >> c10[i] >> c50[i] >> c100[i] >> c500[i];
i++;
}
for (int j = 0; j < i; j++) {
int m, k10, k50, k100, k500;
m = c10[j] * 10 + c50[j] * 50 + c100[j] * 100 + c500[j] * 500 - n[j];
k500 = c500[j] - m / 500;
if (k500 < 0)
k500 = 0;
m -= 500 * (m / 500);
k100 = c100[j] - m / 100;
if (k100 < 0)
k100 = 0;
m -= 100 * (m / 100);
k50 = c50[j] - m / 50;
if (k50 < 0)
k50 = 0;
m -= 50 * (m / 50);
k10 = c10[j] - m / 10;
if (k10 < 0)
k10 = 0;
m -= 10 * (m / 10);
if (k10 > 0)
cout << 10 << " " << k10 << endl;
if (k50 > 0)
cout << 50 << " " << k50 << endl;
if (k100 > 0)
cout << 100 << " " << k100 << endl;
if (k500 > 0)
cout << 500 << " " << k500 << endl;
if (j < i - 1)
cout << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p01133 | C++ | Time Limit Exceeded | #include <math.h>
#include <stdio.h>
#define MAX_NUM 100000000
double dist(int x, int y) { return sqrt((double)(x * x + y * y)); }
double min(double a, double b) {
if (a > b)
return b;
else
return a;
}
int n, cx[20], cy[20], dx, dy;
double dfs(int now, double sum, int bit) {
int i;
double ret = MAX_NUM;
if (sum >= dist(dx - cx[now], dy - cy[now]))
return ret;
if (bit == (1 << n) - 1)
return sum;
for (i = 0; i < n; i++) {
if (~bit & (1 << i)) {
ret = min(
dfs(i, sum + dist(cx[i] - cx[now], cy[i] - cy[now]), bit | (1 << i)),
ret);
}
}
return ret;
}
int main(void) {
int hx, hy, i;
double ans;
while (1) {
scanf("%d%d%d%d%d", &n, &hx, &hy, &dx, &dy);
if (n == 0 && hx == 0 && hy == 0 && dx == 0 && dy == 0)
break;
for (i = 0; i < n; i++)
scanf("%d%d", &cx[i], &cy[i]);
ans = MAX_NUM;
for (i = 0; i < n; i++)
ans = min(ans, dfs(i, dist(cx[i] - hx, cy[i] - hy), 1 << i));
if (ans != MAX_NUM)
printf("YES\n");
else
printf("NO\n");
}
return 0;
} | #include <math.h>
#include <stdio.h>
#define MAX_NUM 100000000
double dist(int x, int y) { return sqrt((double)(x * x + y * y)); }
double min(double a, double b) {
if (a > b)
return b;
else
return a;
}
int n, cx[20], cy[20], dx, dy;
double dfs(int now, double sum, int bit) {
int i;
double ret = MAX_NUM;
for (i = 0; i < n; i++)
if (~bit & (1 << i) && sum + dist(cx[now] - cx[i], cy[now] - cy[i]) >=
dist(dx - cx[i], dy - cy[i]))
return ret;
if (sum >= dist(dx - cx[now], dy - cy[now]))
return ret;
if (bit == (1 << n) - 1)
return sum;
for (i = 0; i < n; i++) {
if (~bit & (1 << i)) {
ret = min(
dfs(i, sum + dist(cx[i] - cx[now], cy[i] - cy[now]), bit | (1 << i)),
ret);
}
}
return ret;
}
int main(void) {
int hx, hy, i;
double ans;
while (1) {
scanf("%d%d%d%d%d", &n, &hx, &hy, &dx, &dy);
if (n == 0 && hx == 0 && hy == 0 && dx == 0 && dy == 0)
break;
for (i = 0; i < n; i++)
scanf("%d%d", &cx[i], &cy[i]);
ans = MAX_NUM;
for (i = 0; i < n; i++)
ans = min(ans, dfs(i, dist(cx[i] - hx, cy[i] - hy), 1 << i));
if (ans != MAX_NUM)
printf("YES\n");
else
printf("NO\n");
}
return 0;
} | insert | 18 | 18 | 18 | 22 | TLE | |
p01133 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int n;
int hx, hy, dx, dy, cx[21], cy[21];
double dist(double ax, double ay, double bx, double by) {
return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
int dfs(int c, double t, int x, int y, int *used) {
// printf("%d %lf %lf %lf\n", c, t, x, y);
if (c == n)
return 1;
rep(i, n) {
if (used[i])
continue;
double nt = dist(x, y, cx[i], cy[i]);
// printf("x:%lf y:%lf nt:%lf\n", x, y, nt);
// printf("dx;%lf dy:%lf cx:%lf cy:%lf\n", dx, dy, cx[i], cy[i]);
// printf("%lf %lf\n", t + nt + EPS, dist(dx, dy, cx[i], cy[i]));
if (t + nt + EPS > dist(dx, dy, cx[i], cy[i]))
return 0;
used[i] = 1;
if (dfs(c + 1, t + nt, cx[i], cy[i], used))
return 1;
used[i] = 0;
}
return 0;
}
int main() {
while (scanf("%d%d%d%d%d", &n, &hx, &hy, &dx, &dy) && n + hx + hy + dx + dy) {
rep(i, n) scanf("%d%d", cx + i, cy + i);
;
int used[21];
memset(used, 0, sizeof(used));
if (dfs(0, 0, hx, hy, used))
puts("YES");
else
puts("NO");
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int n;
int hx, hy, dx, dy, cx[21], cy[21];
double dist(double ax, double ay, double bx, double by) {
return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
int dfs(int c, double t, int x, int y, int *used) {
// printf("%d %lf %lf %lf\n", c, t, x, y);
if (c == n)
return 1;
rep(i, n) {
if (used[i])
continue;
if (t + dist(x, y, cx[i], cy[i]) + EPS > dist(dx, dy, cx[i], cy[i]))
return 0;
}
rep(i, n) {
if (used[i])
continue;
double nt = dist(x, y, cx[i], cy[i]);
// printf("x:%lf y:%lf nt:%lf\n", x, y, nt);
// printf("dx;%lf dy:%lf cx:%lf cy:%lf\n", dx, dy, cx[i], cy[i]);
// printf("%lf %lf\n", t + nt + EPS, dist(dx, dy, cx[i], cy[i]));
if (t + nt + EPS > dist(dx, dy, cx[i], cy[i]))
return 0;
used[i] = 1;
if (dfs(c + 1, t + nt, cx[i], cy[i], used))
return 1;
used[i] = 0;
}
return 0;
}
int main() {
while (scanf("%d%d%d%d%d", &n, &hx, &hy, &dx, &dy) && n + hx + hy + dx + dy) {
rep(i, n) scanf("%d%d", cx + i, cy + i);
;
int used[21];
memset(used, 0, sizeof(used));
if (dfs(0, 0, hx, hy, used))
puts("YES");
else
puts("NO");
}
return 0;
} | insert | 46 | 46 | 46 | 53 | TLE | |
p01133 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-12;
class Compare {
int monster_x;
int monster_y;
public:
Compare(int monster_x, int monster_y)
: monster_x(monster_x), monster_y(monster_y) {}
bool operator()(const P &ci, const P &cj) const {
int dist_i = (ci.first - monster_x) * (ci.first - monster_x) +
(ci.second - monster_y) * (ci.second - monster_y);
int dist_j = (cj.first - monster_x) * (cj.first - monster_x) +
(cj.second - monster_y) * (cj.second - monster_y);
return dist_i < dist_j;
}
};
class State {
int x;
int y;
double dist;
};
bool dfs(int hero_x, int hero_y, double current_time, int S, int monster_x,
int monster_y, const vector<P> &cristals) {
bool res = false;
if (S == (1 << cristals.size()) - 1)
return true;
for (int i = 0; i < cristals.size(); i++) {
if (S & (1 << i))
continue;
double add_time =
sqrt((hero_x - cristals[i].first) * (hero_x - cristals[i].first) +
(hero_y - cristals[i].second) * (hero_y - cristals[i].second));
double tmp_current_time = current_time + add_time;
double impurity_arrive_time = sqrt(
(monster_x - cristals[i].first) * (monster_x - cristals[i].first) +
(monster_y - cristals[i].second) * (monster_y - cristals[i].second));
if (tmp_current_time >= impurity_arrive_time) {
return false;
}
res |= dfs(cristals[i].first, cristals[i].second, tmp_current_time,
S | (1 << i), monster_x, monster_y, cristals);
}
return res;
}
int main() {
int total_cristals;
int hero_x;
int hero_y;
int monster_x;
int monster_y;
while (~scanf("%d %d %d %d %d", &total_cristals, &hero_x, &hero_y, &monster_x,
&monster_y)) {
if (total_cristals == 0 && hero_x == 0 && hero_y == 0 && monster_x == 0 &&
monster_y == 0)
break;
vector<P> cristals;
for (int cristal_i = 0; cristal_i < total_cristals; cristal_i++) {
int x, y;
scanf("%d %d", &x, &y);
cristals.push_back(P(x, y));
}
// Compare comp(monster_x,monster_y);
// sort(cristals.begin(),cristals.end(),comp);
printf("%s\n", dfs(hero_x, hero_y, 0, 0, monster_x, monster_y, cristals)
? "YES"
: "NO");
}
} | #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-12;
class Compare {
int monster_x;
int monster_y;
public:
Compare(int monster_x, int monster_y)
: monster_x(monster_x), monster_y(monster_y) {}
bool operator()(const P &ci, const P &cj) const {
int dist_i = (ci.first - monster_x) * (ci.first - monster_x) +
(ci.second - monster_y) * (ci.second - monster_y);
int dist_j = (cj.first - monster_x) * (cj.first - monster_x) +
(cj.second - monster_y) * (cj.second - monster_y);
return dist_i < dist_j;
}
};
class State {
int x;
int y;
double dist;
};
bool dfs(int hero_x, int hero_y, double current_time, int S, int monster_x,
int monster_y, const vector<P> &cristals) {
bool res = false;
if (S == (1 << cristals.size()) - 1)
return true;
for (int i = 0; i < cristals.size(); i++) {
if (S & (1 << i))
continue;
double add_time =
sqrt((hero_x - cristals[i].first) * (hero_x - cristals[i].first) +
(hero_y - cristals[i].second) * (hero_y - cristals[i].second));
double tmp_current_time = current_time + add_time;
double impurity_arrive_time = sqrt(
(monster_x - cristals[i].first) * (monster_x - cristals[i].first) +
(monster_y - cristals[i].second) * (monster_y - cristals[i].second));
if (tmp_current_time >= impurity_arrive_time) {
return false;
}
res |= dfs(cristals[i].first, cristals[i].second, tmp_current_time,
S | (1 << i), monster_x, monster_y, cristals);
}
return res;
}
int main() {
int total_cristals;
int hero_x;
int hero_y;
int monster_x;
int monster_y;
while (~scanf("%d %d %d %d %d", &total_cristals, &hero_x, &hero_y, &monster_x,
&monster_y)) {
if (total_cristals == 0 && hero_x == 0 && hero_y == 0 && monster_x == 0 &&
monster_y == 0)
break;
vector<P> cristals;
for (int cristal_i = 0; cristal_i < total_cristals; cristal_i++) {
int x, y;
scanf("%d %d", &x, &y);
cristals.push_back(P(x, y));
}
Compare comp(monster_x, monster_y);
sort(cristals.begin(), cristals.end(), comp);
printf("%s\n", dfs(hero_x, hero_y, 0, 0, monster_x, monster_y, cristals)
? "YES"
: "NO");
}
} | replace | 98 | 100 | 98 | 100 | TLE | |
p01133 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
#include <map>
// S
using namespace std;
typedef pair<int, int> P;
int cx[30], cy[30], n, hx, hy, dx, dy;
map<P, double> mp;
bool func(int S, int now, double time) {
if (S == (1 << n) - 1)
return 1;
for (int i = 0; i < n; i++) {
if (!(S & (1 << i))) {
double pre = mp[P(now, i)];
double dis = mp[P(i, n + 1)];
if (pre + time < dis && func(S | (1 << i), i, time + pre))
return 1;
}
}
return 0;
}
int main() {
while (cin >> n >> hx >> hy >> dx >> dy, n || hx || hy || dx || dy) {
for (int i = 0; i < n; i++)
cin >> cx[i] >> cy[i];
cx[n] = hx;
cy[n] = hy;
cx[n + 1] = dx;
cy[n + 1] = dy;
for (int i = 0; i <= n + 1; i++)
for (int j = 0; j <= n + 1; j++)
mp[P(i, j)] = sqrt((cx[i] - cx[j]) * (cx[i] - cx[j]) +
(cy[i] - cy[j]) * (cy[i] - cy[j]));
if (func(0, n, 0.0))
cout << "YES" << endl;
else
cout << "NO" << endl;
mp.clear();
}
return 0;
} | #include <cmath>
#include <iostream>
#include <map>
// S
using namespace std;
typedef pair<int, int> P;
int cx[30], cy[30], n, hx, hy, dx, dy;
map<P, double> mp;
bool func(int S, int now, double time) {
if (S == (1 << n) - 1)
return 1;
for (int i = 0; i < n; i++) {
if (!(S & (1 << i))) {
if (mp[P(now, i)] + time >= mp[P(i, n + 1)])
return 0;
}
}
for (int i = 0; i < n; i++) {
if (!(S & (1 << i))) {
double pre = mp[P(now, i)];
double dis = mp[P(i, n + 1)];
if (pre + time < dis && func(S | (1 << i), i, time + pre))
return 1;
}
}
return 0;
}
int main() {
while (cin >> n >> hx >> hy >> dx >> dy, n || hx || hy || dx || dy) {
for (int i = 0; i < n; i++)
cin >> cx[i] >> cy[i];
cx[n] = hx;
cy[n] = hy;
cx[n + 1] = dx;
cy[n + 1] = dy;
for (int i = 0; i <= n + 1; i++)
for (int j = 0; j <= n + 1; j++)
mp[P(i, j)] = sqrt((cx[i] - cx[j]) * (cx[i] - cx[j]) +
(cy[i] - cy[j]) * (cy[i] - cy[j]));
if (func(0, n, 0.0))
cout << "YES" << endl;
else
cout << "NO" << endl;
mp.clear();
}
return 0;
} | insert | 11 | 11 | 11 | 17 | TLE | |
p01133 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define EPS 1e-10
struct Point {
double x, y, d;
};
int n;
Point hero, demon;
vector<Point> crystal;
bool ok;
double dist(Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void solve(int now, double time, vector<bool> visited) {
int i;
bool f = true;
if (time - crystal[now].d > -EPS)
return;
for (i = 0; i < n; i++) {
if (visited[i])
continue;
visited[i] = true;
solve(i, time + dist(crystal[now], crystal[i]), visited);
visited[i] = false;
f = false;
}
if (f)
ok = true;
return;
}
int main() {
vector<bool> visited;
int i;
double hx, hy, dx, dy, x, y;
double time;
while (cin >> n >> hx >> hy >> dx >> dy, hx || hy || dx || dy) {
hero.x = hx;
hero.y = hy;
demon.x = dx;
demon.y = dy;
crystal.clear();
visited.resize(n);
fill(visited.begin(), visited.end(), false);
for (i = 0; i < n; i++) {
cin >> x >> y;
Point p = {x, y, 0};
p.d = dist(p, demon);
crystal.push_back(p);
}
ok = false;
for (i = 0; i < n; i++) {
time = dist(hero, crystal[i]);
visited[i] = true;
solve(i, time, visited);
visited[i] = false;
if (ok)
break;
}
puts(ok ? "YES" : "NO");
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define EPS 1e-10
struct Point {
double x, y, d;
};
int n;
Point hero, demon;
vector<Point> crystal;
bool ok;
double dist(Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void solve(int now, double time, vector<bool> visited) {
int i;
bool f = true;
if (time - crystal[now].d > -EPS)
return;
for (i = 0; i < n; i++) {
if (visited[i])
continue;
if (time + dist(crystal[now], crystal[i]) - crystal[i].d > EPS)
return;
}
for (i = 0; i < n; i++) {
if (visited[i])
continue;
visited[i] = true;
solve(i, time + dist(crystal[now], crystal[i]), visited);
visited[i] = false;
f = false;
}
if (f)
ok = true;
return;
}
int main() {
vector<bool> visited;
int i;
double hx, hy, dx, dy, x, y;
double time;
while (cin >> n >> hx >> hy >> dx >> dy, hx || hy || dx || dy) {
hero.x = hx;
hero.y = hy;
demon.x = dx;
demon.y = dy;
crystal.clear();
visited.resize(n);
fill(visited.begin(), visited.end(), false);
for (i = 0; i < n; i++) {
cin >> x >> y;
Point p = {x, y, 0};
p.d = dist(p, demon);
crystal.push_back(p);
}
ok = false;
for (i = 0; i < n; i++) {
time = dist(hero, crystal[i]);
visited[i] = true;
solve(i, time, visited);
visited[i] = false;
if (ok)
break;
}
puts(ok ? "YES" : "NO");
}
} | insert | 24 | 24 | 24 | 30 | TLE | |
p01133 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<double, int> P;
int xs[21];
int ys[21];
double h[21];
int n;
double Hypot(int x, int y) { return sqrt(x * x + y * y); }
bool ok(int x, int y, int done, double t) {
if (done + 1 == (1 << n)) {
return true;
}
vector<P> q;
for (int i = 0; i < n; i++) {
if (done & (1 << i))
continue;
double d = t + Hypot(xs[i] - x, ys[i] - y);
if (d >= h[i]) {
return false;
}
q.push_back(P(d, i));
}
sort(q.begin(), q.end());
for (auto p : q) {
int i = p.second;
if (ok(xs[i], ys[i], done | (1 << i), p.first)) {
return true;
}
}
return false;
}
void exec() {
int hx, hy, dx, dy;
cin >> n >> hx >> hy >> dx >> dy;
if ((n | hx | hy | dx | dy) == 0) {
exit(1);
}
for (int i = 0; i < n; i++) {
cin >> xs[i] >> ys[i];
h[i] = Hypot(xs[i] - dx, ys[i] - dy);
}
if (ok(hx, hy, 0, 0)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
int main() {
while (1)
exec();
} | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<double, int> P;
int xs[21];
int ys[21];
double h[21];
int n;
double Hypot(int x, int y) { return sqrt(x * x + y * y); }
bool ok(int x, int y, int done, double t) {
if (done + 1 == (1 << n)) {
return true;
}
vector<P> q;
for (int i = 0; i < n; i++) {
if (done & (1 << i))
continue;
double d = t + Hypot(xs[i] - x, ys[i] - y);
if (d >= h[i]) {
return false;
}
q.push_back(P(d, i));
}
sort(q.begin(), q.end());
for (auto p : q) {
int i = p.second;
if (ok(xs[i], ys[i], done | (1 << i), p.first)) {
return true;
}
}
return false;
}
void exec() {
int hx, hy, dx, dy;
cin >> n >> hx >> hy >> dx >> dy;
if ((n | hx | hy | dx | dy) == 0) {
exit(0);
}
for (int i = 0; i < n; i++) {
cin >> xs[i] >> ys[i];
h[i] = Hypot(xs[i] - dx, ys[i] - dy);
}
if (ok(hx, hy, 0, 0)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
int main() {
while (1)
exec();
} | replace | 60 | 61 | 60 | 61 | 1 | |
p01133 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
int N, M, K, L, R, H, W;
const long long int MOD = 1000000007;
const float EPS = 1e-8;
float dis(float a, float c, float b, float d) {
return sqrt((a - b) * (a - b) + (c - d) * (c - d));
}
float dp[1 << 20][20];
int main() {
int N;
float sx, sy, gx, gy;
while (cin >> N >> sx >> sy >> gx >> gy, N) {
vector<float> y(N);
vector<float> x(N);
vector<float> devil(N);
bool f = true;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
devil[i] = dis(gx, gy, x[i], y[i]);
if (devil[i] < dis(sx, sy, x[i], y[i])) {
f = false;
}
}
if (!f) {
cout << "NO\n";
continue;
}
vector<vector<float>> dist(N, vector<float>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[i][j] = dis(x[i], y[i], x[j], y[j]);
}
}
for (int i = 0; i < 1 << N; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = MOD;
}
}
for (int i = 0; i < N; i++) {
if (devil[i] - EPS > dis(sx, sy, x[i], y[i])) {
dp[1 << i][i] = dis(sx, sy, x[i], y[i]);
}
}
for (int i = 1; i < 1 << N; i++) {
for (int j = 0; j < N; j++) {
if (!((i >> j) & 1))
continue;
if (dp[i][j] >= 1000000)
continue;
for (int k = 0; k < N; k++) {
if ((i >> k) & 1)
continue;
float nx = dp[i][j] + dist[j][k];
if (nx < devil[k] - EPS) {
dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], nx);
}
}
}
}
float ans = MOD;
for (int i = 0; i < N; i++) {
ans = min(ans, dp[(1 << N) - 1][i]);
}
if (ans >= 10000000) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
int N, M, K, L, R, H, W;
const long long int MOD = 1000000007;
const float EPS = 1e-8;
float dis(float a, float c, float b, float d) {
return sqrt((a - b) * (a - b) + (c - d) * (c - d));
}
float dp[1 << 20][20];
int main() {
int N;
float sx, sy, gx, gy;
while (cin >> N >> sx >> sy >> gx >> gy, N) {
vector<float> y(N);
vector<float> x(N);
vector<float> devil(N);
bool f = true;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
devil[i] = dis(gx, gy, x[i], y[i]);
if (devil[i] < dis(sx, sy, x[i], y[i])) {
f = false;
}
}
if (!f) {
cout << "NO\n";
continue;
}
vector<vector<float>> dist(N, vector<float>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[i][j] = dis(x[i], y[i], x[j], y[j]);
}
}
for (int i = 0; i < 1 << N; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = MOD;
}
}
for (int i = 0; i < N; i++) {
if (devil[i] - EPS > dis(sx, sy, x[i], y[i])) {
dp[1 << i][i] = dis(sx, sy, x[i], y[i]);
}
}
for (int i = 1; i < 1 << N; i++) {
for (int j = 0; j < N; j++) {
if (!((i >> j) & 1))
continue;
if (dp[i][j] >= 1000000)
continue;
bool hoge = false;
for (int k = 0; k < N; k++) {
if ((i >> k) & 1)
continue;
if (dp[i][j] + dist[j][k] > devil[k] + EPS)
hoge = true;
}
if (hoge)
continue;
for (int k = 0; k < N; k++) {
if ((i >> k) & 1)
continue;
float nx = dp[i][j] + dist[j][k];
if (nx < devil[k] - EPS) {
dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], nx);
}
}
}
}
float ans = MOD;
for (int i = 0; i < N; i++) {
ans = min(ans, dp[(1 << N) - 1][i]);
}
if (ans >= 10000000) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
return 0;
}
| insert | 57 | 57 | 57 | 67 | TLE | |
p01133 | C++ | Time Limit Exceeded | #include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
double eps = 1e-9;
int x[23];
int y[23];
double dist[23][23];
int n;
int solve(int a, int b, double s) {
if (a == (1 << n) - 1)
return 1;
for (int i = 0; i < n; i++) {
if (a & (1 << i))
continue;
if (s + dist[b][i] + eps > dist[n + 1][i])
return 0;
if (solve(a + (1 << i), i, s + dist[b][i]))
return 1;
}
return 0;
}
int main() {
int a, hx, hy, dx, dy;
while (scanf("%d%d%d%d%d", &a, &hx, &hy, &dx, &dy), a) {
n = a;
for (int i = 0; i < a; i++)
scanf("%d%d", x + i, y + i);
x[a] = hx;
x[a + 1] = dx;
y[a] = hy;
y[a + 1] = dy;
for (int i = 0; i < a + 2; i++)
for (int j = 0; j < a + 2; j++)
dist[i][j] =
sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
if (solve(0, a, 0))
printf("YES\n");
else
printf("NO\n");
}
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
double eps = 1e-9;
int x[23];
int y[23];
double dist[23][23];
int n;
int solve(int a, int b, double s) {
if (a == (1 << n) - 1)
return 1;
for (int i = 0; i < n; i++) {
if (a & (1 << i))
continue;
if (s + dist[b][i] + eps > dist[n + 1][i])
return 0;
}
for (int i = 0; i < n; i++) {
if (a & (1 << i))
continue;
if (solve(a + (1 << i), i, s + dist[b][i]))
return 1;
}
return 0;
}
int main() {
int a, hx, hy, dx, dy;
while (scanf("%d%d%d%d%d", &a, &hx, &hy, &dx, &dy), a) {
n = a;
for (int i = 0; i < a; i++)
scanf("%d%d", x + i, y + i);
x[a] = hx;
x[a + 1] = dx;
y[a] = hy;
y[a + 1] = dy;
for (int i = 0; i < a + 2; i++)
for (int j = 0; j < a + 2; j++)
dist[i][j] =
sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
if (solve(0, a, 0))
printf("YES\n");
else
printf("NO\n");
}
} | insert | 17 | 17 | 17 | 22 | TLE | |
p01133 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#define INF (1 << 30)
#define EPS (double)(1e-5)
using namespace std;
int n, hx, hy, dx, dy;
int cx[22], cy[22];
double L(int x, int y) { return sqrt(x * x + y * y); }
bool solve(int m, int bit, double l) {
if (bit == (1 << n) - 1)
return true;
for (int i = 1; i < n; i++) {
if (bit & (1 << i))
continue;
if (L(cx[m] - cx[i], cy[m] - cy[i]) + l + EPS > L(cx[i] - dx, cy[i] - dy))
return false;
if (solve(i, bit | (1 << i), l + L(cx[m] - cx[i], cy[m] - cy[i])))
return true;
}
return false;
}
int main(void) {
while (cin >> n >> cx[0] >> cy[0] >> dx >> dy && n) {
n++;
for (int i = 1; i < n; i++) {
cin >> cx[i] >> cy[i];
}
if (solve(0, 1, 0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#define INF (1 << 30)
#define EPS (double)(1e-5)
using namespace std;
int n, hx, hy, dx, dy;
int cx[22], cy[22];
double L(int x, int y) { return sqrt(x * x + y * y); }
bool solve(int m, int bit, double l) {
if (bit == (1 << n) - 1)
return true;
for (int i = 1; i < n; i++) {
if (bit & (1 << i))
continue;
if (L(cx[m] - cx[i], cy[m] - cy[i]) + l + EPS > L(cx[i] - dx, cy[i] - dy))
return false;
}
for (int i = 1; i < n; i++) {
if (bit & (1 << i))
continue;
if (solve(i, bit | (1 << i), l + L(cx[m] - cx[i], cy[m] - cy[i])))
return true;
}
return false;
}
int main(void) {
while (cin >> n >> cx[0] >> cy[0] >> dx >> dy && n) {
n++;
for (int i = 1; i < n; i++) {
cin >> cx[i] >> cy[i];
}
if (solve(0, 1, 0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
} | insert | 20 | 20 | 20 | 24 | TLE | |
p01136 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
vector<int> v[31];
ll dp[31][50];
int main() {
int n;
while (scanf("%d", &n), n) {
rep(i, n) {
int f;
scanf("%d", &f);
rep(j, f) {
int k;
scanf("%d", &k);
v[k].push_back(i);
}
}
rep(i, n) dp[0][i] = 1LL << i;
for (int i = 1; i <= 30; i++) {
rep(j, n) dp[i][j] = dp[i - 1][j];
rep(t, n) for (int j : v[i]) for (int k : v[i]) {
dp[i][j] |= dp[i][k];
dp[i][k] |= dp[i][j];
}
}
rep(i, 31) rep(j, n) {
if (dp[i][j] == (1LL << n) - 1) {
printf("%d\n", i);
goto g;
}
}
puts("-1");
g:;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
vector<int> v[31];
ll dp[31][50];
int main() {
int n;
while (scanf("%d", &n), n) {
rep(i, 31) v[i].clear();
rep(i, n) {
int f;
scanf("%d", &f);
rep(j, f) {
int k;
scanf("%d", &k);
v[k].push_back(i);
}
}
rep(i, n) dp[0][i] = 1LL << i;
for (int i = 1; i <= 30; i++) {
rep(j, n) dp[i][j] = dp[i - 1][j];
rep(t, n) for (int j : v[i]) for (int k : v[i]) {
dp[i][j] |= dp[i][k];
dp[i][k] |= dp[i][j];
}
}
rep(i, 31) rep(j, n) {
if (dp[i][j] == (1LL << n) - 1) {
printf("%d\n", i);
goto g;
}
}
puts("-1");
g:;
}
} | insert | 10 | 10 | 10 | 11 | TLE | |
p01136 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, a;
cin >> n;
while (n != 0) {
int i, j, k, l;
int v[51][31] = {{}};
for (i = 0; i < n; i++) {
cin >> m;
for (j = 0; j < m; j++) {
cin >> a;
v[i][a] = 1;
}
}
vector<int> g[51];
vector<int> p[51];
for (i = 0; i < n; i++)
g[i].push_back(i);
bool f = false, x;
for (i = 1; i < 31; i++) {
// cout << "day" << i << endl;
for (k = 0; k < n; k++) {
sort(g[i].begin(), g[i].end());
g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end());
p[k].clear();
for (l = 0; l < g[k].size(); l++)
p[k].push_back(g[k][l]);
// for(l=0;l<p[k].size();l++) cout << p[k][l] << " ";
// cout << endl;
}
for (j = 0; j < n; j++) {
if (v[j][i] == 0)
continue;
for (k = j + 1; k < n; k++) {
if (v[k][i] == 0)
continue;
// cout << i << ":" << j << ":" << k << endl;
for (l = 0; l < p[j].size(); l++)
g[k].push_back(p[j][l]);
for (l = 0; l < p[k].size(); l++)
g[j].push_back(p[k][l]);
}
}
bool li[51];
for (j = 0; j < n; j++) {
for (k = 0; k < n; k++)
li[k] = false;
for (k = 0; k < g[j].size(); k++) {
// cout << g[j][k] << " ";
li[g[j][k]] = true;
}
// cout << endl;
x = true;
for (k = 0; k < n; k++)
if (!li[k])
x = false;
if (x) {
f = true;
break;
}
}
if (f) {
cout << i << endl;
break;
}
}
if (!f)
cout << -1 << endl;
cin >> n;
}
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, a;
cin >> n;
while (n != 0) {
int i, j, k, l;
int v[51][31] = {{}};
for (i = 0; i < n; i++) {
cin >> m;
for (j = 0; j < m; j++) {
cin >> a;
v[i][a] = 1;
}
}
vector<int> g[51];
vector<int> p[51];
for (i = 0; i < n; i++)
g[i].push_back(i);
bool f = false, x;
for (i = 1; i < 31; i++) {
// cout << "day" << i << endl;
for (k = 0; k < n; k++) {
sort(g[k].begin(), g[k].end());
g[k].erase(unique(g[k].begin(), g[k].end()), g[k].end());
p[k].clear();
for (l = 0; l < g[k].size(); l++)
p[k].push_back(g[k][l]);
// for(l=0;l<p[k].size();l++) cout << p[k][l] << " ";
// cout << endl;
}
for (j = 0; j < n; j++) {
if (v[j][i] == 0)
continue;
for (k = j + 1; k < n; k++) {
if (v[k][i] == 0)
continue;
// cout << i << ":" << j << ":" << k << endl;
for (l = 0; l < p[j].size(); l++)
g[k].push_back(p[j][l]);
for (l = 0; l < p[k].size(); l++)
g[j].push_back(p[k][l]);
}
}
bool li[51];
for (j = 0; j < n; j++) {
for (k = 0; k < n; k++)
li[k] = false;
for (k = 0; k < g[j].size(); k++) {
// cout << g[j][k] << " ";
li[g[j][k]] = true;
}
// cout << endl;
x = true;
for (k = 0; k < n; k++)
if (!li[k])
x = false;
if (x) {
f = true;
break;
}
}
if (f) {
cout << i << endl;
break;
}
}
if (!f)
cout << -1 << endl;
cin >> n;
}
} | replace | 25 | 27 | 25 | 27 | 0 | |
p01136 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
using namespace std;
#define dump(n) cout << "# " << #n << '=' << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int INFTY = 1 << 29;
const double EPS = 1e-9;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
rep(i, a.size()) os << (i ? " " : "") << a[i];
return os << ']';
}
int main() {
for (int n; cin >> n, n;) {
vvi ds(n);
rep(i, n) {
int f;
cin >> f;
ds[i].resize(f);
rep(j, f) {
cin >> ds[i][j];
ds[i][j]--;
}
}
vector<ll> meet(30);
rep(i, n) rep(j, ds[i].size()) meet[ds[i][j]] |= 1ll << i;
vector<ll> canhave(n);
rep(i, n) canhave[i] |= 1ll << i;
bool ok = false;
for (int d = 0;; d++) {
ll maps = 0;
rep(i, n) if (meet[d] >> i & 1) maps |= canhave[i];
rep(i, n) {
if (meet[d] >> i & 1)
canhave[i] |= maps;
if (canhave[i] == (1ll << n) - 1) {
cout << d + 1 << endl;
ok = true;
goto end;
}
}
}
end:
if (!ok)
cout << -1 << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
using namespace std;
#define dump(n) cout << "# " << #n << '=' << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int INFTY = 1 << 29;
const double EPS = 1e-9;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
rep(i, a.size()) os << (i ? " " : "") << a[i];
return os << ']';
}
int main() {
for (int n; cin >> n, n;) {
vvi ds(n);
rep(i, n) {
int f;
cin >> f;
ds[i].resize(f);
rep(j, f) {
cin >> ds[i][j];
ds[i][j]--;
}
}
vector<ll> meet(30);
rep(i, n) rep(j, ds[i].size()) meet[ds[i][j]] |= 1ll << i;
vector<ll> canhave(n);
rep(i, n) canhave[i] |= 1ll << i;
bool ok = false;
rep(d, 30) {
ll maps = 0;
rep(i, n) if (meet[d] >> i & 1) maps |= canhave[i];
rep(i, n) {
if (meet[d] >> i & 1)
canhave[i] |= maps;
if (canhave[i] == (1ll << n) - 1) {
cout << d + 1 << endl;
ok = true;
goto end;
}
}
}
end:
if (!ok)
cout << -1 << endl;
}
return 0;
} | replace | 75 | 76 | 75 | 76 | 0 | |
p01136 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
bool f[50][50] = {false};
vector<int> day[30];
for (int i = 0; i < n; i++)
f[i][i] = true;
for (int i = 0, a; i < n; i++) {
cin >> a;
for (int j = 0, b; j < a; j++) {
cin >> b;
day[b - 1].push_back(i);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < day[i].size(); j++)
for (int k = 0; k < day[i].size(); k++)
for (int l = 0; l < n; l++)
f[day[i][j]][l] = f[day[i][k]][l] =
f[day[i][j]][l] | f[day[i][k]][l];
for (int j = 0; j < n; j++) {
bool flag = true;
for (int k = 0; k < n; k++)
flag &= f[j][k];
if (flag) {
cout << i + 1 << endl;
goto jump;
}
}
}
cout << "-1" << endl;
jump:;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
bool f[50][50] = {false};
vector<int> day[30];
for (int i = 0; i < n; i++)
f[i][i] = true;
for (int i = 0, a; i < n; i++) {
cin >> a;
for (int j = 0, b; j < a; j++) {
cin >> b;
day[b - 1].push_back(i);
}
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < day[i].size(); j++)
for (int k = 0; k < day[i].size(); k++)
for (int l = 0; l < n; l++)
f[day[i][j]][l] = f[day[i][k]][l] =
f[day[i][j]][l] | f[day[i][k]][l];
for (int j = 0; j < n; j++) {
bool flag = true;
for (int k = 0; k < n; k++)
flag &= f[j][k];
if (flag) {
cout << i + 1 << endl;
goto jump;
}
}
}
cout << "-1" << endl;
jump:;
}
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p01136 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
while (cin >> a, a) {
vector<int> b[30];
for (int c = 0; c < a; c++) {
int d;
cin >> d;
for (int e = 0; e < d; e++) {
int f;
cin >> f;
f--;
b[f].push_back(c);
}
}
for (int c = 0; c < 30; c++) {
bool e[30]{};
if (b[c].size())
e[b[c][0]] = true;
for (int d = c; d >= 0; d--) {
bool f = false;
for (int g = 0; g < b[d].size(); g++) {
if (e[b[d][g]])
f = true;
}
if (f) {
for (int g = 0; g < b[d].size(); g++) {
e[b[d][g]] = true;
}
}
}
bool k = true;
for (int i = 0; i < a; i++) {
if (!e[i])
k = false;
}
if (k) {
cout << c + 1 << endl;
goto l;
}
}
puts("-1");
l:;
}
} | #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
while (cin >> a, a) {
vector<int> b[30];
for (int c = 0; c < a; c++) {
int d;
cin >> d;
for (int e = 0; e < d; e++) {
int f;
cin >> f;
f--;
b[f].push_back(c);
}
}
for (int c = 0; c < 30; c++) {
bool e[50]{};
if (b[c].size())
e[b[c][0]] = true;
for (int d = c; d >= 0; d--) {
bool f = false;
for (int g = 0; g < b[d].size(); g++) {
if (e[b[d][g]])
f = true;
}
if (f) {
for (int g = 0; g < b[d].size(); g++) {
e[b[d][g]] = true;
}
}
}
bool k = true;
for (int i = 0; i < a; i++) {
if (!e[i])
k = false;
}
if (k) {
cout << c + 1 << endl;
goto l;
}
}
puts("-1");
l:;
}
} | replace | 28 | 29 | 28 | 29 | 0 | |
p01136 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int N;
int main() {
for (; scanf("%d", &N), N;) {
set<int> dp[35];
vector<int> D[35];
for (int i = 0; i < N; i++) {
int t, d;
dp[i].insert(i);
scanf("%d", &t);
for (int j = 0; j < t; j++) {
scanf("%d", &d);
D[d].push_back(i);
}
}
for (int i = 0; i < 31; i++) {
set<int> a;
for (int j = 0; j < D[i].size(); j++) {
for (set<int>::iterator it = dp[D[i][j]].begin();
it != dp[D[i][j]].end(); it++)
a.insert(*it);
}
if (a.size() == N) {
printf("%d\n", i);
goto e;
}
for (int j = 0; j < D[i].size(); j++)
dp[D[i][j]] = a;
}
puts("-1");
e:;
}
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int N;
int main() {
for (; scanf("%d", &N), N;) {
set<int> dp[99];
vector<int> D[99];
for (int i = 0; i < N; i++) {
int t, d;
dp[i].insert(i);
scanf("%d", &t);
for (int j = 0; j < t; j++) {
scanf("%d", &d);
D[d].push_back(i);
}
}
for (int i = 0; i < 31; i++) {
set<int> a;
for (int j = 0; j < D[i].size(); j++) {
for (set<int>::iterator it = dp[D[i][j]].begin();
it != dp[D[i][j]].end(); it++)
a.insert(*it);
}
if (a.size() == N) {
printf("%d\n", i);
goto e;
}
for (int j = 0; j < D[i].size(); j++)
dp[D[i][j]] = a;
}
puts("-1");
e:;
}
} | replace | 20 | 22 | 20 | 22 | 0 | |
p01136 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(), (X).end()
using namespace std;
const int INF = 1000000000;
const double eps = 1e-8;
/*
int root(vector<int> & ufa,int i)
{
if(i != ufa[i])
ufa[i] = root(ufa,ufa[i]);
return ufa[i];
}
void join(vector<int> & ufa,int i,int j)
{
int ri = root(ufa,i);
int rj = root(ufa,j);
ufa[ri] = rj;
}
*/
struct edge {
int s;
int t;
};
int main(void) {
while (1) {
int n;
cin >> n;
if (!n)
break;
vector<vector<int>> ary(n);
vector<int> l(n);
int gsize = 30 + n;
vector<vector<int>> dist(gsize, vector<int>(gsize, INF));
REP(i, n) {
cin >> l[i];
ary[i] = vector<int>(l[i]);
REP(j, l[i]) cin >> ary[i][j];
sort(ALL(ary[i]));
dist[i][n + ary[i][0] - 1] = 1;
FOR(j, 1, l[i]) { dist[n + ary[i][j - 1] - 1][n + ary[i][j] - 1] = 1; }
}
REP(i, gsize)
REP(j, gsize) REP(k, gsize) dist[j][k] =
min(dist[j][k], dist[j][i] + dist[i][k]);
int days = -1;
REP(i, 30) {
bool flg = true;
REP(j, n) {
if (dist[j][n + i] >= INF) {
flg = false;
break;
}
}
if (flg) {
days = i + 1;
break;
}
}
cout << days << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(), (X).end()
using namespace std;
const int INF = 1000000000;
const double eps = 1e-8;
/*
int root(vector<int> & ufa,int i)
{
if(i != ufa[i])
ufa[i] = root(ufa,ufa[i]);
return ufa[i];
}
void join(vector<int> & ufa,int i,int j)
{
int ri = root(ufa,i);
int rj = root(ufa,j);
ufa[ri] = rj;
}
*/
struct edge {
int s;
int t;
};
int main(void) {
while (1) {
int n;
cin >> n;
if (!n)
break;
vector<vector<int>> ary(n);
vector<int> l(n);
int gsize = 30 + n;
vector<vector<int>> dist(gsize, vector<int>(gsize, INF));
REP(i, n) {
cin >> l[i];
ary[i] = vector<int>(l[i]);
REP(j, l[i]) cin >> ary[i][j];
sort(ALL(ary[i]));
if (l[i])
dist[i][n + ary[i][0] - 1] = 1;
FOR(j, 1, l[i]) { dist[n + ary[i][j - 1] - 1][n + ary[i][j] - 1] = 1; }
}
REP(i, gsize)
REP(j, gsize) REP(k, gsize) dist[j][k] =
min(dist[j][k], dist[j][i] + dist[i][k]);
int days = -1;
REP(i, 30) {
bool flg = true;
REP(j, n) {
if (dist[j][n + i] >= INF) {
flg = false;
break;
}
}
if (flg) {
days = i + 1;
break;
}
}
cout << days << endl;
}
return 0;
} | replace | 59 | 60 | 59 | 61 | 0 | |
p01136 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
using namespace std;
typedef long long STATES;
int main(void) {
STATES free_days[31], dp[51], goal_state, next;
STATES *p;
short int i, j, n, answer, free_day, k;
while (scanf("%d", &n) == 1 && n) {
memset(free_days, 0, sizeof(free_days));
memset(dp, 0, sizeof(dp));
goal_state = 0;
for (i = 0; i < n; i++)
goal_state |= 1LL << i;
for (i = 0; i < n; i++) {
scanf("%d", &k);
for (j = 0; j < k; j++) {
scanf("%d", &free_day);
free_days[free_day] |= 1LL << i;
}
}
answer = -1;
for (i = 0; i < n; i++)
dp[i] = 1LL << i;
p = free_days + 1;
for (i = 1; i <= 30; i++, p++) {
next = 0;
for (j = 0; j < n; j++)
if (*p & 1LL << j)
next |= dp[j];
if (next == goal_state) {
answer = i;
break;
}
for (j = 0; j < n; j++)
if (*p & 1LL << j)
dp[j] |= next;
}
printf("%d\n", answer);
}
return 0;
} | #include <cstdio>
#include <cstring>
using namespace std;
typedef long long STATES;
int main(void) {
STATES free_days[31], dp[51], goal_state, next;
STATES *p;
int i, j, n, free_day, k;
short answer;
while (scanf("%d", &n) == 1 && n) {
memset(free_days, 0, sizeof(free_days));
memset(dp, 0, sizeof(dp));
goal_state = 0;
for (i = 0; i < n; i++)
goal_state |= 1LL << i;
for (i = 0; i < n; i++) {
scanf("%d", &k);
for (j = 0; j < k; j++) {
scanf("%d", &free_day);
free_days[free_day] |= 1LL << i;
}
}
answer = -1;
for (i = 0; i < n; i++)
dp[i] = 1LL << i;
p = free_days + 1;
for (i = 1; i <= 30; i++, p++) {
next = 0;
for (j = 0; j < n; j++)
if (*p & 1LL << j)
next |= dp[j];
if (next == goal_state) {
answer = i;
break;
}
for (j = 0; j < n; j++)
if (*p & 1LL << j)
dp[j] |= next;
}
printf("%d\n", answer);
}
return 0;
} | replace | 9 | 10 | 9 | 11 | 0 | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
while (1) {
int e;
cin >> e;
if (e == 0)
break;
int ans = e + 1;
for (int x = 0; x * x <= e; x++)
for (int y = 0; y * y <= e; y++)
for (int z = 0; z * z * z <= e; z++)
if (x + y * y + z * z * z == e)
ans = min(ans, x + y + z);
cout << ans << endl;
}
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
while (1) {
int e;
cin >> e;
if (e == 0)
break;
int ans = e + 1;
for (int y = 0; y * y <= e; y++)
for (int z = 0; z * z * z <= e; z++)
if (y * y + z * z * z <= e)
ans = min(ans, e - y * y - z * z * z + y + z);
cout << ans << endl;
}
} | replace | 11 | 16 | 11 | 15 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9 + 7)
#define PI 3.1415926535897932384
template <class T> ostream &operator<<(std::ostream &o, const vector<T> &v) {
rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; }
return o;
}
int main() {
int e, n = 1000000;
while (1) {
cin >> e;
int mi = INF;
if (e == 0)
break;
for (int i = 0; i <= e; i++) {
for (int j = 0; j * j <= (e - i * i * i); j++) {
if (j * j + i * i * i > e)
break;
int x = e - (j * j + i * i * i);
if (mi > (i + j + x)) {
mi = i + j + x;
}
}
}
cout << mi << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9 + 7)
#define PI 3.1415926535897932384
template <class T> ostream &operator<<(std::ostream &o, const vector<T> &v) {
rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; }
return o;
}
int main() {
int e, n = 1000000;
while (1) {
cin >> e;
int mi = INF;
if (e == 0)
break;
for (int i = 0; i * i * i <= e; i++) {
for (int j = 0; j * j <= (e - i * i * i); j++) {
if (j * j + i * i * i > e)
break;
int x = e - (j * j + i * i * i);
if (mi > (i + j + x)) {
mi = i + j + x;
}
}
}
cout << mi << endl;
}
}
| replace | 37 | 38 | 37 | 38 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
int e;
while (cin >> e, e) {
int m = e;
for (int z = 0; pow(z, 3) <= e; ++z) {
for (int y = 0; pow(y, 2) <= e - pow(z, 3); ++y) {
int x = e - pow(y, 2) - pow(z, 3);
m = min(m, x + y + z);
}
}
cout << m << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
int e;
while (cin >> e, e) {
int m = e;
for (int z = 0; z * z * z <= e; ++z) {
for (int y = 0; y * y <= e - z * z * z; ++y) {
int x = e - y * y - z * z * z;
m = min(m, x + y + z);
}
}
cout << m << endl;
}
return 0;
}
| replace | 16 | 19 | 16 | 19 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
#include <math.h>
using namespace std;
int e;
int main() {
for (;;) {
cin >> e;
;
int m = e;
if (e == 0)
break;
for (int y = 0; pow(y, 2) <= e; y++) {
for (int z = 0; pow(y, 2) + pow(z, 3) <= e; z++) {
int x = e - pow(z, 3) - pow(y, 2);
if (x + y + z < m) {
m = x + y + z;
}
}
}
cout << m << endl;
}
} | #include <iostream>
#include <math.h>
using namespace std;
int e;
int main() {
for (;;) {
cin >> e;
;
int m = e;
if (e == 0)
break;
for (int y = 0; y * y <= e; y++) {
for (int z = 0; y * y + z * z * z <= e; z++) {
int x = e - z * z * z - y * y;
if (x + y + z < m) {
m = x + y + z;
}
}
}
cout << m << endl;
}
} | replace | 11 | 14 | 11 | 14 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int ret = 1e6;
for (int z = 0; z <= e; ++z) {
int y = (int)pow(e - z * z * z, 1.0 / 2.0);
int x = e - z * z * z - y * y;
ret = min(ret, x + y + z);
}
cout << ret << endl;
}
return 0;
} | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int ret = 1e6;
for (int z = 0; z * z * z <= e; ++z) {
int y = (int)pow(e - z * z * z, 1.0 / 2.0);
int x = e - z * z * z - y * y;
ret = min(ret, x + y + z);
}
cout << ret << endl;
}
return 0;
} | replace | 7 | 8 | 7 | 8 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int num;
int ans = 1e9;
for (int i = 0; i < e; i++) {
for (int j = 0; j < e; j++) {
num = e - i * i * i - j * j;
if (num < 0)
break;
ans = min(ans, num + i + j);
}
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int num;
int ans = 1e9;
for (int i = 0; i < e; i++) {
if (i * i * i > e)
break;
for (int j = 0; j < e; j++) {
num = e - i * i * i - j * j;
if (num < 0)
break;
ans = min(ans, num + i + j);
}
}
cout << ans << endl;
}
} | insert | 9 | 9 | 9 | 11 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define inf 1000000000
using namespace std;
int e;
int yy(int a) {
int i = 0;
while (i * i <= a) {
if (i * i == a)
return i;
i++;
}
return inf;
}
int zzz(int a) {
int i = 0;
while (i * i * i <= a) {
if (i * i * i == a)
return i;
i++;
}
return inf;
}
int main() {
while (cin >> e, e) {
int ans = inf;
for (int i = 0; i <= e; i++) {
for (int j = 0; j <= e; j++) {
if (i + j <= e) {
ans = min(ans, i + yy(j) + zzz(e - i - j));
}
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define inf 1000000000
using namespace std;
int e;
int yy(int a) {
int i = 0;
while (i * i <= a) {
if (i * i == a)
return i;
i++;
}
return inf;
}
int zzz(int a) {
int i = 0;
while (i * i * i <= a) {
if (i * i * i == a)
return i;
i++;
}
return inf;
}
int main() {
while (cin >> e, e) {
int ans = inf;
for (int i = 0; i * i * i <= e; i++) {
for (int j = 0; j * j <= e; j++) {
if (i * i * i + j * j <= e) {
ans = min(ans, i + j + (e - i * i * i - j * j));
}
}
}
cout << ans << endl;
}
return 0;
} | replace | 31 | 35 | 31 | 35 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()
typedef long long ll;
int main() {
ll e;
while (cin >> e, e) {
ll m = e;
for (int y = 0; y * y <= e; y++) {
for (int z = 0; z * z * z + y * y <= e; z++) {
m = min(m, y + z + (e - (ll)pow(y, 2) - (ll)pow(z, 3)));
}
}
cout << m << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()
typedef long long ll;
int main() {
ll e;
while (cin >> e, e) {
ll m = e;
for (int y = 0; y * y <= e; y++) {
for (int z = 0; z * z * z + y * y <= e; z++) {
m = min(m, y + z + (e - y * y - z * z * z));
}
}
cout << m << endl;
}
}
| replace | 19 | 20 | 19 | 20 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int e, ans;
while (cin >> e && e != 0) {
ans = 1000000;
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; z * z * z + y * y <= e; y++) {
for (int x = 0; z * z * z + y * y + x <= e; x++) {
if (z * z * z + y * y + x == e && x + y + z < ans)
ans = x + y + z;
}
}
}
cout << ans << endl;
}
} | #include <iostream>
using namespace std;
int main() {
int e, ans;
while (cin >> e && e != 0) {
ans = 1000000;
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; z * z * z + y * y <= e; y++) {
int x = e - z * z * z - y * y;
if (x + y + z < ans)
ans = x + y + z;
}
}
cout << ans << endl;
}
} | replace | 9 | 13 | 9 | 12 | TLE | |
p01137 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
int e;
while (cin >> e, e) {
int m = 20000000;
int x, y, z;
for (z = 0; (int)pow(z, 3) <= e; z++) {
for (y = 0; (int)pow(y, 2) + (int)pow(z, 3) <= e; y++) {
x = e - ((int)pow(y, 2) + (int)pow(z, 3));
m = min(m, x + y + z);
}
}
cout << m << endl;
}
return 0;
} | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
int e;
while (cin >> e, e) {
int m = 20000000;
int x, y, z;
for (z = 0; z * z * z <= e; z++) {
for (y = 0; y * y + z * z * z <= e; y++) {
x = e - (y * y + z * z * z);
m = min(m, x + y + z);
}
}
cout << m << endl;
}
return 0;
} | replace | 11 | 14 | 11 | 14 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int e;
while (cin >> e, e) {
int x, y, z;
int ans = INT_MAX;
for (z = 0; z <= pow(e, 1.0 / 3.0); z++) {
for (y = 0; y <= sqrt(e); y++) {
if (pow(z, 3) + pow(y, 2) > e)
break;
ans = min(ans, (int)(z + y + (e - pow(y, 2) - pow(z, 3))));
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int e;
while (cin >> e, e) {
int x, y, z;
int ans = INT_MAX;
for (z = 0; z * z * z <= e; z++) {
y = sqrt(e - pow(z, 3));
x = e - pow(z, 3) - pow(y, 2);
ans = min(ans, x + y + z);
}
cout << ans << endl;
}
return 0;
} | replace | 10 | 16 | 10 | 14 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
#define INF 9999999
int main() {
int e;
while (cin >> e, e) {
// x+y^2+z^3=e
int ans = INF;
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; (y * y) + (z * z * z) <= e; y++) {
for (int x = 0; x + (y * y) + (z * z * z) <= e; x++) {
if (x + (y * y) + (z * z * z) == e)
ans = min(ans, x + y + z);
}
}
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
#define INF 9999999
int main() {
int e;
while (cin >> e, e) {
// x+y^2+z^3=e
int ans = INF;
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; (y * y) + (z * z * z) <= e; y++) {
ans = min(ans, e - y * y - z * z * z + y + z);
}
}
cout << ans << endl;
}
return 0;
} | replace | 14 | 18 | 14 | 15 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int e;
while (cin >> e && e) {
int m = 1 << 30, tmp;
for (int x = 0; x <= 1000000 && x <= e; x++) {
for (int y = 0; y <= 1000 && (x + y * y) <= e; y++) {
for (int z = 0; z <= 100 && (x + y * y + z * z * z) <= e; z++) {
if ((x + y * y + z * z * z) == e)
m = min(m, x + y + z);
}
}
}
cout << m << endl;
}
} | #include <iostream>
using namespace std;
int main() {
int e;
while (cin >> e && e) {
int m = 1 << 30;
for (int y = 0; y <= 1000; y++) {
for (int z = 0; z <= 100; z++) {
int x = e - y * y - z * z * z;
if (x >= 0)
m = min(m, x + y + z);
}
}
cout << m << endl;
}
} | replace | 7 | 14 | 7 | 13 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int x, y, z;
int answer = 1000000;
/*for(int i=0;i<=e;i++){
for(int j=0;j<=sqrt(e)-i;j++){
for(int k=0;k<=pow(e,1.0/3.0)-i+pow(j,2.0);k++){
if(i+pow(j,2.0)+pow(k,3.0)==e&&answer>i+j+k){
answer = i+j+k;
}
}
}
}*/
for (int k = 0; k * k * k <= e; k++) {
for (int j = 0; j * j <= e - k * k * k; j++) {
int i = e - j * j - k * k * k;
if (i + pow(j, 2.0) + pow(k, 3.0) == e && answer > i + j + k) {
answer = i + j + k;
}
}
}
cout << answer << endl;
}
return 0;
}
| #include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int x, y, z;
int answer = 1000000;
/*for(int i=0;i<=e;i++){
for(int j=0;j<=sqrt(e)-i;j++){
for(int k=0;k<=pow(e,1.0/3.0)-i+pow(j,2.0);k++){
if(i+pow(j,2.0)+pow(k,3.0)==e&&answer>i+j+k){
answer = i+j+k;
}
}
}
}*/
for (int k = 0; k * k * k <= e; k++) {
for (int j = 0; j * j <= e - k * k * k; j++) {
int i = e - j * j - k * k * k;
if (answer > i + j + k) {
answer = i + j + k;
}
}
}
cout << answer << endl;
}
return 0;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
while (1) {
int e, min = 100000000, ans;
cin >> e;
if (e == 0)
break;
for (int i = 0; i <= e; i++) {
for (int j = 0; j <= e; j++) {
ans = e - (i * i + j * j * j);
if (min > ans + j + i && e >= ans && ans >= 0)
min = ans + i + j;
}
}
cout << min << endl;
}
return 0;
}
| #include <iostream>
using namespace std;
int main() {
while (1) {
int e, min = 100000000, ans;
cin >> e;
if (e == 0)
break;
for (int i = 0; i * i * i <= e; i++) {
for (int j = 0; j * j <= e; j++) {
ans = e - (i * i * i + j * j);
if (min > ans + j + i && e >= ans && ans >= 0)
min = ans + i + j;
}
}
cout << min << endl;
}
return 0;
}
| replace | 9 | 12 | 9 | 12 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int e;
cin >> e;
while (e) {
int x = 0;
int y = 0;
int z = 0;
int m = 0;
for (z = 0; z <= e / 9; z++)
for (y = 0; y <= e / 2; y++) {
x = e - z * z * z - y * y;
if (x < 0)
continue;
int t = x + y + z;
if (m == 0 || m > t)
m = t;
}
cout << m << endl;
cin >> e;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int e;
cin >> e;
while (e) {
int x = 0;
int y = 0;
int z = 0;
int m = 0;
for (z = 0; z * z * z <= e; z++)
for (y = 0; z * z * z + y * y <= e; y++) {
x = e - z * z * z - y * y;
if (x < 0)
continue;
int t = x + y + z;
if (m == 0 || m > t)
m = t;
}
cout << m << endl;
cin >> e;
}
return 0;
}
| replace | 11 | 13 | 11 | 13 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
#include <math.h>
using namespace std;
int solve(int E) {
int ans = E;
for (int z = 0; z * z * z <= E; ++z) {
for (int y = 0; y * y <= E; ++y) {
for (int x = 0; x < E; ++x)
if (x + y * y + z * z * z == E && x + y + z < ans)
ans = x + y + z;
}
}
return ans;
}
int main() {
int E;
while (cin >> E && E > 0) {
cout << solve(E) << endl;
}
} | #include <iostream>
#include <math.h>
using namespace std;
int solve(int E) {
int ans = E;
for (int z = 0; z * z * z <= E; ++z) {
for (int y = 0; y * y <= E; ++y) {
int x = E - y * y - z * z * z;
if (x + y + z < ans && x >= 0)
ans = x + y + z;
}
}
return ans;
}
int main() {
int E;
while (cin >> E && E > 0) {
cout << solve(E) << endl;
}
} | replace | 7 | 10 | 7 | 10 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
while (true) {
int e;
cin >> e;
if (e == 0) {
break;
}
int ans = e;
for (int x = 0; x <= e; x++) {
for (int y = 0; y * y <= e; y++) {
for (int z = 0; z * z * z <= e; z++) {
if (x + y * y + z * z * z == e) {
ans = min(x + y + z, ans);
}
}
}
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
while (true) {
int e;
cin >> e;
if (e == 0) {
break;
}
int ans = e;
for (int y = 0; y * y <= e; y++) {
for (int z = 0; z * z * z <= e; z++) {
if (y * y + z * z * z <= e) {
ans = min(e - y * y - z * z * z + y + z, ans);
}
}
}
cout << ans << endl;
}
return 0;
} | replace | 15 | 21 | 15 | 19 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <cctype>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
int main(int argc, char const *argv[]) {
int e;
while (cin >> e, e) {
int x, y, z;
int m = 1000000;
// for (int i = 0; i <= e; i++)
//{
// for (int j = 0; j*j <= e; j++)
// {
// for (int k = 0; k*k*k <= e; k++)
// {
// //cout << " x y z = " << i << j << k <<endl;
// if ( i + j*j + k*k*k == e)
// {
// m = min( m, i + j + k);
// }
// }
// }
// }
for (int k = 0; 0 <= k * k * k; k++) {
int j = sqrt(e - k * k * k);
int i = e - k * k * k - j * j;
m = min(m, i + j + k);
}
cout << m << endl;
}
return 0;
} | #include <cctype>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
int main(int argc, char const *argv[]) {
int e;
while (cin >> e, e) {
int x, y, z;
int m = 1000000;
// for (int i = 0; i <= e; i++)
//{
// for (int j = 0; j*j <= e; j++)
// {
// for (int k = 0; k*k*k <= e; k++)
// {
// //cout << " x y z = " << i << j << k <<endl;
// if ( i + j*j + k*k*k == e)
// {
// m = min( m, i + j + k);
// }
// }
// }
// }
for (int k = 0; k * k * k <= e; k++) {
int j = sqrt(e - k * k * k);
int i = e - k * k * k - j * j;
m = min(m, i + j + k);
}
cout << m << endl;
}
return 0;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
#define mp(a, b) make_pair(a, b)
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int mini = 1000000;
for (int x = 0; x <= e; x++) {
for (int y = 0; x + y * y <= e; y++) {
for (int z = 0; x + y * y + z * z * z <= e; z++) {
if (x + y * y + z * z * z == e)
mini = min(mini, x + y + z);
}
}
}
p(mini);
}
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
#define mp(a, b) make_pair(a, b)
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int mini = 1000000;
int k;
for (int z = 0; (k = e - z * z * z) >= 0; z++) {
int y = (int)sqrt(k) + 0.00001;
int x = k - y * y;
mini = min(mini, x + y + z);
}
p(mini);
}
return 0;
} | replace | 10 | 17 | 10 | 15 | TLE | |
p01137 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
using namespace std;
bool solve() {
int n;
cin >> n;
if (!n)
return false;
int ans = 1000000;
for (int k = n; k >= 0; k--) {
if ((long long)k * k * k > n)
continue; // long long
for (int j = n; j >= 0; j--) {
if ((long long)j * j + (long long)k * k * k > n)
continue; //
int i = n - j * j - k * k * k;
if (0 <= i && i <= n) {
int m = i + j + k;
ans = min(ans, m);
}
}
}
cout << ans << endl;
return true;
}
int main() {
cout.setf(ios::fixed);
cout.precision(10);
while (solve())
;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
using namespace std;
bool solve() {
int n;
cin >> n;
if (!n)
return false;
int ans = 1000000;
for (int k = 0; k * k * k <= n; k++) {
for (int j = 0; j * j + k * k * k <= n; j++) {
int i = n - j * j - k * k * k;
if (0 <= i && i <= n) {
int m = i + j + k;
ans = min(ans, m);
}
}
}
cout << ans << endl;
return true;
}
int main() {
cout.setf(ios::fixed);
cout.precision(10);
while (solve())
;
return 0;
}
| replace | 24 | 30 | 24 | 26 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int e;
while (scanf("%d", &e) != EOF && e) {
int m = 1000;
for (int z = 100; z >= 0; z--) {
if (e < z * z * z) {
continue;
}
for (int y = 0; y < m; y++) {
if (e < y * y + z * z * z) {
break;
}
for (int x = 0; x < m; x++) {
if (e == x + y * y + z * z * z && x + y + z < m) {
m = x + y + z;
} else if (e < x + y * y + z * z * z) {
break;
}
}
}
}
printf("%d\n", m);
}
} | #include <iostream>
using namespace std;
int main() {
int e;
while (scanf("%d", &e) != EOF && e) {
int m = 1000;
for (int z = 100; z >= 0; z--) {
if (e < z * z * z) {
continue;
}
for (int y = 0; y < m; y++) {
if (e < y * y + z * z * z) {
break;
}
int x = e - y * y - z * z * z;
if (x + y + z < m) {
m = x + y + z;
}
}
}
printf("%d\n", m);
}
} | replace | 15 | 21 | 15 | 18 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
int main() {
int e;
while (1) {
std::cin >> e;
if (!e)
break;
int m = 1000001;
for (int i = 0; i * i * i <= e; i++) {
for (int ii = 0; i * i * i + ii * ii <= e; ii++) {
for (int i3 = 0; i * i * i + ii * ii + i3 <= e; i3++) {
if (i * i * i + ii * ii + i3 == e) {
int tmp = i + ii + i3;
if (tmp < m)
m = tmp;
}
}
}
}
std::cout << m << std::endl;
}
return 0;
} | #include <iostream>
int main() {
int e;
while (1) {
std::cin >> e;
if (!e)
break;
int m = 1000001;
for (int i = 0; i * i * i <= e; i++) {
for (int ii = 0; i * i * i + ii * ii <= e; ii++) {
int x = e - i * i * i - ii * ii;
int tmp = i + ii + x;
if (tmp < m)
m = tmp;
}
}
std::cout << m << std::endl;
}
return 0;
} | replace | 11 | 18 | 11 | 15 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int e;
void solve() {
int m = e;
for (int x = 0; x <= e; x++) {
for (int y = 0; y * y <= e; y++) {
for (int z = 0; z * z * z <= e; z++) {
if (x + y * y + z * z * z == e) {
m = min(m, x + y + z);
}
}
}
}
cout << m << endl;
}
int main() {
while (1) {
cin >> e;
if (e == 0)
break;
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int e;
void solve() {
int m = e;
for (int y = 0; y * y <= e; y++) {
for (int z = 0; z * z * z <= e; z++) {
int x = e - (y * y) - (z * z * z);
if (0 <= x) {
m = min(m, x + y + z);
}
}
}
cout << m << endl;
}
int main() {
while (1) {
cin >> e;
if (e == 0)
break;
solve();
}
return 0;
} | replace | 9 | 15 | 9 | 14 | TLE | |
p01137 | C++ | Time Limit Exceeded | /* 2012-08-20T10:33:30 */
#define DEBUG_ON
#define CONDITION true
using namespace std; /*{{{*/
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <vector>
#define INF (1e9)
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef complex<double> P;
#define FOR(i, b, e) for (typeof(b) i = (b); i != (e); i < (e) ? ++i : --i)
#define REP(i, n) FOR(i, 0, n)
#define IFC(c) \
if (c) \
continue;
#define IFB(c) \
if (c) \
break;
#define IFR(c, r) \
if (c) \
return r;
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n) (1ULL << (n))
#define BITOF(n, m) ((ULL)(n) >> (m)&1)
#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))
#ifdef DEBUG_ON
#define dprt(fmt, ...) \
if (CONDITION) \
fprintf(stderr, fmt, __VA_ARGS__)
#define darr(a) \
if (CONDITION) \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr_range(a, f, t) \
if (CONDITION) \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define dvec(v) \
if (CONDITION) \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr2(a, n, m) \
if (CONDITION) \
FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v) \
if (CONDITION) \
FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT() \
if (CONDITION) { \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#define dump(x) \
if (CONDITION) \
cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;
#define dumpf() \
if (CONDITION) \
cerr << __PRETTY_FUNCTION__ << endl;
#define dumpv(x) \
if (CONDITION) \
cerr << " [L:" << __LINE__ << "] " << #x << " = "; \
REP(q, (x).size()) cerr << (x)[q] << " "; \
cerr << endl;
#define where() \
if (CONDITION) \
cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \
<< "]" << endl;
#define show_bits(b, s) \
if (CONDITION) { \
REP(i, s) { \
cerr << BITOF(b, s - 1 - i); \
if (i % 4 == 3) \
cerr << ' '; \
} \
cerr << endl; \
}
#else
#define cerr \
if (0) \
cerr
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#define dump(x)
#define dumpf()
#define dumpv(x)
#define where()
#define show_bits(b, s)
#endif
inline int bits_count(ULL b) {
int c = 0;
while (b != 0) {
c += (b & 1);
b >>= 1;
}
return c;
}
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
}
inline VS split(string s, char delimiter) {
VS v;
string t;
REP(i, s.length()) {
IFC(s[i] == ' ');
if (s[i] == delimiter)
v.PB(t), t = "";
else
t += s[i];
}
v.PB(t);
return v;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
/*}}}*/
int main() {
ULL e;
while (cin >> e, e) {
int ans = INF;
FOR(i, 0, (int)cbrt(e) + 1) {
FOR(j, 0, (int)sqrt(e) + 1) {
int k = e - pow(i, 3) - pow(j, 2);
if (k >= 0) {
ans = min(ans, i + j + k);
}
}
}
cout << ans << endl;
}
} | /* 2012-08-20T10:33:30 */
#define DEBUG_ON
#define CONDITION true
using namespace std; /*{{{*/
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <vector>
#define INF (1e9)
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef complex<double> P;
#define FOR(i, b, e) for (typeof(b) i = (b); i != (e); i < (e) ? ++i : --i)
#define REP(i, n) FOR(i, 0, n)
#define IFC(c) \
if (c) \
continue;
#define IFB(c) \
if (c) \
break;
#define IFR(c, r) \
if (c) \
return r;
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n) (1ULL << (n))
#define BITOF(n, m) ((ULL)(n) >> (m)&1)
#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))
#ifdef DEBUG_ON
#define dprt(fmt, ...) \
if (CONDITION) \
fprintf(stderr, fmt, __VA_ARGS__)
#define darr(a) \
if (CONDITION) \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr_range(a, f, t) \
if (CONDITION) \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define dvec(v) \
if (CONDITION) \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr2(a, n, m) \
if (CONDITION) \
FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v) \
if (CONDITION) \
FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT() \
if (CONDITION) { \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#define dump(x) \
if (CONDITION) \
cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;
#define dumpf() \
if (CONDITION) \
cerr << __PRETTY_FUNCTION__ << endl;
#define dumpv(x) \
if (CONDITION) \
cerr << " [L:" << __LINE__ << "] " << #x << " = "; \
REP(q, (x).size()) cerr << (x)[q] << " "; \
cerr << endl;
#define where() \
if (CONDITION) \
cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \
<< "]" << endl;
#define show_bits(b, s) \
if (CONDITION) { \
REP(i, s) { \
cerr << BITOF(b, s - 1 - i); \
if (i % 4 == 3) \
cerr << ' '; \
} \
cerr << endl; \
}
#else
#define cerr \
if (0) \
cerr
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#define dump(x)
#define dumpf()
#define dumpv(x)
#define where()
#define show_bits(b, s)
#endif
inline int bits_count(ULL b) {
int c = 0;
while (b != 0) {
c += (b & 1);
b >>= 1;
}
return c;
}
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
}
inline VS split(string s, char delimiter) {
VS v;
string t;
REP(i, s.length()) {
IFC(s[i] == ' ');
if (s[i] == delimiter)
v.PB(t), t = "";
else
t += s[i];
}
v.PB(t);
return v;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
/*}}}*/
int main() {
ULL e;
while (cin >> e, e) {
int ans = INF;
for (int i = 0; i * i * i <= e; i++) {
for (int j = 0; j * j <= e - i; j++) {
int k = e - i * i * i - j * j;
if (k >= 0) {
ans = min(ans, i + j + k);
}
}
}
cout << ans << endl;
}
} | replace | 197 | 200 | 197 | 200 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
const int INF = 10000000;
using namespace std;
typedef long long ll;
const int MAX = 10000;
/** Problem2012 : Space Coconut Grab **/
int main() {
int e;
int m = INF;
while (cin >> e, e != 0) {
m = INF;
rep(i, 150) {
rep(j, 150) {
rep(k, 150) {
if (i + j * j + k * k * k == e) {
if (m > i + j + k) {
m = i + j + k;
}
}
}
}
}
cout << m << endl;
}
return 0;
} | #include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
const int INF = 10000000;
using namespace std;
typedef long long ll;
const int MAX = 10000;
/** Problem2012 : Space Coconut Grab **/
int main() {
int e;
int m = INF;
while (cin >> e, e != 0) {
m = INF;
REP(i, 0, 1000) {
REP(j, 0, 1000) {
if (e - i * i - j * j * j >= 0) {
int t = e - i * i - j * j * j + i + j;
if (t < m)
m = t;
}
}
}
cout << m << endl;
}
return 0;
} | replace | 17 | 25 | 17 | 23 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
for (int x = 0; x <= e; x++)
for (int y = 0; y <= e; y++)
for (int z = 0; z <= e; z++)
if (x + y * y + z * z * z == e) {
cout << x + y + z << endl;
goto out;
}
out:;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int e;
while (cin >> e, e) {
int min_a = 1000000;
int z_, y_;
for (int z = 0; z * z * z <= e; z++)
for (int y = 0; y * y + z * z * z <= e; y++) {
if (min_a > z + y + e - y * y - z * z * z) {
min_a = z + y + e - y * y - z * z * z;
z_ = z;
y_ = y;
}
}
cout << e - y_ * y_ - z_ * z_ * z_ + y_ + z_ << endl;
}
return 0;
} | replace | 8 | 16 | 8 | 20 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main() {
int e;
while (cin >> e && e != 0) {
int m = 214214, x = 0;
rep(z, 1000) rep(y, 10000) {
x = e - (y * y + z * z * z);
if (e == x + (y * y) + (z * z * z) && x >= 0) {
m = min(x + y + z, m);
}
}
printf("%d\n", m);
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main() {
int e;
while (cin >> e && e != 0) {
int m = 214214, x = 0;
rep(z, 111) rep(y, 1111) {
x = e - (y * y + z * z * z);
if (e == x + (y * y) + (z * z * z) && x >= 0) {
m = min(x + y + z, m);
}
}
printf("%d\n", m);
}
return 0;
} | replace | 13 | 14 | 13 | 14 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 999999999
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
/*---------------------------------------------------*/
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
int mini = INF;
rep(y, sqrt(n)) {
rep(z, sqrt(n)) {
int x = n - pow(y, 2) - pow(z, 3);
if (x < 0)
continue;
// cout<<x<<" "<<y<<" "<<z<<endl;
mini = min(mini, x + y + z);
}
}
cout << mini << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 999999999
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
/*---------------------------------------------------*/
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
int mini = INF;
for (int y = 0; y * y <= n; y++) {
for (int z = 0; z * z * z <= n; z++) {
int x = n - y * y - z * z * z;
if (x < 0)
continue;
// cout<<x<<" "<<y<<" "<<z<<endl;
mini = min(mini, x + y + z);
}
}
cout << mini << endl;
}
return 0;
} | replace | 36 | 39 | 36 | 39 | TLE | |
p01137 | 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 rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int e;
while (cin >> e, e) {
int m = 99999999;
for (int x = 0; x <= e; x++) {
for (int y = 0; x + y * y <= e; y++) {
for (int z = 0; x + y * y + z * z * z <= e; z++) {
if (x + y * y + z * z * z == e) {
m = min(m, x + y + z);
}
}
}
}
cout << m << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int e;
while (cin >> e, e) {
int m = 99999999;
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; y * y + z * z * z <= e; y++) {
int x = e - (y * y + z * z * z);
m = min(m, x + y + z);
}
}
cout << m << endl;
}
} | replace | 24 | 31 | 24 | 28 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int e;
while (scanf("%d", &e), e) {
int m = 1 << 25;
for (int i = 0; i <= e; i++) {
for (int j = 0; i + j * j <= e; j++) {
for (int k = 0; i + j * j + k * k * k <= e; k++) {
if (i + j * j + k * k * k == e) {
m = min(m, i + j + k);
}
}
}
}
printf("%d\n", m);
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int e;
while (scanf("%d", &e), e) {
int m = 1 << 25;
for (int i = 0; i * i * i <= e; i++) {
for (int j = 0; i * i * i + j * j <= e; j++) {
int val = i * i * i + j * j;
m = min(m, i + j + (e - val));
}
}
printf("%d\n", m);
}
return 0;
} | replace | 8 | 15 | 8 | 12 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, m) for (long long i = 0; i < m; i++)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>
int main() {
while (true) {
int n;
cin >> n;
if (n == 0)
return 0;
ll ans = INF;
REP(i, (int)pow(n, 0.335) + 1) {
REP(j, (int)pow((n - i * i * i), 0.5) + 1) {
int k = n - (i * i * i) - (j * j);
if (k >= 0 && i + j + k < ans)
ans = i + j + k;
}
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, m) for (long long i = 0; i < m; i++)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>
int main() {
while (true) {
int n;
cin >> n;
if (n == 0)
return 0;
ll ans = INF;
REP(i, (int)pow(n, 0.335) + 1) {
if (n < i * i * i)
break;
int j = (int)pow(n - i * i * i, 0.5);
if (ans > i + j + (n - i * i * i - j * j)) {
ans = i + j + (n - i * i * i - j * j);
}
}
cout << ans << endl;
}
return 0;
}
| replace | 21 | 25 | 21 | 26 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int INF = 10000000;
int cast(int e) {
int Min = INF;
for (int i = 0; pow(i, 3) <= e; i++) {
for (int j = 0; pow(j, 2) <= e - pow(i, 3); j++) {
int k = e - pow(i, 3) - pow(j, 2);
if (k >= 0) {
Min = min(i + j + k, Min);
} else {
break;
}
}
}
return Min;
}
int main() {
while (1) {
int e;
cin >> e;
if (!e)
break;
cout << cast(e) << endl;
}
return 0;
} | #include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int INF = 10000000;
int cast(int e) {
int Min = INF;
for (int i = 0; i * i * i <= e; i++) {
for (int j = 0; j * j <= e - i * i * i; j++) {
int k = e - i * i * i - j * j;
if (k >= 0) {
Min = min(i + j + k, Min);
} else {
break;
}
}
}
return Min;
}
int main() {
while (1) {
int e;
cin >> e;
if (!e)
break;
cout << cast(e) << endl;
}
return 0;
} | replace | 12 | 15 | 12 | 15 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define per(i, n) for (int i = n; i >= 0; i--)
#define ROF(i, s, n) for (int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) \
for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[] = {0, -1, 0, 1, 1, 1, -1, -1};
int n;
int main() {
while (~scanf("%d", &n) && n) {
int ans = n;
for (int i = n - 1; i >= 0; i--) {
if (i * i * i > n) {
continue;
}
for (int j = sqrt(n - i * i * i); j >= 0; j--) {
if (i * i * i + j * j > n) {
continue;
}
ans = min(ans, i + j + (n - (i * i * i + j * j)));
}
}
printf("%d\n", ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define per(i, n) for (int i = n; i >= 0; i--)
#define ROF(i, s, n) for (int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) \
for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[] = {0, -1, 0, 1, 1, 1, -1, -1};
int n;
int main() {
while (~scanf("%d", &n) && n) {
int ans = n;
for (int i = 0; i * i * i <= n; i++) {
int j = sqrt(n - i * i * i);
ans = min(ans, i + j + (n - (i * i * i + j * j)));
}
printf("%d\n", ans);
}
return 0;
} | replace | 45 | 55 | 45 | 48 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int E, X, tempmin;
int min;
while (true) {
cin >> E;
if (E == 0) {
break;
}
min = 1000000;
for (int Z = 0; Z * Z * Z <= E; Z++) {
for (int Y = 0; Y * Y <= (E - Z * Z * Z); Y++) {
X = E - Y * Y - Z * Z * Z;
tempmin = X + Y + Z;
cout << X << " " << Y << " " << Z << endl;
// cout << tempmin << endl;
if ((tempmin < min) && (X + Y * Y + Z * Z * Z == E)) {
min = tempmin;
}
}
}
cout << min << endl;
}
return 0;
} | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int E, X, tempmin;
int min;
while (true) {
cin >> E;
if (E == 0) {
break;
}
min = 1000000;
for (int Z = 0; Z * Z * Z <= E; Z++) {
for (int Y = 0; Y * Y <= (E - Z * Z * Z); Y++) {
X = E - Y * Y - Z * Z * Z;
tempmin = X + Y + Z;
// cout << X << " " << Y << " " << Z << endl;
// cout << tempmin << endl;
if ((tempmin < min) && (X + Y * Y + Z * Z * Z == E)) {
min = tempmin;
}
}
}
cout << min << endl;
}
return 0;
} | replace | 19 | 20 | 19 | 20 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main(void) {
for (;;) {
int e;
cin >> e;
int m = 1 << 26;
if (e == 0) {
return 0;
}
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; y * y + z * z * z <= e; y++) {
for (int x = 0; x + y * y + z * z * z <= e; x++) {
if (x + y * y + z * z * z == e && x + y + z < m) {
m = x + y + z;
}
}
}
}
cout << m << endl;
}
}
| #include <iostream>
using namespace std;
int main(void) {
for (;;) {
int e;
cin >> e;
int m = 1 << 26;
if (e == 0) {
return 0;
}
for (int z = 0; z * z * z <= e; z++) {
for (int y = 0; y * y + z * z * z <= e; y++) {
int x = e - y * y - z * z * z;
if (x + y + z < m) {
m = x + y + z;
}
}
}
cout << m << endl;
}
}
| replace | 12 | 16 | 12 | 15 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int E;
int main() {
while (cin >> E && E > 0) {
int m = 500;
for (int z = 0; z <= cbrt(E); z++) {
if (z >= m)
break;
for (int y = 0; y <= sqrt(E - pow(z, 3)); y++) {
if (y + z >= m)
break;
int x = E - pow(z, 3) - pow(y, 2);
if (x >= 0) {
if (x + y + z < m) {
m = x + y + z;
}
}
}
}
cout << m << endl;
}
} | #include <cmath>
#include <iostream>
using namespace std;
int E;
int main() {
while (cin >> E && E > 0) {
int m = 1000000;
for (int z = 0; z * z * z <= E; z++) {
// if(z >= m) break;
for (int y = 0; y * y <= E - z * z * z; y++) {
// if (y+z >= m) break;
int x = E - z * z * z - y * y;
if (x >= 0) {
if (x + y + z < m) {
m = x + y + z;
}
}
}
}
cout << m << endl;
}
} | replace | 6 | 14 | 6 | 12 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int e, m, a;
while (1) {
cin >> e;
m = e;
if (e == 0) {
return 0;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m - i; j++) {
a = e - i * (i - 1) - j * (j - 1) * (j + 1);
if ((a >= i + j) && (m > a) && (a >= 0)) {
m = e - i * (i - 1) - j * (j - 1) * (j + 1);
}
}
}
cout << m << "\n";
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int e, m, a;
while (1) {
cin >> e;
m = e;
if (e == 0) {
return 0;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m - i; j++) {
a = e - i * (i - 1) - j * (j - 1) * (j + 1);
if ((a >= i + j) && (m > a) && (a >= 0)) {
m = e - i * (i - 1) - j * (j - 1) * (j + 1);
}
if (a < 0) {
break;
}
}
}
cout << m << "\n";
}
return 0;
} | insert | 23 | 23 | 23 | 26 | TLE | |
p01137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> pii;
int main() {
int e;
while (1) {
cin >> e;
if (e == 0)
break;
int ans = INF;
int x, y, z;
rep(z, e + 1) rep(y, e - z * z * z + 1) {
x = e - z * z * z - y * y;
ans = min(ans, x + y + z);
}
cout << ans << endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> pii;
int main() {
int e;
while (1) {
cin >> e;
if (e == 0)
break;
int ans = INF;
int x, y, z;
for (z = 0; z * z * z <= e; z++)
for (y = 0; z * z * z + y * y <= e; y++) {
x = e - z * z * z - y * y;
ans = min(ans, x + y + z);
}
cout << ans << endl;
}
} | replace | 29 | 33 | 29 | 34 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.