buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
string s;
cin >> s;
int ansj = 0, ansi = 0;
;
for (int i = 0; i < s.length() - 2; i++) {
if (s.substr(i, 3) == "JOI")
ansj++;
if (s.substr(i, 3) == "IOI")
ansi++;
}
std::cout << ansj << std::endl;
std::cout << ansi << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
string s;
while (cin >> s) {
int ansj = 0, ansi = 0;
for (int i = 0; i < s.length() - 2; i++) {
if (s.substr(i, 3) == "JOI")
ansj++;
if (s.substr(i, 3) == "IOI")
ansi++;
}
std::cout << ansj << std::endl;
std::cout << ansi << std::endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 118
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
string joi = "JOI", ioi = "IOI";
int num_joi = 0, num_ioi = 0;
for (int i = 0; i < s.size() - 2; i++) {
string sub = s.substr(i, 3);
if (sub == joi)
num_joi++;
if (sub == ioi)
num_ioi++;
}
cout << num_joi << "\n" << num_ioi << "\n";
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
while (cin >> s) {
string joi = "JOI", ioi = "IOI";
int num_joi = 0, num_ioi = 0;
for (int i = 0; i < s.size() - 2; i++) {
string sub = s.substr(i, 3);
if (sub == joi)
num_joi++;
if (sub == ioi)
num_ioi++;
}
cout << num_joi << "\n" << num_ioi << "\n";
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 109
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF_LL 9000000000000000000
#define INF 2000000000
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;
class Union_find {
private:
vector<int> par;
vector<int> rank;
int n;
public:
Union_find(int a) {
n = a;
for (int i = 0; i < n; i++) {
par.push_back(i);
rank.push_back(0);
}
}
int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
int main(void) {
int n, k;
while (cin >> n >> k && n && k) {
vector<int> input;
vector<pair<pair<int, int>, ll>> con;
bool there0 = false;
REP(i, k) {
int a;
cin >> a;
if (a == 0)
there0 = true;
else
input.push_back(a);
}
sort(input.begin(), input.end());
int s = 0, e = 1, sz = 1;
REP(i, input.size() - 1) {
if (input[e] - input[s] <= 1) {
sz++;
e++;
} else {
con.push_back({{input[s], input[e - 1]}, sz});
s = e;
e++;
sz = 1;
}
}
con.push_back({{input[s], input[e - 1]}, sz});
if (con.size() == 1) {
int res = con[0].second;
if (1 < con[0].first.first || con[0].first.second < n) {
if (there0)
res++;
}
cout << res << endl;
continue;
}
ll res = 0;
REP(i, con.size() - 1) {
int sa = con[i + 1].first.first - con[i].first.second;
if (sa == 2 && there0) {
res = max(res, con[i].second + con[i + 1].second + 1);
} else if (there0) {
res = max(res, con[i].second + 1);
} else {
res = max(res, con[i].second);
}
}
if (there0) {
res = max(res, con[con.size() - 1].second + 1);
} else {
res = max(res, con[con.size() - 1].second);
}
cout << res << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF_LL 9000000000000000000
#define INF 2000000000
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;
class Union_find {
private:
vector<int> par;
vector<int> rank;
int n;
public:
Union_find(int a) {
n = a;
for (int i = 0; i < n; i++) {
par.push_back(i);
rank.push_back(0);
}
}
int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
int main(void) {
int n, k;
while (cin >> n >> k && n && k) {
vector<int> input;
vector<pair<pair<int, int>, ll>> con;
bool there0 = false;
REP(i, k) {
int a;
cin >> a;
if (a == 0)
there0 = true;
else
input.push_back(a);
}
sort(input.begin(), input.end());
int s = 0, e = 1, sz = 1;
REP(i, input.size() - 1) {
if (input[e] - input[e - 1] <= 1) {
sz++;
e++;
} else {
con.push_back({{input[s], input[e - 1]}, sz});
s = e;
e++;
sz = 1;
}
}
con.push_back({{input[s], input[e - 1]}, sz});
if (con.size() == 1) {
int res = con[0].second;
if (1 < con[0].first.first || con[0].first.second < n) {
if (there0)
res++;
}
cout << res << endl;
continue;
}
ll res = 0;
REP(i, con.size() - 1) {
int sa = con[i + 1].first.first - con[i].first.second;
if (sa == 2 && there0) {
res = max(res, con[i].second + con[i + 1].second + 1);
} else if (there0) {
res = max(res, con[i].second + 1);
} else {
res = max(res, con[i].second);
}
}
if (there0) {
res = max(res, con[con.size() - 1].second + 1);
} else {
res = max(res, con[con.size() - 1].second);
}
cout << res << endl;
}
return 0;
}
|
[["-", 51, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 31, 22], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 736
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 100010
int main() {
int n, k;
int v[MAX], dp[MAX];
int tmp;
while (cin >> n >> k) {
if (n == 0 && k == 0)
break;
memset(v, 0, sizeof(v));
memset(dp, 0, sizeof(dp));
bool is_0 = false;
for (int i = 0; i < k; i++) {
cin >> tmp;
if (tmp == 0) {
is_0 = true;
continue;
}
v[tmp] = 1;
dp[tmp] = 1;
}
int ans = 0;
for (int i = 0; i <= n; i++) {
if (v[i] == v[i + 1] == 1)
dp[i + 1] = dp[i] + 1;
ans = max(ans, dp[i + 1]);
}
if (is_0) {
for (int i = 1; i <= n; i++) {
if (v[i] == 0) {
v[i] = 1;
int cnt = 1, t1 = i - 1, t2 = i + 1;
while (v[t1] == 1) {
t1--;
if (t1 < 0)
break;
cnt++;
}
while (v[t2] == 1) {
t2++;
if (t2 > n + 1)
break;
cnt++;
}
v[i] = 0;
ans = max(ans, cnt);
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 100010
int main() {
int n, k;
int v[MAX], dp[MAX];
int tmp;
while (cin >> n >> k) {
if (n == 0 && k == 0)
break;
memset(v, 0, sizeof(v));
memset(dp, 0, sizeof(dp));
bool is_0 = false;
for (int i = 0; i < k; i++) {
cin >> tmp;
if (tmp == 0) {
is_0 = true;
continue;
}
v[tmp] = 1;
dp[tmp] = 1;
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (v[i] == v[i + 1] && v[i] == 1)
dp[i + 1] = dp[i] + 1;
ans = max(ans, dp[i + 1]);
}
if (is_0) {
for (int i = 1; i <= n; i++) {
if (v[i] == 0) {
v[i] = 1;
int cnt = 1, t1 = i - 1, t2 = i + 1;
while (v[t1] == 1) {
t1--;
if (t1 < 0)
break;
cnt++;
}
while (v[t2] == 1) {
t2++;
if (t2 > n + 1)
break;
cnt++;
}
v[i] = 0;
ans = max(ans, cnt);
}
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 51, 16, 31, 16, 12, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 16, 31, 69, 28, 22], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 70], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
| 1
| 340
|
# AOJ 0517: Longest Steps
# Python3 2018.6.30 bal4u
while True:
n, k = map(int, input().split())
if n == 0: break
c = [0]*(n+1)
f = 0;
for i in range(k):
a = int(input())
if a == 0: f = 1
else: c[a] = 1
ans = w0 = w = 0
for i in range(1, n+1):
if c[i]: w += 1
elif w > 0:
if w0 + w + f > ans: ans = w0 + w + f
w0 = w if f and c[i+1] else 0
w = 0
if w0 + w + f > ans: ans = w0 + w + f
print(ans)
|
# AOJ 0517: Longest Steps
# Python3 2018.6.30 bal4u
while True:
n, k = map(int, input().split())
if n == 0: break
c = [0]*(n+2)
f = 0;
for i in range(k):
a = int(input())
if a == 0: f = 1
else: c[a] = 1
ans = w0 = w = 0
for i in range(1, n+1):
if c[i]: w += 1
elif w > 0:
if w0 + w + f > ans: ans = w0 + w + f
w0 = w if f and c[i+1] else 0
w = 0
if w0 + w + f > ans: ans = w0 + w + f
print(ans)
|
[["-", 0, 662, 12, 657, 12, 23, 0, 657, 12, 612], ["+", 0, 662, 12, 657, 12, 23, 0, 657, 12, 612]]
| 5
| 160
|
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int x[5000], y[5000], maxn;
bool p[7000][7000];
int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;
int main() {
while (true) {
memset(p, false, sizeof(p));
cin >> n;
maxn = 0;
if (n == 0) {
break;
}
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
p[x[i]][y[i]] = true;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
Ax = x[i];
Bx = x[j];
Ay = y[i];
By = y[j];
Cx = Ax - (By - Ay);
Cy = Ay + (Bx - Ax);
Dx = Bx - (By - Ay);
Dy = By - (Bx - Ax);
if (Cx >= 0 && Cy >= 0 && Dx >= 0 && Dy >= 0 && Cx <= 5000 &&
Cy <= 5000 && Dx <= 5000 && Dy <= 5000) {
if (p[Cx][Cy] == true && p[Dx][Dy] == true) {
maxn = max(maxn, (Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));
}
}
}
}
cout << maxn << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int x[5000], y[5000], maxn;
bool p[7000][7000];
int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;
int main() {
while (true) {
memset(p, false, sizeof(p));
cin >> n;
maxn = 0;
if (n == 0) {
break;
}
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
p[x[i]][y[i]] = true;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
Ax = x[i];
Bx = x[j];
Ay = y[i];
By = y[j];
Cx = Ax - (By - Ay);
Cy = Ay + (Bx - Ax);
Dx = Bx - (By - Ay);
Dy = By + (Bx - Ax);
if (Cx >= 0 && Cy >= 0 && Dx >= 0 && Dy >= 0 && Cx <= 5000 &&
Cy <= 5000 && Dx <= 5000 && Dy <= 5000) {
if (p[Cx][Cy] == true && p[Dx][Dy] == true) {
maxn = max(maxn, (Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));
}
}
}
}
cout << maxn << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
| 1
| 340
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
P h[3000];
int main() {
int n;
while (scanf("%d", &n), n) {
rep(i, n) scanf("%d%d", &h[i].first, &h[i].second);
sort(h, h + n, [](P a, P b) { return a.second < b.second; });
stable_sort(h, h + n);
int Max = 0;
rep(i, n) {
for (int j = i + 1; j < n; j++) {
int x = h[j].first - h[i].first, y = abs(h[j].second - h[i].second);
if (!x)
continue;
P a = {h[i].first, h[i].second + x}, b = {h[j].first, h[j].second + x};
if (h[i].second < h[j].second) {
a.first -= y;
b.first -= y;
} else {
a.first += y;
b.second += y;
}
if (binary_search(h, h + n, a) && binary_search(h, h + n, b))
Max = max(Max, (x + y) * (x + y) - x * y * 2);
}
}
printf("%d\n", Max);
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
P h[3000];
int main() {
int n;
while (scanf("%d", &n), n) {
rep(i, n) scanf("%d%d", &h[i].first, &h[i].second);
sort(h, h + n, [](P a, P b) { return a.second < b.second; });
stable_sort(h, h + n);
int Max = 0;
rep(i, n) {
for (int j = i + 1; j < n; j++) {
int x = h[j].first - h[i].first, y = abs(h[j].second - h[i].second);
if (!x)
continue;
P a = {h[i].first, h[i].second + x}, b = {h[j].first, h[j].second + x};
if (h[i].second < h[j].second) {
a.first -= y;
b.first -= y;
} else {
a.first += y;
b.first += y;
}
if (binary_search(h, h + n, a) && binary_search(h, h + n, b))
Max = max(Max, (x + y) * (x + y) - x * y * 2);
}
}
printf("%d\n", Max);
}
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 11, 31, 118, 119, 120], ["+", 0, 9, 0, 1, 0, 11, 31, 118, 119, 120]]
| 1
| 344
|
#include <algorithm>
#include <iostream>
#define A first
#define B second
using namespace std;
pair<int, int> z[3000];
int n, x, y, ans;
bool IT(int x, int y) {
int left = 0, right = n, mid;
while (true) {
if (left >= right - 1)
break;
mid = (left + right) / 2;
if (z[mid].A == x && z[mid].B == y)
return true;
if (z[mid].A < x || (z[mid].A == x && z[mid].B < y))
left = mid;
else
right = mid;
}
return false;
}
int main() {
while (true) {
cin >> n;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> z[i].A >> z[i].B;
sort(z, z + n);
ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
x = z[i].B - z[j].B;
y = z[i].A - z[j].A;
if (IT(z[i].A + x, z[i].B - y) && IT(z[j].A - x, z[j].B - y))
ans = max(ans, x * x + y * y);
if (IT(z[i].A - x, z[i].B + y) && IT(z[j].A - x, z[j].B + y))
ans = max(ans, x * x + y * y);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#define A first
#define B second
using namespace std;
pair<int, int> z[3000];
int n, x, y, ans;
bool IT(int x, int y) {
int left = 0, right = n, mid;
while (true) {
if (left >= right - 1)
break;
mid = (left + right) / 2;
if (z[mid].A == x && z[mid].B == y)
return true;
if (z[mid].A < x || (z[mid].A == x && z[mid].B < y))
left = mid;
else
right = mid;
}
return false;
}
int main() {
while (true) {
cin >> n;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> z[i].A >> z[i].B;
sort(z, z + n);
ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
x = z[i].B - z[j].B;
y = z[i].A - z[j].A;
if (IT(z[i].A + x, z[i].B - y) && IT(z[j].A + x, z[j].B - y))
ans = max(ans, x * x + y * y);
if (IT(z[i].A - x, z[i].B + y) && IT(z[j].A - x, z[j].B + y))
ans = max(ans, x * x + y * y);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 51, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 51, 16, 12, 2, 3, 4, 0, 16, 17, 72]]
| 1
| 409
|
#include <bits/stdc++.h>
using namespace std;
#define loop(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
vector<P> p;
bool ex(int x, int y) { return binary_search(p.begin(), p.end(), P(x, y)); }
int main() {
int n, x, y;
while (cin >> n, n) {
loop(_, n) {
cin >> x >> y;
p.push_back(P(x, y));
}
sort(p.begin(), p.end());
int m = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int px = p[i].first;
int py = p[i].second;
int qx = p[j].first;
int qy = p[j].second;
int dx = qx - px;
int dy = qy - py;
if ((ex(px - dy, py + dx) && ex(qx - dy, qy + dx)) ||
(ex(px + dy, py - dx) && ex(qx + dy, qy - dx))) {
m = max(m, dx * dx + dy * dy);
}
}
}
cout << m << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define loop(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
vector<P> p;
bool ex(int x, int y) { return binary_search(p.begin(), p.end(), P(x, y)); }
int main() {
int n, x, y;
while (cin >> n, n) {
p.clear();
loop(_, n) {
cin >> x >> y;
p.push_back(P(x, y));
}
sort(p.begin(), p.end());
int m = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int px = p[i].first;
int py = p[i].second;
int qx = p[j].first;
int qy = p[j].second;
int dx = qx - px;
int dy = qy - py;
if ((ex(px - dy, py + dx) && ex(qx - dy, qy + dx)) ||
(ex(px + dy, py - dx) && ex(qx + dy, qy - dx))) {
m = max(m, dx * dx + dy * dy);
}
}
}
cout << m << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 296
|
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main() {
int n;
while (cin >> n && n != 0) {
int ans = 0;
P p;
map<P, bool> mp;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p.first >> p.second;
mp[p] = true;
}
auto itb = mp.begin(), ite = mp.end();
for (auto it1 = itb; it1 != ite; ++it1) {
for (auto it2 = itb; it2 != ite; ++it2) {
if (it1 == it2)
continue;
P f = it1->first, s = it2->first;
if (!(f.first < s.first))
continue;
int dx = s.first - f.first, dy = s.second - f.second;
if (mp.find(P(f.first + dy, f.second - dx)) != ite &&
mp.find(P(f.first + dx + dy, f.second - dx + dy)) != ite) {
ans = max(ans, dx * dx + dy * dy);
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main() {
int n;
while (cin >> n && n != 0) {
int ans = 0;
P p;
map<P, bool> mp;
for (int i = 0; i < n; ++i) {
cin >> p.first >> p.second;
mp[p] = true;
}
auto itb = mp.begin(), ite = mp.end();
for (auto it1 = itb; it1 != ite; ++it1) {
for (auto it2 = itb; it2 != ite; ++it2) {
if (it1 == it2)
continue;
P f = it1->first, s = it2->first;
if (!(f.first < s.first))
continue;
int dx = s.first - f.first, dy = s.second - f.second;
if (mp.find(P(f.first + dy, f.second - dx)) != ite &&
mp.find(P(f.first + dx + dy, f.second - dx + dy)) != ite) {
ans = max(ans, dx * dx + dy * dy);
}
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 285
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<double, double> P;
int n, x[3001], y[3001];
set<P> st;
int main() {
while (cin >> n, n) {
st.clear();
r(i, n) {
cin >> x[i] >> y[i];
st.insert(P(x[i], y[i]));
}
int ans = 0;
r(i, n) r(j, n) if (i != j) {
int tx1 = x[i] - x[j], ty1 = y[i] - y[j];
int tx2 = x[i] + ty1, ty2 = y[i] - tx1;
int tx3 = x[j] + ty1, ty3 = y[j] - tx1;
int tx4 = x[i] - ty1, ty4 = y[i] + tx1;
int tx5 = x[j] + ty1, ty5 = y[j] + tx1;
if (st.count(P(tx2, ty2)) && st.count(P(tx3, ty3)) ||
st.count(P(tx4, ty4)) && st.count(P(tx5, ty5))) {
ans = max(ans, tx1 * tx1 + ty1 * ty1);
}
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<double, double> P;
int n, x[3001], y[3001];
set<P> st;
int main() {
while (cin >> n, n) {
st.clear();
r(i, n) {
cin >> x[i] >> y[i];
st.insert(P(x[i], y[i]));
}
int ans = 0;
r(i, n) r(j, n) if (i != j) {
int tx1 = x[i] - x[j], ty1 = y[i] - y[j];
int tx2 = x[i] + ty1, ty2 = y[i] - tx1;
int tx3 = x[j] + ty1, ty3 = y[j] - tx1;
int tx4 = x[i] - ty1, ty4 = y[i] + tx1;
int tx5 = x[j] - ty1, ty5 = y[j] + tx1;
if (st.count(P(tx2, ty2)) && st.count(P(tx3, ty3)) ||
st.count(P(tx4, ty4)) && st.count(P(tx5, ty5))) {
ans = max(ans, tx1 * tx1 + ty1 * ty1);
}
}
cout << ans << endl;
}
}
|
[["-", 64, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 64, 9, 0, 43, 49, 50, 51, 16, 17, 33]]
| 1
| 303
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
while (cin >> N, N) {
vector<PLL> xs(N);
set<PLL> cnt;
REP(i, N) {
cin >> xs[i];
cnt.insert(xs[i]);
}
LL ans = -1;
REP(i1, N) REP(i2, N) {
if (i1 == i2)
continue;
PLL dp(xs[i2].FF - xs[i1].FF, xs[i2].SS - xs[i1].SS);
if ((cnt.count(MP(xs[i1].FF - dp.SS, xs[i1].SS + dp.FF)) &&
cnt.count(MP(xs[i2].FF - dp.SS, xs[i2].SS + dp.FF))) ||
(cnt.count(MP(xs[i1].FF + dp.SS, xs[i1].SS - dp.FF)) &&
cnt.count(MP(xs[i2].FF + dp.SS, xs[i2].SS - dp.FF)))) {
maxi(ans, dp.FF * dp.FF + dp.SS * dp.SS);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
while (cin >> N, N) {
vector<PLL> xs(N);
set<PLL> cnt;
REP(i, N) {
cin >> xs[i];
cnt.insert(xs[i]);
}
LL ans = 0;
REP(i1, N) REP(i2, N) {
if (i1 == i2)
continue;
PLL dp(xs[i2].FF - xs[i1].FF, xs[i2].SS - xs[i1].SS);
if ((cnt.count(MP(xs[i1].FF - dp.SS, xs[i1].SS + dp.FF)) &&
cnt.count(MP(xs[i2].FF - dp.SS, xs[i2].SS + dp.FF))) ||
(cnt.count(MP(xs[i1].FF + dp.SS, xs[i1].SS - dp.FF)) &&
cnt.count(MP(xs[i2].FF + dp.SS, xs[i2].SS - dp.FF)))) {
maxi(ans, dp.FF * dp.FF + dp.SS * dp.SS);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 592
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define f first
#define s second
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef unsigned int uint;
typedef long long ll;
int main() {
int n;
while (scanf("%d", &n), n) {
typedef set<pair<int, int>> S;
S s;
REP(i, n) {
int x, y;
scanf("%d%d", &x, &y);
s.insert(mp(x, y));
}
int ans = 0;
for (S::iterator it1 = s.begin(); it1 != s.end(); it1++) {
for (S::iterator it2 = s.begin(); it2 != s.end(); it2++) {
if (it1 == it2)
continue;
int x1 = it1->f;
int y1 = it1->s;
int x2 = it2->f;
int y2 = it2->s;
int dx = x2 - x1;
int dy = y2 - y1;
int x3 = x1 - dy;
int y3 = y1 + dx;
int x4 = x2 - dy;
int y4 = x2 + dx;
// printf("(%d,%d) (%d,%d) (%d,%d) (%d,%d)\n",x1,y1,x2,y2,x3,y3,x4,y4);
if (s.find(mp(x3, y3)) != s.end() && s.find(mp(x4, y4)) != s.end()) {
#define DBL(x) ((x) * (x))
ans = max(ans, DBL(x1 - x2) + DBL(y1 - y2));
}
}
}
printf("%d\n", ans);
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define f first
#define s second
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef unsigned int uint;
typedef long long ll;
int main() {
int n;
while (scanf("%d", &n), n) {
typedef set<pair<int, int>> S;
S s;
REP(i, n) {
int x, y;
scanf("%d%d", &x, &y);
s.insert(mp(x, y));
}
int ans = 0;
for (S::iterator it1 = s.begin(); it1 != s.end(); it1++) {
for (S::iterator it2 = s.begin(); it2 != s.end(); it2++) {
if (it1 == it2)
continue;
int x1 = it1->f;
int y1 = it1->s;
int x2 = it2->f;
int y2 = it2->s;
int dx = x2 - x1;
int dy = y2 - y1;
int x3 = x1 - dy;
int y3 = y1 + dx;
int x4 = x2 - dy;
int y4 = y2 + dx;
if (s.find(mp(x3, y3)) != s.end() && s.find(mp(x4, y4)) != s.end()) {
#define DBL(x) ((x) * (x))
ans = max(ans, DBL(x1 - x2) + DBL(y1 - y2));
}
}
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22]]
| 1
| 368
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define f first
#define s second
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
pair<int, int> t[3333];
rep(i, n) {
int a, b;
cin >> a >> b;
t[i].f = a;
t[i].s = b;
}
sort(t, t + n);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int dx = t[j].f - t[i].f;
int dy = t[j].s - t[i].s;
int flg = 1;
int flg2 = 0;
/*
printf("%d %d\n",i,j);
printf("%d,%d %d,%d %d,%d\n",t[i].f,t[i].s,t[j].f,t[j].s,dx,dy);*/
if (binary_search(t, t + n, make_pair(t[j].f - dy, t[j].s + dx)) == 0) {
flg = 0;
}
if (flg == 1 &&
binary_search(t, t + n, make_pair(t[i].f - dy, t[i].s + dx)) == 0) {
flg = 0;
}
/*
if(binary_search(t,t+n,make_pair(t[j].f+dy,t[j].s-dx))==0){
flg2=0;
}
if(flg2==1 && binary_search(t,t+n,make_pair(t[i].f+dy,t[i].s-dx))==0){
flg2=0;
}*/
if (flg == 1 || flg2 == 1) {
ans = max(ans, dx * dx + dy * dy);
}
}
}
printf("%d\n", ans);
break;
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define f first
#define s second
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
pair<int, int> t[3333];
rep(i, n) {
int a, b;
cin >> a >> b;
t[i].f = a;
t[i].s = b;
}
sort(t, t + n);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int dx = t[j].f - t[i].f;
int dy = t[j].s - t[i].s;
int flg = 1;
int flg2 = 0;
/*
printf("%d %d\n",i,j);
printf("%d,%d %d,%d %d,%d\n",t[i].f,t[i].s,t[j].f,t[j].s,dx,dy);*/
if (binary_search(t, t + n, make_pair(t[j].f - dy, t[j].s + dx)) == 0) {
flg = 0;
}
if (flg == 1 &&
binary_search(t, t + n, make_pair(t[i].f - dy, t[i].s + dx)) == 0) {
flg = 0;
}
/*
if(binary_search(t,t+n,make_pair(t[j].f+dy,t[j].s-dx))==0){
flg2=0;
}
if(flg2==1 && binary_search(t,t+n,make_pair(t[i].f+dy,t[i].s-dx))==0){
flg2=0;
}*/
if (flg == 1 || flg2 == 1) {
ans = max(ans, dx * dx + dy * dy);
}
}
}
printf("%d\n", ans);
}
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 93, 0, 94], ["-", 8, 9, 0, 52, 8, 9, 0, 93, 0, 35]]
| 1
| 326
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;
typedef long long ll;
typedef pair<int, int> pii;
int x[3000];
int y[3000];
int main() {
int n;
while (cin >> n, n) {
map<pii, int> mp;
REP(i, n) {
cin >> x[i] >> y[i];
mp[pii(x[i], y[i])] = 1;
}
int res = 0;
REP(i, n) {
REP(j, i) {
int dy = x[i] - x[j];
int dx = -(y[i] - y[j]);
if (dx == 0 || dy == 0)
continue;
REP(k, 2) {
if (mp.count(pii(x[j] + dx, y[j] + dy)) &&
mp.count(pii(x[i] + dx, y[i] + dy))) {
res = max(res, dx * dx + dy * dy);
// cout << x[i] << " " << y[i] << endl;
// cout << x[j] << " " << y[j] << endl;
// cout << mp.count(pii(x[j]+dx, y[j]+dy)) << endl;
// cout << mp.count(pii(x[i]+dx, y[i]+dy)) << endl;
// cout << x[j]+dx << " " << y[j]+dy << endl;
// cout << x[i]+dx << " " << y[i]+dy << endl << endl;
}
dx = -dx;
dy = -dy;
}
}
}
cout << res << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;
typedef long long ll;
typedef pair<int, int> pii;
int x[3000];
int y[3000];
int main() {
int n;
while (cin >> n, n) {
map<pii, int> mp;
REP(i, n) {
cin >> x[i] >> y[i];
mp[pii(x[i], y[i])] = 1;
}
int res = 0;
REP(i, n) {
REP(j, i) {
int dy = x[i] - x[j];
int dx = -(y[i] - y[j]);
if (dx == 0 && dy == 0)
continue;
REP(k, 2) {
if (mp.count(pii(x[j] + dx, y[j] + dy)) &&
mp.count(pii(x[i] + dx, y[i] + dy))) {
res = max(res, dx * dx + dy * dy);
}
dx = -dx;
dy = -dy;
}
}
}
cout << res << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 318
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<pair<int, int>> p(n);
for (int i = 0; i < n; ++i)
cin >> p[i].first >> p[i].second;
sort(p.begin(), p.end());
int ret = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int x = p[j].first - p[i].first;
int y = p[j].second - p[i].second;
pair<int, int> p1(p[i].first + y, p[i].second + x);
pair<int, int> p2(p[j].first + y, p[j].second + y);
if (binary_search(p.begin(), p.end(), p1) &&
binary_search(p.begin(), p.end(), p2))
ret = max(ret, x * x + y * y);
}
}
cout << ret << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<pair<int, int>> p(n);
for (int i = 0; i < n; ++i)
cin >> p[i].first >> p[i].second;
sort(p.begin(), p.end());
int ret = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int x = p[j].first - p[i].first;
int y = p[j].second - p[i].second;
pair<int, int> p1(p[i].first + y, p[i].second - x);
pair<int, int> p2(p[j].first + y, p[j].second - x);
if (binary_search(p.begin(), p.end(), p1) &&
binary_search(p.begin(), p.end(), p2))
ret = max(ret, x * x + y * y);
}
}
cout << ret << endl;
}
}
|
[["-", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 33], ["-", 0, 43, 49, 50, 51, 4, 0, 16, 12, 22], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 22]]
| 1
| 306
|
#include <stdio.h>
int main() {
int n, k;
int i, j, u[5], v = 0;
int a[100000], sum = 0, w = 0;
while (scanf("%d%d", &n, &k), n != 0 && k != 0) {
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n - k + 1; i++) {
for (j = 0; j < k; j++)
sum += a[j];
if (sum > w)
w = sum;
sum = 0;
}
u[v] = w, v++;
}
for (i = 0; i < v; i++)
printf("%d\n", u[i]);
return 0;
}
|
#include <stdio.h>
int main() {
int n, k;
int i, j, u[5], v = 0;
int a[100000], sum = 0, w = 0;
while (scanf("%d%d", &n, &k), n != 0 && k != 0) {
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n - k + 1; i++) {
for (j = i; j < k + i; j++)
sum += a[j];
if (sum > w)
w = sum;
sum = 0;
}
u[v] = w, v++;
}
for (i = 0; i < v; i++)
printf("%d\n", u[i]);
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 10, 11, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
| 0
| 184
|
#include <stdio.h>
#include <string.h>
typedef long LONG;
LONG a[1000002];
int main(void) {
int n, k;
int i;
LONG max;
while (1) {
scanf("%d%d", &n, &k);
if (n == 0 && k == 0) {
break;
}
memset(a, 0, sizeof(a));
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 2; i <= n; i++) {
a[i] += a[i - 1];
}
max = a[k] - a[0];
for (i = 1; i <= n - k + 1; i++) {
// printf("<%d>", a[i + k - 1] - a[i - 1]);
if (max < a[i + k - 1] - a[i - 1]) {
max = a[i + k - 1] - a[i - 1];
}
}
printf("%ld\n", max);
}
return (0);
}
|
#include <stdio.h>
#include <string.h>
typedef int LONG;
LONG a[100010];
int main(void) {
int n, k;
int i;
LONG max;
while (1) {
scanf("%d%d", &n, &k);
if (n == 0 && k == 0) {
break;
}
memset(a, 0, sizeof(a));
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= n; i++) {
a[i] += a[i - 1];
}
max = a[k] - a[0];
for (i = 1; i <= n - k + 1; i++) {
// printf("<%d>", a[i + k - 1] - a[i - 1]);
if (max < a[i + k - 1] - a[i - 1]) {
max = a[i + k - 1] - a[i - 1];
}
}
printf("%d\n", max);
}
return (0);
}
|
[["-", 36, 36, 0, 30, 0, 134, 39, 86, 0, 96], ["+", 36, 36, 36, 36, 0, 30, 0, 134, 39, 40], ["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 219
|
#include <stdio.h>
long plus(int *a, long s, long e) {
long sum, c;
c = s;
sum = 0;
while (c <= e) {
sum += (long)a[c];
c++;
}
}
int main() {
int a[100000];
long sum, max, n, k, i;
scanf("%ld %ld", &n, &k);
while (n != 0) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = plus(a, 0, k - 1);
sum = max;
for (i = 1; i < n - k + 1; i++) {
sum = sum - (long)a[i - 1] + (long)a[i + k - 1];
max = sum > max ? sum : max;
}
printf("%ld\n", max);
scanf("%ld %ld", &n, &k);
}
return 0;
}
|
#include <stdio.h>
long plus(int *a, long s, long e) {
long sum, c;
c = s;
sum = 0;
while (c <= e) {
sum += (long)a[c];
c++;
}
return sum;
}
int main() {
int a[100000];
long sum, max, n, k, i;
scanf("%ld %ld", &n, &k);
while (n != 0) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = plus(a, 0, k - 1);
sum = max;
for (i = 1; i < n - k + 1; i++) {
sum = sum - (long)a[i - 1] + (long)a[i + k - 1];
max = sum > max ? sum : max;
}
printf("%ld\n", max);
scanf("%ld %ld", &n, &k);
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
| 0
| 221
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n, k, i, a[100000], max, sum;
scanf("%d %d", &n, &k);
while (1) {
max = sum = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i >= k) {
sum = sum - a[i - 4] + a[i];
if (sum > max) {
max = sum;
}
} else if (i < k) {
max += a[i];
sum += a[i];
}
}
printf("%d\n", max);
scanf("%d %d", &n, &k);
if (n == 0 && k == 0)
break;
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n, k, i, a[100000], max, sum;
scanf("%d %d", &n, &k);
while (1) {
max = sum = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i >= k) {
sum = sum - a[i - k] + a[i];
if (sum > max) {
max = sum;
}
} else if (i < k) {
max += a[i];
sum += a[i];
}
}
printf("%d\n", max);
scanf("%d %d", &n, &k);
if (n == 0 && k == 0)
break;
}
return 0;
}
|
[["-", 12, 16, 31, 16, 12, 69, 71, 16, 12, 13], ["+", 12, 16, 31, 16, 12, 69, 71, 16, 12, 22]]
| 0
| 177
|
a[' '];
n, s, i, m;
main(k) {
for (; scanf("%d%d", &n, &k) * n; s = i = !printf("%d\n", m))
for (; i < n; s += a[i], m = i++ < k ? s : fmax(m, s -= a[i - k]))
scanf("%d", a + i);
}
|
a[' '];
n, s, i, m;
main(k) {
for (; scanf("%d%d", &n, &k) * n; s = i = !printf("%d\n", m))
for (; i < n; s += a[i], m = i++ < k ? s : fmax(m, s -= a[i + ~k]))
scanf("%d", a + i);
}
|
[["-", 3, 4, 0, 11, 12, 69, 71, 16, 17, 33], ["+", 3, 4, 0, 11, 12, 69, 71, 16, 17, 72], ["+", 0, 11, 12, 69, 71, 16, 12, 91, 17, 92]]
| 0
| 102
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (n != 0 || k != 0) {
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
vector<int> S(n + 1);
S.at(0) = 0;
for (int i = 0; i < n + 1; i++) {
S.at(i + 1) = S.at(i) + a.at(i);
}
int ans = 0;
for (int i = 0; i + k < n + 2; i++) {
if (S.at(i + k) - S.at(i) > ans)
ans = S.at(i + k) - S.at(i);
}
cout << ans << endl;
cin >> n >> k;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (n != 0 || k != 0) {
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
vector<int> S(n + 1);
S.at(0) = 0;
for (int i = 0; i < n; i++) {
S.at(i + 1) = S.at(i) + a.at(i);
}
int ans = 0;
for (int i = 0; i + k < n + 1; i++) {
if (S.at(i + k) - S.at(i) > ans)
ans = S.at(i + k) - S.at(i);
}
cout << ans << endl;
cin >> n >> k;
}
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 205
|
#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (n != 0 || k != 0) {
int i = 0, a[n], S[n - 1];
S[0] = 0;
while (i < n) {
cin >> a[i];
if (i >= 1)
S[i] = S[i - 1] + a[i - 1];
i++;
}
i = 0;
int m = S[k - 1] - S[0];
while (k + i <= n) {
if (m < S[i + k] - S[i])
m = S[i + k] - S[i];
i++;
}
cout << m << endl;
cin >> n >> k;
}
}
|
#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (n != 0 || k != 0) {
int i = 0, a[n], S[n - 1];
S[0] = 0;
while (i < n) {
cin >> a[i];
if (i >= 1)
S[i] = S[i - 1] + a[i - 1];
i++;
}
i = 0;
int m = S[k] - S[0];
while (k + i < n) {
if (m < S[i + k] - S[i])
m = S[i + k] - S[i];
i++;
}
cout << m << endl;
cin >> n >> k;
}
}
|
[["-", 51, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18]]
| 1
| 176
|
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 999999999;
int main() {
int N, K;
while (cin >> N >> K) {
if (N == 0)
break;
vector<ll> a(N);
for (int i = 0; i < N; ++i)
cin >> a[i];
vector<int> s(N + 1, 0);
for (int i = 0; i < N; ++i)
s[i + 1] = s[i] + a[i];
ll res = -INF;
for (int i = 0; i <= N - K; ++i) {
ll val = s[K + i];
if (res < val)
res = val;
}
cout << res << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 999999999;
int main() {
int N, K;
while (cin >> N >> K) {
if (N == 0)
break;
vector<ll> a(N);
for (int i = 0; i < N; ++i)
cin >> a[i];
vector<int> s(N + 1, 0);
for (int i = 0; i < N; ++i)
s[i + 1] = s[i] + a[i];
ll res = -INF;
for (int i = 0; i <= N - K; ++i) {
ll val = s[K + i] - s[i];
if (res < val)
res = val;
}
cout << res << endl;
}
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["+", 49, 50, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 49, 50, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 49, 50, 51, 16, 12, 69, 341, 342, 0, 73]]
| 1
| 179
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k, max, temp, num, total;
while (true) { //ベクターに格納
cin >> n >> k;
if (n == k == 0)
break;
vector<double> v;
total = 0;
v.push_back(total);
for (int i = 0; i < n; i++) {
cin >> num; //入力をnumに代入
total += num;
v.push_back(total); //ベクターvにプッシュ
}
max = 0;
temp = 0;
for (int i = 0; i + k <= n; i++) {
temp = v[i + k] - v[i];
if (temp > max)
max = temp; // tempが最も大きい数値ならmaxを更新
temp = 0; // tempの初帰化
}
cout << max << endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k, max, temp, num, total;
while (true) { //ベクターに格納
cin >> n >> k;
if (n == k != 0) {
break;
}
vector<double> v;
total = 0;
v.push_back(total);
for (int i = 0; i < n; i++) {
cin >> num; //入力をnumに代入
total += num;
v.push_back(total); //ベクターvにプッシュ
}
max = 0;
temp = 0;
for (int i = 0; i + k <= n; i++) {
temp = v[i + k] - v[i];
if (temp > max)
max = temp; // tempが最も大きい数値ならmaxを更新
temp = 0; // tempの初帰化
}
cout << max << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 162
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
while (1) {
int n, k;
cin >> n >> k;
if (n == 0 && k == 0) {
break;
}
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int s = 0;
int m = 0;
while (s + 2 < n) {
int cm = 0;
for (int j = 0; j < k; j++) {
cm += a[s + j];
}
if (cm > m) {
m = cm;
}
s++;
}
cout << m << endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
while (1) {
int n, k;
cin >> n >> k;
if (n == 0 && k == 0) {
break;
}
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int s = 0;
int m = 0;
while (s + k - 1 < n) {
int cm = 0;
for (int j = 0; j < k; j++) {
cm += a[s + j];
}
if (cm > m) {
m = cm;
}
s++;
}
cout << m << endl;
}
}
|
[["-", 0, 52, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 33], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 12, 13]]
| 1
| 148
|
#include <bits/stdc++.h>
using namespace std;
template <class T> struct treap {
#define treapInf INT_MAX
public:
struct node {
T val;
node *lch, *rch;
int pri, sz;
T sum, mini;
node(T val, int pri) : val(val), pri(pri), sz(1), sum(val), mini(val) {
lch = rch = NULL;
}
};
node *root;
treap() : root(NULL) { srand(time(NULL)); }
private:
inline int size(node *t) { return !t ? 0 : t->sz; }
inline T sum(node *t) { return !t ? 0 : t->sum; }
inline T mini(node *t) { return !t ? treapInf : t->mini; }
node *update(node *t) {
if (!t)
return t;
t->sz = size(t->lch) + size(t->rch) + 1;
t->sum = sum(t->lch) + sum(t->rch) + t->val;
t->mini = min(min(mini(t->lch), mini(t->rch)), t->val);
return t;
}
node *merge(node *l, node *r) {
if (!l || !r)
return l ? l : r;
if (l->pri > r->pri) {
l->rch = merge(l->rch, r);
return update(l);
} else {
r->lch = merge(l, r->lch);
return update(r);
}
}
pair<node *, node *> split(node *t, int k) {
if (!t)
return make_pair((node *)NULL, (node *)NULL);
if (k <= size(t->lch)) {
pair<node *, node *> s = split(t->lch, k);
t->lch = s.second;
return make_pair(s.first, update(t));
} else {
pair<node *, node *> s = split(t->rch, k - size(t->lch) - 1);
t->rch = s.first;
return make_pair(update(t), s.second);
}
}
node *insert(node *t, int k, T val, int pri) {
pair<node *, node *> s = split(t, k);
t = merge(s.first, new node(val, pri));
t = merge(t, s.second);
return update(t);
}
node *erase(node *t, int k) {
pair<node *, node *> s1, s2;
s2 = split(t, k + 1);
s1 = split(s2.first, k);
return update(t = merge(s1.first, s2.second));
}
node *find(node *t, int k) {
// if(!t)return t;
int c = size(t->lch);
if (k < c)
return find(t->lch, k);
if (k == c)
return t;
return find(t->rch, k - c - 1);
}
T rangeMinimumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return treapInf;
if (l <= 0 && sz <= r)
return mini(t);
sz = size(t->lch);
T vl = rangeMinimumQuery(l, r, t->lch);
T vr = rangeMinimumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = min(vl, vr);
if (l <= sz && sz < r)
res = min(res, t->val);
return res;
}
T rangeSumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return 0;
if (l <= 0 && sz <= r)
return sum(t);
sz = size(t->lch);
T vl = rangeSumQuery(l, r, t->lch);
T vr = rangeSumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = vl + vr;
if (l <= sz && sz < r)
res += t->val;
return res;
}
void debug(node *t) {
if (!t)
return;
debug(t->lch);
cout << t->val << " ";
debug(t->rch);
}
public:
void insert(int k, T val) { root = insert(root, k, val, rand()); }
void erase(int k) { root = erase(root, k); }
node *find(int k) { return find(root, k); }
void add(int k, T v) {
node *a = find(k);
T tmp = a->val;
erase(k);
insert(k, tmp + v);
}
void update(int k, T v) {
erase(k);
insert(k, v);
}
T rangeMinimumQuery(int l, int r) { return rangeMinimumQuery(l, r, root); }
T rangeSumQuery(int l, int r) { return rangeSumQuery(l, r, root); }
void init(int n, T val) {
for (int i = 0; i < n; i++)
insert(i, val);
}
void debug() {
debug(root);
cout << endl;
}
};
int main() {
int N, K;
while (cin >> N >> K) {
treap<long long> t;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
t.insert(i, a);
}
long long ma = LLONG_MIN;
for (int i = 0; i + K <= N; i++) {
ma = max(ma, t.rangeSumQuery(i, i + K));
}
cout << ma << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T> struct treap {
#define treapInf INT_MAX
public:
struct node {
T val;
node *lch, *rch;
int pri, sz;
T sum, mini;
node(T val, int pri) : val(val), pri(pri), sz(1), sum(val), mini(val) {
lch = rch = NULL;
}
};
node *root;
treap() : root(NULL) { srand(time(NULL)); }
private:
inline int size(node *t) { return !t ? 0 : t->sz; }
inline T sum(node *t) { return !t ? 0 : t->sum; }
inline T mini(node *t) { return !t ? treapInf : t->mini; }
node *update(node *t) {
if (!t)
return t;
t->sz = size(t->lch) + size(t->rch) + 1;
t->sum = sum(t->lch) + sum(t->rch) + t->val;
t->mini = min(min(mini(t->lch), mini(t->rch)), t->val);
return t;
}
node *merge(node *l, node *r) {
if (!l || !r)
return l ? l : r;
if (l->pri > r->pri) {
l->rch = merge(l->rch, r);
return update(l);
} else {
r->lch = merge(l, r->lch);
return update(r);
}
}
pair<node *, node *> split(node *t, int k) {
if (!t)
return make_pair((node *)NULL, (node *)NULL);
if (k <= size(t->lch)) {
pair<node *, node *> s = split(t->lch, k);
t->lch = s.second;
return make_pair(s.first, update(t));
} else {
pair<node *, node *> s = split(t->rch, k - size(t->lch) - 1);
t->rch = s.first;
return make_pair(update(t), s.second);
}
}
node *insert(node *t, int k, T val, int pri) {
pair<node *, node *> s = split(t, k);
t = merge(s.first, new node(val, pri));
t = merge(t, s.second);
return update(t);
}
node *erase(node *t, int k) {
pair<node *, node *> s1, s2;
s2 = split(t, k + 1);
s1 = split(s2.first, k);
return update(t = merge(s1.first, s2.second));
}
node *find(node *t, int k) {
// if(!t)return t;
int c = size(t->lch);
if (k < c)
return find(t->lch, k);
if (k == c)
return t;
return find(t->rch, k - c - 1);
}
T rangeMinimumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return treapInf;
if (l <= 0 && sz <= r)
return mini(t);
sz = size(t->lch);
T vl = rangeMinimumQuery(l, r, t->lch);
T vr = rangeMinimumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = min(vl, vr);
if (l <= sz && sz < r)
res = min(res, t->val);
return res;
}
T rangeSumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return 0;
if (l <= 0 && sz <= r)
return sum(t);
sz = size(t->lch);
T vl = rangeSumQuery(l, r, t->lch);
T vr = rangeSumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = vl + vr;
if (l <= sz && sz < r)
res += t->val;
return res;
}
void debug(node *t) {
if (!t)
return;
debug(t->lch);
cout << t->val << " ";
debug(t->rch);
}
public:
void insert(int k, T val) { root = insert(root, k, val, rand()); }
void erase(int k) { root = erase(root, k); }
node *find(int k) { return find(root, k); }
void add(int k, T v) {
node *a = find(k);
T tmp = a->val;
erase(k);
insert(k, tmp + v);
}
void update(int k, T v) {
erase(k);
insert(k, v);
}
T rangeMinimumQuery(int l, int r) { return rangeMinimumQuery(l, r, root); }
T rangeSumQuery(int l, int r) { return rangeSumQuery(l, r, root); }
void init(int n, T val) {
for (int i = 0; i < n; i++)
insert(i, val);
}
void debug() {
debug(root);
cout << endl;
}
};
int main() {
int N, K;
while (cin >> N >> K, N || K) {
treap<long long> t;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
t.insert(i, a);
}
long long ma = LLONG_MIN;
for (int i = 0; i + K <= N; i++) {
ma = max(ma, t.rangeSumQuery(i, i + K));
}
cout << ma << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 22]]
| 1
| 1,306
|
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
int main(void) {
int n, k;
while (cin >> n >> k, n + k) {
vector<int> a(n);
rep(i, n) cin >> a[i];
int ret = -100000;
// cout<<k-1<<" "<<n-k+1<<endl;
int sum = 0;
rep(i, k) sum += a[i];
for (int i = k; i < n; i++) {
// for(int j = i-2; j <= i ; j ++)cout<<a[j]<<" ";cout<<endl;
sum = sum + a[i] - a[i - 3];
ret = max(ret, sum);
}
cout << ret << endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
int main(void) {
int n, k;
while (cin >> n >> k, n + k) {
vector<int> a(n);
rep(i, n) cin >> a[i];
int ret = -100000;
int sum = 0;
rep(i, k) sum += a[i];
for (int i = k; i < n; i++) {
sum = sum + a[i] - a[i - k];
ret = max(ret, sum);
}
cout << ret << endl;
}
}
|
[["-", 12, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 12, 16, 12, 69, 341, 342, 0, 16, 12, 22]]
| 1
| 137
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, k;
cin >> n >> k;
if (n == 0 && k == 0) {
break;
} else {
int i, inp;
int *a;
a = new int[n];
for (i = 0; i < n; i++) {
cin >> inp;
a[i] = inp;
}
int sum1 = 0, sum2 = 0, max = 0;
for (i = 0; i < k; i++) {
sum1 += a[i];
}
max = sum1;
for (i = k; i < n; i++) {
sum2 = sum1 + a[i] - a[i - k];
if (sum2 > max) {
max = sum2;
}
sum2 = sum1;
}
cout << max << endl;
delete[] a;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, k;
cin >> n >> k;
if (n == 0 && k == 0) {
break;
} else {
int i, inp;
int *a;
a = new int[n];
for (i = 0; i < n; i++) {
cin >> inp;
a[i] = inp;
}
int sum1 = 0, sum2 = 0, max = 0;
for (i = 0; i < k; i++) {
sum1 += a[i];
}
max = sum1;
for (i = k; i < n; i++) {
sum2 = sum1 + a[i] - a[i - k];
if (sum2 > max) {
max = sum2;
}
sum1 = sum2;
}
cout << max << endl;
delete[] a;
}
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 189
|
#include <cstdio>
using namespace std;
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
const int MAX_N = 100000;
int n, a[MAX_N], k, S, S1, S2;
int p;
while (true) {
scanf("%d%d", &n, &k);
if (n == 0 && k == 0)
break;
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
S = 0;
for (p = 0; p < k; p++) {
S += a[p];
}
S1 = S;
while (p < n) {
S2 = S1 + a[p] + a[p - k];
S = max(S, S2);
S1 = S2;
p++;
}
printf("%d\n", S);
}
return 0;
}
|
#include <cstdio>
using namespace std;
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
const int MAX_N = 100000;
int n, a[MAX_N], k, S, S1, S2;
int p;
while (true) {
scanf("%d%d", &n, &k);
if (n == 0 && k == 0)
break;
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
S = 0;
for (p = 0; p < k; p++) {
S += a[p];
}
S1 = S;
while (p < n) {
S2 = S1 + a[p] - a[p - k];
S = max(S, S2);
S1 = S2;
p++;
}
printf("%d\n", S);
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33]]
| 1
| 202
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
void mainmain() {
int n;
int K;
while (cin >> n >> K, n) {
vll v(n);
rep(i, n) cin >> v[i];
ll cnt = 0;
ll ans = -INFL;
ll sum = 0;
rep(i, n) {
if (cnt < K) {
sum += v[i];
cnt++;
} else {
sum += v[i] - v[i - K];
}
maxs(ans, sum);
}
cout << ans << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
mainmain();
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
void mainmain() {
int n;
int K;
while (cin >> n >> K, n) {
vll v(n);
rep(i, n) cin >> v[i];
ll cnt = 0;
ll ans = -INFL;
ll sum = 0;
rep(i, n) {
if (cnt < K) {
sum += v[i];
cnt++;
} else {
sum += v[i] - v[i - K];
maxs(ans, sum);
}
}
cout << ans << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
mainmain();
}
|
[["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 478
|
#include <algorithm>
#include <iostream>
using namespace std;
#pragma warning(disable : 4996)
long long n, k, a[200000], s, ret;
int main() {
while (true) {
cin >> n >> k;
if (n == 0)
break;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (i <= k)
s += a[i];
}
ret = s;
for (int i = k + 1; i <= n; i++) {
s -= a[i - k];
s += a[i];
ret = max(ret, s);
}
cout << ret << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
#pragma warning(disable : 4996)
long long n, k, a[200000], s, ret;
int main() {
while (true) {
cin >> n >> k;
s = 0;
if (n == 0)
break;
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (i <= k)
s += a[i];
}
ret = s;
for (int i = k + 1; i <= n; i++) {
s -= a[i - k];
s += a[i];
ret = max(ret, s);
}
cout << ret << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 149
|
#include <bits/stdc++.h>
#define LL long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
static const LL INF = 1LL << 61LL;
static const int MAX_N = 1 << 18;
typedef pair<int, int> PII;
LL S[MAX_N + 1], n, m;
LL ans;
class BIT {
public:
int N;
void init(int _N) {
N = _N;
rep(i, N + 1) S[i] = 0;
}
LL getSum(int i) {
LL s = 0;
while (i) {
s += S[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= N) {
S[i] += x;
i += i & -i;
}
}
};
int main() {
while (1) {
BIT bit;
int t = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
bit.init(n);
FOR(i, 1, n) {
int x;
cin >> x;
bit.add(i, x);
}
FOR(i, m, n - m + 1) {
LL query = bit.getSum(i) - bit.getSum(t);
ans = max(query, ans);
t++;
}
cout << ans << endl;
ans = 0;
}
return 0;
}
|
#include <bits/stdc++.h>
#define LL long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
static const LL INF = 1LL << 61LL;
static const int MAX_N = 1 << 18;
typedef pair<int, int> PII;
LL S[MAX_N + 1], n, m;
LL ans;
class BIT {
public:
int N;
void init(int _N) {
N = _N;
rep(i, N + 1) S[i] = 0;
}
LL getSum(int i) {
LL s = 0;
while (i) {
s += S[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= N) {
S[i] += x;
i += i & -i;
}
}
};
int main() {
while (1) {
BIT bit;
int t = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
bit.init(n);
FOR(i, 1, n) {
int x;
cin >> x;
bit.add(i, x);
}
FOR(i, m, n) {
LL query = bit.getSum(i) - bit.getSum(t);
ans = max(query, ans);
t++;
}
cout << ans << endl;
ans = 0;
}
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 16, 31, 16, 17, 33], ["-", 0, 2, 3, 4, 0, 16, 31, 16, 12, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
| 1
| 304
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define For(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
void solve16(int a, int b) {
vector<int> v;
REP(i, a) {
int j;
cin >> j;
v.push_back(j);
}
vector<long> vl;
long s = 0;
REP(i, b) { s += i; }
vl.push_back(s);
REP(i, a - b) {
s -= v[i];
s += v[b + i];
vl.push_back(s);
}
sort(vl.begin(), vl.end(), greater<long>());
cout << vl[0] << endl;
}
int main() {
int a, b;
while (cin >> a >> b, a + b) {
solve16(a, b);
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define For(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
void solve16(int a, int b) {
vector<int> v;
REP(i, a) {
int j;
cin >> j;
v.push_back(j);
}
vector<long> vl;
long s = 0;
REP(i, b) { s += v[i]; }
vl.push_back(s);
REP(i, a - b) {
s -= v[i];
s += v[b + i];
vl.push_back(s);
}
sort(vl.begin(), vl.end(), greater<long>());
cout << vl[0] << endl;
}
int main() {
int a, b;
while (cin >> a >> b, a + b) {
solve16(a, b);
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 70], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 73]]
| 1
| 203
|
#include <iostream>
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
using namespace std;
int main(void) {
int n, k;
while (cin >> n >> k, n || k) {
int a[100000];
int sum = 0;
int m = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < k; i++)
sum += a[i];
m = sum;
for (int i = k; i < n; i++) {
sum -= a[i - k - 1];
sum += a[k];
m = MAX(sum, m);
}
cout << m << endl;
}
return 0;
}
|
#include <iostream>
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
using namespace std;
int main(void) {
int n, k;
while (cin >> n >> k, n || k) {
int a[100000];
int sum = 0;
int m = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < k; i++)
sum += a[i];
m = sum;
for (int i = k; i < n; i++) {
sum -= a[i - k];
sum += a[i];
m = MAX(sum, m);
}
cout << m << endl;
}
return 0;
}
|
[["-", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
| 1
| 154
|
#include <iostream>
using namespace std;
int main(void) {
for (;;) {
int a, b, c[100000] = {0}, d = 0, e = 0, max = 0;
cin >> a >> b;
if (a == 0 && b == 0)
break;
for (int A = 0; A < a; A++) {
cin >> c[A];
if (A >= b) {
for (int B = 0; B < b; B++) {
d = d + c[A + e];
e--;
}
if (max < d)
max = d;
d = 0;
}
}
cout << max << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
for (;;) {
int a, b, c[100000] = {0}, d = 0, e = 0, max = 0;
cin >> a >> b;
if (a == 0 && b == 0)
break;
for (int A = 0; A < a; A++) {
cin >> c[A];
if (A >= b) {
for (int B = 0; B < b; B++) {
d = d + c[A + e];
e--;
}
if (max < d)
max = d;
d = 0;
e = 0;
}
}
cout << max << endl;
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 148
|
#include <iostream>
using namespace std;
int main() {
int n, k;
while (1) {
cin >> n >> k;
int N[n], sum[n - k + 1];
if (n == 0 && k == 0)
break;
for (int i = 0; i < n - k + 1; i++) {
sum[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> N[i];
}
for (int i = 0; i <= n - k; i++) {
for (int j = 0; j < k; j++) {
sum[i] += N[i + j];
}
}
int max = 0;
for (int i = 0; i < n; i++) {
if (max < sum[i]) {
max = sum[i];
}
}
cout << max << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int n, k;
while (1) {
cin >> n >> k;
int N[n], sum[n - k + 1];
if (n == 0 && k == 0)
break;
for (int i = 0; i < n - k + 1; i++) {
sum[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> N[i];
}
for (int i = 0; i <= n - k; i++) {
for (int j = 0; j < k; j++) {
sum[i] += N[i + j];
}
}
int max = 0;
for (int i = 0; i <= n - k; i++) {
if (max < sum[i]) {
max = sum[i];
}
}
cout << max << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
| 1
| 197
|
#include <iostream>
using namespace std;
int seq[100000];
int n, k;
int req(int rem, int i) {
rem -= seq[i];
rem += seq[i + k];
return rem;
}
int main() {
while (cin >> n >> k) {
if (n == 0 && k == 0)
break;
for (int i = 0; i < n; i++) {
cin >> seq[i];
}
int rem = 0;
for (int i = 0; i < k; i++) {
rem += seq[i];
}
int remm = rem;
for (int i = 0; i < n - k; i++) {
rem = req(rem, i);
remm = max(remm, rem);
}
cout << rem << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int seq[100000];
int n, k;
int req(int rem, int i) {
rem -= seq[i];
rem += seq[i + k];
return rem;
}
int main() {
while (cin >> n >> k) {
if (n == 0 && k == 0)
break;
for (int i = 0; i < n; i++) {
cin >> seq[i];
}
int rem = 0;
for (int i = 0; i < k; i++) {
rem += seq[i];
}
int remm = rem;
for (int i = 0; i < n - k; i++) {
rem = req(rem, i);
remm = max(remm, rem);
}
cout << remm << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 176
|
#include <iostream>
main() {
for (int n, k, a[100000], s, M, i; std::cin >> n >> k, n; printf("%d\n", M))
for (M = 1 << 31, i = s = 0; i < n;
s += a[i++], k < i && (s -= a[i - k - 1]), M < s && (M = s))
std::cin >> a[i];
}
|
#include <iostream>
main() {
for (int n, k, a[100000], s, M, i; std::cin >> n >> k, n; printf("%d\n", M))
for (M = 1 << 31, i = s = 0; i < n;
s += a[i], k < ++i && (s -= a[i - k - 1]) && M < s && (M = s))
std::cin >> a[i];
}
|
[["-", 31, 11, 12, 69, 341, 342, 0, 27, 17, 29], ["+", 3, 347, 0, 16, 31, 16, 31, 27, 17, 29], ["-", 12, 69, 28, 343, 345, 344, 3, 347, 0, 21], ["+", 28, 343, 345, 344, 3, 347, 0, 16, 17, 98]]
| 1
| 109
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
int k;
while (cin >> n >> k, n != 0 || k != 0) {
vector<int> data;
int sum = 0;
for (int i = 1; i <= n; i++) {
int tmp;
cin >> tmp;
data.push_back(tmp);
}
for (int i = 0; i < k; i++) {
sum += data[i];
}
int max = sum;
for (int i = 3; i < data.size(); i++) {
sum -= data[i - 3];
sum += data[i];
if (sum > max)
max = sum;
}
cout << max << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
int k;
while (cin >> n >> k, n != 0 || k != 0) {
vector<int> data;
int sum = 0;
for (int i = 1; i <= n; i++) {
int tmp;
cin >> tmp;
data.push_back(tmp);
}
for (int i = 0; i < k; i++) {
sum += data[i];
}
int max = sum;
for (int i = k; i < data.size(); i++) {
sum -= data[i - k];
sum += data[i];
if (sum > max)
max = sum;
}
cout << max << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 22], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 0, 11, 12, 69, 341, 342, 0, 16, 12, 22]]
| 1
| 162
|
#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
static const double eps = 1e-8;
int stage[16][16];
ll bit[100001];
ll sumBIT(int i, ll *bit) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void addBIT(int i, int x, ll *bit, int n) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
int main() {
int n, k;
while (~scanf("%d %d", &n, &k)) {
if (n == k && k == 0)
break;
memset(bit, 0, sizeof(bit));
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
addBIT(i + 1, num, bit, 100000);
}
ll res = numeric_limits<ll>::min();
for (int i = 1; i + 2 <= n; i++) {
res = max(sumBIT(i + 2, bit) - sumBIT(i - 1, bit), res);
}
printf("%lld\n", res);
}
}
|
#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
static const double eps = 1e-8;
int stage[16][16];
ll bit[100001];
ll sumBIT(int i, ll *bit) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void addBIT(int i, int x, ll *bit, int n) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
int main() {
int n, k;
while (~scanf("%d %d", &n, &k)) {
if (n == k && k == 0)
break;
memset(bit, 0, sizeof(bit));
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
addBIT(i + 1, num, bit, 100000);
}
ll res = numeric_limits<ll>::min();
for (int i = 1; i + k - 1 <= n; i++) {
res = max(sumBIT(i + k - 1, bit) - sumBIT(i - 1, bit), res);
}
printf("%lld\n", res);
}
}
|
[["-", 8, 9, 0, 7, 15, 16, 31, 16, 12, 13], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 12, 13], ["-", 0, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["+", 31, 2, 3, 4, 0, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 317
|
// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d", &x)
#define rep(i, x) for (int i = 0; i < x; i++)
int main() {
while (1) {
int n, k;
scanf("%d %d", &n, &k);
if (!n)
return 0;
int ret = -INF;
int res = 0;
queue<int> que;
for (int i = 0; i < k; i++) {
int s;
scanf("%d", &s);
res += s;
que.push(s);
}
ret = max(ret, res);
for (int i = k; i <= n; i++) {
int s;
scanf("%d", &s);
res += s;
res -= (que.front());
ret = max(ret, res);
que.pop();
que.push(s);
}
printf("%d\n", ret);
}
}
|
// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d", &x)
#define rep(i, x) for (int i = 0; i < x; i++)
int main() {
while (1) {
int n, k;
scanf("%d %d", &n, &k);
if (!n)
return 0;
int ret = -INF;
int res = 0;
queue<int> que;
for (int i = 0; i < k; i++) {
int s;
scanf("%d", &s);
res += s;
que.push(s);
}
ret = max(ret, res);
for (int i = k; i < n; i++) {
int s;
scanf("%d", &s);
res += s;
res -= (que.front());
ret = max(ret, res);
que.pop();
que.push(s);
}
printf("%d\n", ret);
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 272
|
#include <iostream>
using namespace std;
int main() {
int n, k;
int a[100100];
int b[100100];
for (;;) {
cin >> n >> k;
if (n == 0 && k == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
b[0] = 0;
for (int i = 0; i < n; i++) {
b[i + 1] = b[i] + a[i];
}
int mx = -100000;
for (int i = 0; i < n - k; i++) {
int s = b[i + k + 1] - b[i];
if (mx < s)
mx = s;
}
cout << mx << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, k;
int a[100100];
int b[100100];
for (;;) {
cin >> n >> k;
if (n == 0 && k == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
b[0] = 0;
for (int i = 0; i < n; i++) {
b[i + 1] = b[i] + a[i];
}
int mx = -100000;
for (int i = 0; i < n - k + 1; i++) {
int s = b[i + k] - b[i];
if (mx < s)
mx = s;
}
cout << mx << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 17, 72], ["-", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 176
|
#include <algorithm>
#include <iostream>
using namespace std;
int n, m;
int x, s;
int a[100000];
int main(void) {
while (cin >> n >> m, n || m) {
for (int i = 0; i < n; i++) {
cin >> a[i];
}
x = 0;
for (int i = 0; i < n; i++) {
x += a[i];
}
s = x;
for (int i = 0; i < n - m; i++) {
x -= a[i];
x += a[i + m];
if (s < x)
s = x;
}
cout << s << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int n, m;
int x, s;
int a[100000];
int main(void) {
while (cin >> n >> m, n || m) {
for (int i = 0; i < n; i++) {
cin >> a[i];
}
x = 0;
for (int i = 0; i < m; i++) {
x += a[i];
}
s = x;
for (int i = 0; i < n - m; i++) {
x -= a[i];
x += a[i + m];
if (s < x)
s = x;
}
cout << s << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
| 1
| 152
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string label;
int joiCount = 0;
int ioiCount = 0;
int joiIndex = 0;
int ioiIndex = 0;
while (true) {
cin >> label;
if (cin.eof()) {
break;
}
joiCount = 0;
ioiCount = 0;
joiIndex = 0;
ioiIndex = 0;
while (label.find("joi", joiIndex) != string::npos) {
joiIndex = label.find("joi", joiIndex) + 1;
joiCount++;
}
while (label.find("ioi", ioiIndex) != string::npos) {
ioiIndex = label.find("ioi", ioiIndex) + 1;
ioiCount++;
}
cout << joiCount << '\n' << ioiCount << '\n';
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string label;
int joiCount = 0;
int ioiCount = 0;
int joiIndex = 0;
int ioiIndex = 0;
while (true) {
cin >> label;
if (cin.eof()) {
break;
}
joiCount = 0;
ioiCount = 0;
joiIndex = 0;
ioiIndex = 0;
while (label.find("JOI", joiIndex) != string::npos) {
joiIndex = label.find("JOI", joiIndex) + 1;
joiCount++;
}
while (label.find("IOI", ioiIndex) != string::npos) {
ioiIndex = label.find("IOI", ioiIndex) + 1;
ioiCount++;
}
cout << joiCount << '\n' << ioiCount << '\n';
}
return 0;
}
|
[["-", 51, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["+", 51, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["-", 12, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["+", 12, 16, 31, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 166
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int joi = 0, ioi = 0, i = 0;
bool check = true;
while (cin >> str) {
joi = 0;
ioi = 0;
if (str[0] == '0')
break;
i = 0;
while (check) {
if (str.find("JOI", i) >= 0 && str.find("JOI", i) < str.size()) {
i = str.find("JOI", i) + 1;
joi++;
check = true;
}
else
check = false;
}
i = 0;
check = true;
while (check) {
if (str.find("IOI", i) >= 0 && str.find("IOI", i) < str.size()) {
i = str.find("IOI", i) + 1;
ioi++;
check = true;
}
else
check = false;
}
cout << joi << endl << ioi << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int joi = 0, ioi = 0, i = 0;
bool check = true;
while (cin >> str) {
joi = 0;
ioi = 0;
i = 0;
if (str[0] == '0')
break;
check = true;
while (check) {
if (str.find("JOI", i) >= 0 && str.find("JOI", i) < str.size()) {
i = str.find("JOI", i) + 1;
joi++;
check = true;
}
else
check = false;
}
i = 0;
check = true;
while (check) {
if (str.find("IOI", i) >= 0 && str.find("IOI", i) < str.size()) {
i = str.find("IOI", i) + 1;
ioi++;
check = true;
}
else
check = false;
}
cout << joi << endl << ioi << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 146]]
| 1
| 223
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
int IOI = 0, JOI = 0;
string tmp;
tmp = s;
for (size_t a = tmp.find("IOI"); a != string::npos; a = tmp.find("IOI")) {
tmp[a] = 'A';
IOI++;
}
for (size_t a = s.find("JOI"); a != string::npos; a = s.find("JOI")) {
s[a] = 'A';
JOI++;
}
cout << JOI << endl;
cout << IOI << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
for (string s; cin >> s;) {
int IOI = 0, JOI = 0;
string tmp;
tmp = s;
for (size_t a = tmp.find("IOI"); a != string::npos; a = tmp.find("IOI")) {
tmp[a] = 'A';
IOI++;
}
for (size_t a = s.find("JOI"); a != string::npos; a = s.find("JOI")) {
s[a] = 'A';
JOI++;
}
cout << JOI << endl;
cout << IOI << endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 24], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 25], ["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
| 1
| 174
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int a, b, c, d, e, f;
while (cin >> s) {
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
while (a >= 0 || d >= 0) {
a = s.find("JOI", b);
d = s.find("IOI", e);
if (a >= 0) {
c++;
b = a + 1;
}
if (d >= 0) {
f++;
e = d + 1;
}
}
cout << c << ' ' << f << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int a, b, c, d, e, f;
while (cin >> s) {
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
while (a >= 0 || d >= 0) {
a = s.find("JOI", b);
d = s.find("IOI", e);
if (a >= 0) {
c++;
b = a + 1;
}
if (d >= 0) {
f++;
e = d + 1;
}
}
cout << c << endl << f << endl;
}
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 104], ["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 125], ["+", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22]]
| 1
| 149
|
#include <iostream>
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0522
int main() {
string str;
cin >> str;
int c1 = 0, c2 = 0;
for (int i = 0; i < str.size() - 2; i++) {
if (str[i] != 'J' && str[i] != 'I')
continue;
if (str[i + 1] != 'O')
continue;
if (str[i + 2] != 'I')
continue;
if (str[i] == 'J')
c1++;
else
c2++;
}
cout << c1 << endl << c2 << endl;
return 0;
}
|
#include <iostream>
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0522
int main() {
string str;
while (cin >> str) {
int c1 = 0, c2 = 0;
for (int i = 0; i < str.size() - 2; i++) {
if (str[i] != 'J' && str[i] != 'I')
continue;
if (str[i + 1] != 'O')
continue;
if (str[i + 2] != 'I')
continue;
if (str[i] == 'J')
c1++;
else
c2++;
}
cout << c1 << endl << c2 << endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 134
|
#include <stdio.h>
#include <string.h>
char S[112345];
int ans[2] = {0};
int main(void) {
while (true) {
memset(S, '\0', sizeof(S));
ans[0] = 0, ans[1] = 0;
scanf("%s", &S);
if (S[0] == '\0') {
break;
}
for (int i = 0; i < strlen(S) - 2; ++i) {
if (S[i] == 'J' && S[i + 1] == 'O' && S[i + 2] == 'I') {
++ans[0];
}
if (S[i] == 'I' && S[i + 1] == 'O' && S[i + 2] == 'I') {
++ans[1];
}
}
printf("%d\n%d", ans[0], ans[1]);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
char S[112345];
int ans[2] = {0};
int main(void) {
while (true) {
memset(S, '\0', sizeof(S));
ans[0] = 0, ans[1] = 0;
scanf("%s", &S);
if (S[0] == '\0') {
break;
}
for (int i = 0; i < strlen(S) - 2; ++i) {
if (S[i] == 'J' && S[i + 1] == 'O' && S[i + 2] == 'I') {
++ans[0];
}
if (S[i] == 'I' && S[i + 1] == 'O' && S[i + 2] == 'I') {
++ans[1];
}
}
printf("%d\n%d\n", ans[0], ans[1]);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 211
|
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
string j;
int joi = 0, ioi = 0;
for (int i = 0; i < s.size() - 2; i++) {
j = s.substr(i, 3);
if (j == "JOI") {
joi++;
}
if (j == "IOI") {
ioi++;
}
}
cout << joi << endl << ioi << endl;
}
|
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
while (cin >> s) {
string j;
int joi = 0, ioi = 0;
for (int i = 0; i < s.size() - 2; i++) {
j = s.substr(i, 3);
if (j == "JOI") {
joi++;
}
if (j == "IOI") {
ioi++;
}
}
cout << joi << endl << ioi << endl;
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 110
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
string s;
cin >> s;
int joi = 0, ioi = 0;
for (int i = 0; i < (int)s.size() - 2; i++) {
if (s.substr(i, 3) == "JOI")
joi++;
if (s.substr(i, 3) == "IOI")
ioi++;
}
cout << joi << endl << ioi << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
string s;
while (cin >> s) {
int joi = 0, ioi = 0;
for (int i = 0; i < (int)s.size() - 2; i++) {
if (s.substr(i, 3) == "JOI")
joi++;
if (s.substr(i, 3) == "IOI")
ioi++;
}
cout << joi << endl << ioi << endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 105
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(x, y, z) for (int x = y; x < z; x++)
#define INF 9999999;
#define VEC vector<int>
#define in push_back
#define ans(x) cout << x << endl
#define ll long long int
using namespace std;
int main() {
string s;
while (cin >> s) {
cin >> s;
int IOI = 0, JOI = 0;
for (int i = 0; i < s.length() - 2; i++) {
if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')
JOI++;
else if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
IOI++;
}
ans(JOI);
ans(IOI);
}
}
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(x, y, z) for (int x = y; x < z; x++)
#define INF 9999999;
#define VEC vector<int>
#define in push_back
#define ans(x) cout << x << endl
#define ll long long int
using namespace std;
int main() {
string s;
while (cin >> s) {
int IOI = 0, JOI = 0;
for (int i = 0; i < s.length() - 2; i++) {
if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')
JOI++;
if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
IOI++;
}
ans(JOI);
ans(IOI);
}
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 185
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int main() {
string str;
cin >> str;
int i, ioi = 0, joi = 0;
for (i = 0; i < str.size() - 2; i++) {
if (str.substr(i, 3) == "JOI")
joi++;
if (str.substr(i, 3) == "IOI")
ioi++;
}
cout << joi << endl << ioi << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int main() {
string str;
while (cin >> str) {
int i, ioi = 0, joi = 0;
for (i = 0; i < str.size() - 2; i++) {
if (str.substr(i, 3) == "JOI")
joi++;
if (str.substr(i, 3) == "IOI")
ioi++;
}
cout << joi << endl << ioi << endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 275
|
#include <cstring>
#include <iostream>
using namespace std;
int main() {
char str[10001];
int r[2], i;
while (cin >> str) {
if (cin.eof())
break;
r[0] = r[1] = 0;
for (i = 0; i < signed(strlen(str)) - 2;) {
if (str[i] == 'I' || str[i] == 'J') {
if (str[i + 1] == 'O' && str[i + 2] == 'I') {
r[str[i] - 'I']++;
i += 2;
} else
i++;
} else
i++;
}
cout << r[0] << endl << r[1] << endl;
}
}
|
#include <cstring>
#include <iostream>
using namespace std;
int main() {
char str[10001];
int r[2], i;
while (cin >> str) {
if (cin.eof())
break;
r[0] = r[1] = 0;
for (i = 0; i < signed(strlen(str)) - 2;) {
if (str[i] == 'I' || str[i] == 'J') {
if (str[i + 1] == 'O' && str[i + 2] == 'I') {
r['J' - str[i]]++;
i += 2;
} else
i++;
} else
i++;
}
cout << r[0] << endl << r[1] << endl;
}
}
|
[["+", 28, 69, 341, 342, 0, 16, 31, 103, 0, 104], ["+", 28, 69, 341, 342, 0, 16, 31, 103, 0, 125], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33], ["-", 28, 69, 341, 342, 0, 16, 12, 103, 0, 104], ["-", 28, 69, 341, 342, 0, 16, 12, 103, 0, 125]]
| 1
| 168
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int ans1 = 0, ans2 = 0;
for (int i = 0; i < s.size() - 2; i++) {
string t = "";
t += s[i];
t += s[i + 1];
t += s[i + 2];
if (t == "JOI")
ans1++;
if (t == "IOI")
ans2++;
}
cout << ans1 << endl << ans2 << endl;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
while (cin >> s) {
int ans1 = 0, ans2 = 0;
for (int i = 0; i < s.size() - 2; i++) {
string t = "";
t += s[i];
t += s[i + 1];
t += s[i + 2];
if (t == "JOI")
ans1++;
if (t == "IOI")
ans2++;
}
cout << ans1 << endl << ans2 << endl;
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 115
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
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();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const double EPS = 1e-10;
int main() {
string str;
while (cin >> str) {
cin >> str;
int jc = 0, ic = 0;
REP(i, str.size() - 2) {
if (str[i + 1] == 'O' && str[i + 2] == 'I') {
if (str[i] == 'J') {
jc++;
} else if (str[i] == 'I') {
ic++;
}
}
}
cout << jc << endl;
cout << ic << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
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();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const double EPS = 1e-10;
int main() {
string str;
while (cin >> str) {
int jc = 0, ic = 0;
REP(i, str.size() - 2) {
if (str[i + 1] == 'O' && str[i + 2] == 'I') {
if (str[i] == 'J') {
jc++;
} else if (str[i] == 'I') {
ic++;
}
}
}
cout << jc << endl;
cout << ic << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 303
|
#include <iostream>
using namespace std;
int main() {
char s[10000 + 4];
int i = 0;
while (scanf("%s", &s) != EOF) {
int Jc = 0, Ic = 0;
while (s[i + 2] != '\0') {
if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')
Jc++;
if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
Ic++;
i++;
}
printf("%d\n%d\n", Jc, Ic);
}
}
|
#include <iostream>
using namespace std;
int main() {
char s[10000 + 4];
int i = 0;
while (scanf("%s", &s) != EOF) {
i = 0;
int Jc = 0, Ic = 0;
while (s[i + 2] != '\0') {
if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')
Jc++;
if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
Ic++;
i++;
}
printf("%d\n%d\n", Jc, Ic);
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 154
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int joi = 0, ioi = 0;
string str;
while (cin >> str) {
for (int i = 0; i < str.size() - 2; i++) {
if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I')
joi++;
else if (str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I')
ioi++;
}
cout << joi << endl;
cout << ioi << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int joi = 0, ioi = 0;
string str;
while (cin >> str) {
joi = ioi = 0;
for (int i = 0; i < str.size() - 2; i++) {
if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I')
joi++;
else if (str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I')
ioi++;
}
cout << joi << endl;
cout << ioi << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 141
|
#include <iostream>
using namespace std;
int main() {
string inp;
int cnt_j, cnt_i;
cin >> inp;
cnt_j = cnt_i = 0;
for (int i = 0; i < inp.size() - 2; i++) {
if (inp.substr(i, 3) == "JOI")
cnt_j++;
else if (inp.substr(i, 3) == "IOI")
cnt_i++;
}
cout << cnt_j << '\n' << cnt_i << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
string inp;
int cnt_j, cnt_i;
while (cin >> inp) {
cnt_j = cnt_i = 0;
for (int i = 0; i < inp.size() - 2; i++) {
if (inp.substr(i, 3) == "JOI")
cnt_j++;
else if (inp.substr(i, 3) == "IOI")
cnt_i++;
}
cout << cnt_j << '\n' << cnt_i << endl;
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 104
|
#include <iostream>
using namespace std;
int main() {
string line;
int len, joi, ioi;
while (cin >> line) {
joi = 0;
ioi = 0;
len = line.length() - 1;
for (int i = 1; i < len; ++i) {
if (line.at(i) == 'O') {
if (line.at(i + 1) == 'I') {
if (line.at(i - 1) == 'J') {
joi++;
} else if (line.at(i - 1) == 'J') {
ioi++;
}
}
}
}
cout << joi << endl;
cout << ioi << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
string line;
int len, joi, ioi;
while (cin >> line) {
joi = 0;
ioi = 0;
len = line.length() - 1;
for (int i = 1; i < len; ++i) {
if (line.at(i) == 'O') {
if (line.at(i + 1) == 'I') {
if (line.at(i - 1) == 'J') {
joi++;
} else if (line.at(i - 1) == 'I') {
ioi++;
}
}
}
}
cout << joi << endl;
cout << ioi << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125]]
| 1
| 152
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string a;
cin >> a;
int joi_ans = 0, ioi_ans = 0;
for (int i = 0; i < a.size(); i++) {
if ("JOI" == a.substr(i, 3)) {
joi_ans++;
} else if ("IOI" == a.substr(i, 3)) {
ioi_ans++;
}
}
printf("%d\n%d\n", joi_ans, ioi_ans);
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string a;
while (cin >> a) {
int joi_ans = 0, ioi_ans = 0;
for (int i = 0; i < a.size(); i++) {
if ("JOI" == a.substr(i, 3)) {
joi_ans++;
} else if ("IOI" == a.substr(i, 3)) {
ioi_ans++;
}
}
printf("%d\n%d\n", joi_ans, ioi_ans);
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 111
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
while (cin >> s) {
int a = 0, b = 0;
for (int i = 0; i < s.size(); i++) {
if (s.substr(i, 3) == "JOI")
a++;
else if (s.substr(i, 3) == "IOI")
b++;
}
cout << a << " " << b << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
while (cin >> s) {
int a = 0, b = 0;
for (int i = 0; i < s.size(); i++) {
if (s.substr(i, 3) == "JOI")
a++;
else if (s.substr(i, 3) == "IOI")
b++;
}
cout << a << endl << b << endl;
}
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22]]
| 1
| 103
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int INF = 1 << 29;
typedef pair<int, int> P;
string n;
int main(void) {
while (cin >> n && n != "") {
int ans = 0;
for (int i = n.find("JOI", 0); i != string::npos;
i = n.find("JOI", (int)i + 3))
ans++;
cout << ans << endl;
ans = 0;
for (int i = n.find("IOI", 0); i != string::npos;
i = n.find("IOI", (int)i + 3))
ans++;
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int INF = 1 << 29;
typedef pair<int, int> P;
string n;
int main(void) {
while (cin >> n && n != "") {
int ans = 0;
for (int i = n.find("JOI", 0); i != string::npos;
i = n.find("JOI", (int)i + 2))
ans++;
cout << ans << endl;
ans = 0;
for (int i = n.find("IOI", 0); i != string::npos;
i = n.find("IOI", (int)i + 2))
ans++;
cout << ans << endl;
}
return 0;
}
|
[["-", 26, 11, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 26, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 176
|
while True:
try:
s = input().strip()
except:
break
i = 0
cnt_joi, cnt_ioi = 0, 0
while i < len(s) - 2:
t = s[i:i + 3]
if t == 'JOI':
cnt_joi += 1
i += 2
elif t == 'IOI':
cnt_ioi += 1
i += 2
elif t[2] == 'O':
i += 1
elif t[2] == 'I':
i += 2
else:
i += 3
print(cnt_joi)
print(cnt_ioi)
|
while True:
try:
s = input().strip()
except:
break
i = 0
cnt_joi, cnt_ioi = 0, 0
while i < len(s) - 2:
t = s[i:i + 3]
if t == 'JOI':
cnt_joi += 1
i += 2
elif t == 'IOI':
cnt_ioi += 1
i += 2
elif t[2] == 'O':
i += 1
elif t[2] in 'IJ':
i += 2
else:
i += 3
print(cnt_joi)
print(cnt_ioi)
|
[["-", 8, 196, 0, 57, 75, 665, 15, 666, 667, 60], ["+", 8, 196, 0, 57, 75, 665, 15, 666, 667, 267], ["-", 0, 57, 75, 665, 15, 666, 0, 557, 0, 6], ["+", 0, 57, 75, 665, 15, 666, 0, 557, 0, 6]]
| 5
| 112
|
#include <algorithm>
#include <cstdio>
using namespace std;
int n;
pair<int, int> p[3005];
int P[3005];
int main() {
while (1) {
scanf("%d", &n);
if (!n)
break;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
P[i] = a;
p[i] = make_pair(a, b);
}
sort(p, p + n);
sort(P, P + n);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int a, b, c, d;
a = p[i].first;
b = p[i].second;
c = p[j].first;
d = p[j].second;
if (ans <= (a - c) * (a - c) + (b - d) * (b - d)) {
continue;
}
int ro1 = lower_bound(P, P + n, a + b - d) - P;
int rp1 = lower_bound(P, P + n, c + b - d) - P;
int wo1 = lower_bound(P, P + n, a - b + d) - P;
int wp1 = lower_bound(P, P + n, c - b + d) - P;
int ro2 = upper_bound(P, P + n, a + b - d) - P;
int rp2 = upper_bound(P, P + n, c + b - d) - P;
int wo2 = upper_bound(P, P + n, a - b + d) - P;
int wp2 = upper_bound(P, P + n, c - b + d) - P;
bool aa = false, bb = false, cc = false, dd = false;
for (int k = ro1; k < ro2; k++) {
if (p[k].second == b + c - a) {
aa = true;
break;
}
}
for (int k = rp1; k < rp2; k++) {
if (p[k].second == d + c - a) {
bb = true;
break;
}
}
for (int k = wo1; k < wo2; k++) {
if (p[k].second == b - c + a) {
cc = true;
break;
}
}
for (int k = wp1; k < wp2; k++) {
if (p[k].second == d - c + a) {
dd = true;
break;
}
}
if ((aa && bb) || (cc && dd)) {
ans = max(ans, (a - c) * (a - c) + (b - d) * (b - d));
}
}
}
printf("%d\n", ans);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int n;
pair<int, int> p[3005];
int P[3005];
int main() {
while (1) {
scanf("%d", &n);
if (!n)
break;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
P[i] = a;
p[i] = make_pair(a, b);
}
sort(p, p + n);
sort(P, P + n);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int a, b, c, d;
a = p[i].first;
b = p[i].second;
c = p[j].first;
d = p[j].second;
if (ans >= (a - c) * (a - c) + (b - d) * (b - d)) {
continue;
}
int ro1 = lower_bound(P, P + n, a + b - d) - P;
int rp1 = lower_bound(P, P + n, c + b - d) - P;
int wo1 = lower_bound(P, P + n, a - b + d) - P;
int wp1 = lower_bound(P, P + n, c - b + d) - P;
int ro2 = upper_bound(P, P + n, a + b - d) - P;
int rp2 = upper_bound(P, P + n, c + b - d) - P;
int wo2 = upper_bound(P, P + n, a - b + d) - P;
int wp2 = upper_bound(P, P + n, c - b + d) - P;
bool aa = false, bb = false, cc = false, dd = false;
for (int k = ro1; k < ro2; k++) {
if (p[k].second == b + c - a) {
aa = true;
break;
}
}
for (int k = rp1; k < rp2; k++) {
if (p[k].second == d + c - a) {
bb = true;
break;
}
}
for (int k = wo1; k < wo2; k++) {
if (p[k].second == b - c + a) {
cc = true;
break;
}
}
for (int k = wp1; k < wp2; k++) {
if (p[k].second == d - c + a) {
dd = true;
break;
}
}
if ((aa && bb) || (cc && dd)) {
ans = max(ans, (a - c) * (a - c) + (b - d) * (b - d));
}
}
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 637
|
#include <iostream>
using namespace std;
static int n, x[3000], y[3000], ans = 0;
static bool a[5000][5000];
int z(int x) {
if (x < 0)
x = -x;
return x;
}
bool f(int p, int q) {
bool c = false;
if (0 <= (x[p] - y[p] + y[q]) && 0 <= (y[p] - x[q] + x[p]) &&
0 <= (x[q] + y[q] - y[p]) && 0 <= (y[q] - x[q] + x[p]) &&
(x[p] - y[p] + y[q]) < 5000 && (y[p] - x[q] + x[p]) < 5000 &&
(x[q] + y[q] - y[p]) < 5000 && (y[q] - x[q] + x[p]) < 5000) {
if (a[x[p] - y[p] + y[q]][y[p] - x[q] + x[p]] &&
a[x[q] + y[q] - y[p]][y[q] - x[q] + x[p]])
c = true;
}
if (0 <= (x[p] + y[p] - y[q]) && 0 <= (y[p] + x[q] - x[p]) &&
0 <= (x[q] - y[q] + y[p]) && 0 <= (y[q] + x[q] - x[p]) &&
(x[p] + y[p] - y[q]) < 5000 && (y[p] + x[q] - x[p]) < 5000 &&
(x[q] - y[q] + y[p]) < 5000 && (y[q] + x[q] - x[p]) < 5000) {
if (a[x[p] + y[p] - y[q]][y[p] + x[q] - x[p]] &&
a[x[q] - y[q] + y[p]][y[q] + x[q] - x[p]])
c = true;
}
return c;
}
int main() {
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < 5000; i++)
for (int j = 0; j < 5000; j++)
a[i][j] = false;
for (int i = 0; i < n; i++) {
scanf("%d%d", &x[i], &y[i]);
a[x[i]][y[i]] = true;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
if (f(i, j) && z(x[i] - x[j]) * z(x[i] - x[j]) +
z(y[i] - y[j]) * z(y[i] - y[j]) >
ans)
ans = z(x[i] - x[j]) * z(x[i] - x[j]) +
z(y[i] - y[j]) * z(y[i] - y[j]);
}
}
}
printf("%d\n", ans);
}
}
|
#include <iostream>
using namespace std;
static int n, x[3000], y[3000], ans = 0;
static bool a[5000][5000];
int z(int x) {
if (x < 0)
x = -x;
return x;
}
bool f(int p, int q) {
bool c = false;
if (0 <= (x[p] - y[p] + y[q]) && 0 <= (y[p] - x[q] + x[p]) &&
0 <= (x[q] + y[q] - y[p]) && 0 <= (y[q] - x[q] + x[p]) &&
(x[p] - y[p] + y[q]) < 5000 && (y[p] - x[q] + x[p]) < 5000 &&
(x[q] + y[q] - y[p]) < 5000 && (y[q] - x[q] + x[p]) < 5000) {
if (a[x[p] - y[p] + y[q]][y[p] - x[q] + x[p]] &&
a[x[q] + y[q] - y[p]][y[q] - x[q] + x[p]])
c = true;
}
if (0 <= (x[p] + y[p] - y[q]) && 0 <= (y[p] + x[q] - x[p]) &&
0 <= (x[q] - y[q] + y[p]) && 0 <= (y[q] + x[q] - x[p]) &&
(x[p] + y[p] - y[q]) < 5000 && (y[p] + x[q] - x[p]) < 5000 &&
(x[q] - y[q] + y[p]) < 5000 && (y[q] + x[q] - x[p]) < 5000) {
if (a[x[p] + y[p] - y[q]][y[p] + x[q] - x[p]] &&
a[x[q] - y[q] + y[p]][y[q] + x[q] - x[p]])
c = true;
}
return c;
}
int main() {
while (1) {
ans = 0;
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < 5000; i++)
for (int j = 0; j < 5000; j++)
a[i][j] = false;
for (int i = 0; i < n; i++) {
scanf("%d%d", &x[i], &y[i]);
a[x[i]][y[i]] = true;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
if (f(i, j) && z(x[i] - x[j]) * z(x[i] - x[j]) +
z(y[i] - y[j]) * z(y[i] - y[j]) >
ans)
ans = z(x[i] - x[j]) * z(x[i] - x[j]) +
z(y[i] - y[j]) * z(y[i] - y[j]);
}
}
}
printf("%d\n", ans);
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 821
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct Point {
int x, y;
Point() {}
Point(int x, int y) : x(x), y(y) {}
Point operator+(const Point &a) { return Point(x - a.x, y - a.y); }
Point operator-(const Point &a) { return Point(x - a.x, y - a.y); }
bool operator<(const Point &a) const { return x == a.y ? y < a.y : x < a.x; }
bool operator==(const Point &a) const { return x == a.x && y == a.y; }
double norm() { return x * x + y * y; }
};
typedef Point Vector;
Vector rotate90R(Vector V) { return Vector(V.y, -V.x); }
bool in(Point p) { return 0 <= p.x && p.x <= 5000 && 0 <= p.y && p.y <= 5000; }
int main() {
int n;
int x, y;
while (cin >> n && n) {
vector<Point> vec;
map<Point, int> exist;
for (int i = 0; i < n; i++) {
cin >> x >> y;
Point p(x, y);
vec.push_back(p);
exist[p]++;
}
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
Vector V1 = vec[i] - vec[j];
Vector V2 = rotate90R(V1);
int area = V1.norm();
Vector VV1 = vec[j] + V2;
Vector VV2 = vec[i] + V2;
if (in(VV1) && in(VV2))
if (exist.count(VV1) && exist.count(VV2))
ans = max(ans, area);
VV1 = vec[j] - V2;
VV2 = vec[i] - V2;
if (in(VV1) && in(VV2))
if (exist.count(VV1) && exist.count(VV2))
ans = max(ans, area);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct Point {
int x, y;
Point() {}
Point(int x, int y) : x(x), y(y) {}
Point operator+(const Point &a) { return Point(x - a.x, y - a.y); }
Point operator-(const Point &a) { return Point(x - a.x, y - a.y); }
bool operator<(const Point &a) const { return x == a.x ? y < a.y : x < a.x; }
bool operator==(const Point &a) const { return x == a.x && y == a.y; }
double norm() { return x * x + y * y; }
};
typedef Point Vector;
Vector rotate90R(Vector V) { return Vector(V.y, -V.x); }
bool in(Point p) { return 0 <= p.x && p.x <= 5000 && 0 <= p.y && p.y <= 5000; }
int main() {
int n;
int x, y;
while (cin >> n && n) {
vector<Point> vec;
map<Point, int> exist;
for (int i = 0; i < n; i++) {
cin >> x >> y;
Point p(x, y);
vec.push_back(p);
exist[p]++;
}
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
Vector V1 = vec[i] - vec[j];
Vector V2 = rotate90R(V1);
int area = V1.norm();
Vector VV1 = vec[j] + V2;
Vector VV2 = vec[i] + V2;
if (in(VV1) && in(VV2))
if (exist.count(VV1) && exist.count(VV2))
ans = max(ans, area);
VV1 = vec[j] - V2;
VV2 = vec[i] - V2;
if (in(VV1) && in(VV2))
if (exist.count(VV1) && exist.count(VV2))
ans = max(ans, area);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 37, 0, 41, 15, 16, 12, 118, 119, 120], ["+", 0, 37, 0, 41, 15, 16, 12, 118, 119, 120]]
| 1
| 505
|
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int, int> P;
int x[3001];
int y[3001];
bool g[5001][5001];
int main() {
int n, ans;
while (cin >> n && n) {
ans = 0;
for (int i = 0; i < 5001; ++i) {
for (int j = 0; j < 5001; ++j) {
g[i][j] = false;
}
}
for (int i = 0; i < n; ++i) {
cin >> x[i];
cin >> y[i];
g[x[i]][y[i]] = true;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int dy = y[j] - y[i];
int dx = x[j] - x[i];
if (x[j] > x[i] && y[j] > y[i] && 0 <= x[i] - dy && x[i] - dy <= 5000 &&
0 <= y[i] + dx && y[i] + dx <= 5000 && 0 <= x[j] - dy &&
x[j] - dy <= 5000 && 0 <= y[j] + dx && y[j] + dx <= 5000) {
if (g[x[i] - dy][y[i] + dx] && g[x[j] - dy][y[j] + dx]) {
ans = max(ans, dx * dx + dy * dy);
}
}
}
}
cout << ans << "\n";
}
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int, int> P;
int x[3001];
int y[3001];
bool g[5001][5001];
int main() {
int n, ans;
while (cin >> n && n) {
ans = 0;
for (int i = 0; i < 5001; ++i) {
for (int j = 0; j < 5001; ++j) {
g[i][j] = false;
}
}
for (int i = 0; i < n; ++i) {
cin >> x[i];
cin >> y[i];
g[x[i]][y[i]] = true;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int dy = y[j] - y[i];
int dx = x[j] - x[i];
if (x[j] >= x[i] && y[j] >= y[i] && 0 <= x[i] - dy &&
x[i] - dy <= 5000 && 0 <= y[i] + dx && y[i] + dx <= 5000 &&
0 <= x[j] - dy && x[j] - dy <= 5000 && 0 <= y[j] + dx &&
y[j] + dx <= 5000) {
if (g[x[i] - dy][y[i] + dx] && g[x[j] - dy][y[j] + dx]) {
ans = max(ans, dx * dx + dy * dy);
}
}
}
}
cout << ans << "\n";
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 47], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 31, 16, 31, 16, 31, 16, 12, 16, 17, 47], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 17, 20]]
| 1
| 400
|
while True:
n = eval(input())
if n == 0: break
xy = [list(map(int,input().split())) for i in range(n)]
S = set(map(tuple,xy))
ans = 0
for i in range(n):
x1,y1 = xy[i]
for j in range(n-1,i,-1):
x2,y2 = xy[j]
a = (x2-y2+y1,y2+x2-x1)
b = (x1-y2+y1,y1+x2-x1)
if a in S and b in S:
ans = max((x1-x2)**2 + (y1-y2)**2)
print(ans)
|
while True:
n = eval(input())
if n == 0: break
xy = [list(map(int,input().split())) for i in range(n)]
S = set(map(tuple,xy))
ans = 0
for i in range(n):
x1,y1 = xy[i]
for j in range(n-1,i,-1):
x2,y2 = xy[j]
a = (x2-y2+y1,y2+x2-x1)
b = (x1-y2+y1,y1+x2-x1)
if a in S and b in S:
ans = max(ans,(x1-x2)**2 + (y1-y2)**2)
print(ans)
|
[["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 21]]
| 5
| 159
|
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> G[5006];
int cnt[5006] = {};
int main() {
queue<int> que;
int flag = 0;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
G[a - 1].push_back(b - 1);
cnt[b - 1]++;
}
for (int i = 0; i < N; i++) {
if (cnt[i] == 0)
que.push(i);
}
while (!que.empty()) {
if (que.size() >= 2)
flag = 1;
int v = que.front();
que.pop();
cout << v << endl;
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
cnt[u]--;
if (cnt[u] == 0)
que.push(u);
}
}
cout << flag << endl;
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> G[5006];
int cnt[5006] = {};
int main() {
queue<int> que;
int flag = 0;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
G[a - 1].push_back(b - 1);
cnt[b - 1]++;
}
for (int i = 0; i < N; i++) {
if (cnt[i] == 0)
que.push(i);
}
while (!que.empty()) {
if (que.size() >= 2)
flag = 1;
int v = que.front();
que.pop();
cout << v + 1 << endl;
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
cnt[u]--;
if (cnt[u] == 0)
que.push(u);
}
}
cout << flag << endl;
return (0);
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 246
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
static const int MAX = 5000;
vector<int> G[MAX + 1];
vector<int> ans;
bool V[MAX + 1];
int W[MAX + 1];
int N, M;
void dfs(int u) {
V[u] = true;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (!V[v])
dfs(v);
}
ans.push_back(u);
}
main() {
cin >> N >> M;
for (int i = 1; i <= N; i++) {
V[i] = false;
W[i] = -1;
}
int s, t;
for (int i = 0; i < M; i++) {
cin >> s >> t;
W[s] = t;
G[t].push_back(s);
}
for (int i = 1; i <= N; i++) {
if (!V[i])
dfs(i);
}
for (int i = 0; i < N; i++)
cout << ans[i] << endl;
bool mul = false;
for (int i = 0; i < N - 1; i++) {
int i1 = ans[i];
int i2 = ans[i + 1];
if (W[i1] == -1) {
mul = true;
break;
}
}
if (mul)
cout << 1 << endl;
else
cout << 1 << endl;
}
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
static const int MAX = 5000;
vector<int> G[MAX + 1];
vector<int> ans;
bool V[MAX + 1];
int W[MAX + 1];
int N, M;
void dfs(int u) {
V[u] = true;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (!V[v])
dfs(v);
}
ans.push_back(u);
}
main() {
cin >> N >> M;
for (int i = 1; i <= N; i++) {
V[i] = false;
W[i] = -1;
}
int s, t;
for (int i = 0; i < M; i++) {
cin >> s >> t;
W[s] = t;
G[t].push_back(s);
}
for (int i = 1; i <= N; i++) {
if (!V[i])
dfs(i);
}
for (int i = 0; i < N; i++)
cout << ans[i] << endl;
bool mul = false;
for (int i = 0; i < N - 1; i++) {
int i1 = ans[i];
int i2 = ans[i + 1];
if (W[i1] == -1) {
mul = true;
break;
}
}
if (mul)
cout << 1 << endl;
else
cout << 0 << endl;
}
|
[["-", 75, 76, 0, 1, 0, 16, 31, 16, 12, 13], ["+", 75, 76, 0, 1, 0, 16, 31, 16, 12, 13]]
| 1
| 338
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
const int MAX_N = 5000;
// win[i]にjが含まれるならiはjに勝った
// win[i]にjが含まれるならiはjに負けた
vector<int> win[MAX_N + 1];
vector<int> lose[MAX_N + 1];
vector<int> ord;
int used[MAX_N + 1] = {0};
// vがordに追加される時点で,
// vから到達可能な全ての頂点,すなわち,vより順位が低いチームは,必ずordに追加されている
void tsort(int v) {
used[v] = true;
for (int i = 0; i < lose[v].size(); i++) {
if (!used[lose[v][i]])
tsort(win[v][i]);
}
ord.pb(v);
}
int main() {
int n, m;
cin >> n >> m;
while (m--) {
//頂点w(winner), l(loser)を入力
int w, l;
cin >> w >> l;
// win[w]にlを含める
// lose[l]にwを含める
win[w].pb(l);
lose[l].pb(w);
}
// この時点では誰が1位か分からないので,
// 誰かに勝っていれば,自分を1位としてトポロジカルソートを行う
for (int i = 1; i <= n; i++)
if (!win[i].size())
tsort(i);
// "他のソート結果が存在する"フラグ
bool exi = 0;
for (int i = 1; i < n; i++) {
// "i位のチームにi+1位のチームが勝った"という情報が与えられているか?
bool ok = find(all(lose[ord[i]]), ord[i - 1]) == lose[ord[i]].end();
exi |= ok;
}
// 順位を出力
for (int i = 0; i < ord.size(); i++) {
cout << ord[i] << endl;
}
// 存在するかどうかを出力
cout << exi << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
const int MAX_N = 5000;
// win[i]にjが含まれるならiはjに勝った
// win[i]にjが含まれるならiはjに負けた
vector<int> win[MAX_N + 1];
vector<int> lose[MAX_N + 1];
vector<int> ord;
int used[MAX_N + 1] = {0};
// vがordに追加される時点で,
// vから到達可能な全ての頂点,すなわち,vより順位が低いチームは,必ずordに追加されている
void tsort(int v) {
used[v] = true;
for (int i = 0; i < lose[v].size(); i++) {
if (!used[lose[v][i]])
tsort(lose[v][i]);
}
ord.pb(v);
}
int main() {
int n, m;
cin >> n >> m;
while (m--) {
//頂点w(winner), l(loser)を入力
int w, l;
cin >> w >> l;
// win[w]にlを含める
// lose[l]にwを含める
win[w].pb(l);
lose[l].pb(w);
}
// この時点では誰が1位か分からないので,
// 誰かに勝っていれば,自分を1位としてトポロジカルソートを行う
for (int i = 1; i <= n; i++)
if (!win[i].size())
tsort(i);
// "他のソート結果が存在する"フラグ
bool exi = 0;
for (int i = 1; i < n; i++) {
// "i位のチームにi+1位のチームが勝った"という情報が与えられているか?
bool ok = find(all(lose[ord[i]]), ord[i - 1]) == lose[ord[i]].end();
exi |= ok;
}
// 順位を出力
for (int i = 0; i < ord.size(); i++) {
cout << ord[i] << endl;
}
// 存在するかどうかを出力
cout << exi << endl;
}
|
[["-", 0, 2, 3, 4, 0, 69, 28, 69, 28, 22], ["+", 0, 2, 3, 4, 0, 69, 28, 69, 28, 22]]
| 1
| 330
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
const int MAX_N = 5000;
// win[i]にjが含まれるならiはjに勝った
// win[i]にjが含まれるならiはjに負けた
vector<int> win[MAX_N + 1];
vector<int> lose[MAX_N + 1];
vector<int> ord;
int used[MAX_N + 1] = {0};
// vがordに追加される時点で,
// vから到達可能な全ての頂点,すなわち,vより順位が低いチームは,必ずordに追加されている
void tsort(int v) {
used[v] = true;
for (int i = 0; i < lose[v].size(); i++) {
if (!used[lose[v][i]])
tsort(win[v][i]);
}
ord.pb(v);
}
int main() {
int n, m;
cin >> n >> m;
while (m--) {
//頂点w(winner), l(loser)を入力
int w, l;
cin >> w >> l;
// win[w]にlを含める
// lose[l]にwを含める
win[w].pb(l);
lose[l].pb(w);
}
// この時点では誰が1位か分からないので,
// 誰かに勝っていれば,自分を1位としてトポロジカルソートを行う
for (int i = 1; i <= n; i++)
if (!win[i].size())
tsort(i);
// "他のソート結果が存在する"フラグ
bool exi = 0;
for (int i = 1; i < n; i++) {
// "i位のチームにi+1位のチームが勝った"という情報が与えられているか?
bool ok = find(all(lose[ord[i]]), ord[i - 1]) == lose[ord[i]].end();
exi |= ok;
}
// 順位を出力
for (int i = 0; i < ord.size(); i++) {
cout << ord[i] << endl;
}
// 存在するかどうかを出力
cout << exi << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
const int MAX_N = 5000;
// win[i]にjが含まれるならiはjに勝った
// win[i]にjが含まれるならiはjに負けた
vector<int> win[MAX_N + 1];
vector<int> lose[MAX_N + 1];
// 順位表
vector<int> ord;
// "順位は決定している"フラグ
int used[MAX_N + 1] = {0};
void tsort(int v) {
// "vの順位は決定した"フラグを立てる
used[v] = true;
for (int i = 0; i < lose[v].size(); i++) {
if (!used[lose[v][i]])
tsort(lose[v][i]);
}
// vがordに追加される時点で,
// vから到達可能な全ての頂点,すなわち,vより順位が高くないことが確定したチームは
// 必ずordに追加されている
ord.pb(v);
}
int main() {
int n, m;
cin >> n >> m;
while (m--) {
//頂点w(winner), l(loser)を入力
int w, l;
cin >> w >> l;
// win[w]にlを含める
// lose[l]にwを含める
win[w].pb(l);
lose[l].pb(w);
}
// この時点では誰が1位か分からないので,
// 誰かに勝っていれば,自分を1位としてトポロジカルソートを行う
// 実際の順位と異なる可能性はあるが,
// 与えられた情報だけに矛盾しなければいいのでこれでOK
for (int i = 1; i <= n; i++)
if (!win[i].size())
tsort(i);
// "他のソート結果が存在する"フラグ
bool exi = 0;
for (int i = 1; i < n; i++) {
// "i位のチームにi+1位のチームが勝った"という情報が与えられているか?
bool ok = find(all(lose[ord[i]]), ord[i - 1]) == lose[ord[i]].end();
// 与えられていればフラグを立てる
exi |= ok;
}
// 出力
for (int i = 0; i < ord.size(); i++) {
cout << ord[i] << endl;
}
// 存在するかどうかを出力
cout << exi << endl;
}
|
[["-", 0, 2, 3, 4, 0, 69, 28, 69, 28, 22], ["+", 0, 2, 3, 4, 0, 69, 28, 69, 28, 22]]
| 1
| 330
|
from collections import deque
def Topologicalsort(v):
start=deque()
for i in range(v):
if indeg[i]==0 :
start.append(i)
if len(start)>1:
flag=True
else:
flag=False
while len(start)>0:
i=start.popleft()
ans.append(i)
tmp=[]
for j in g[i]:
indeg[j]-=1
if indeg[j]==0:
tmp.append(j)
start.append(j)
if len(tmp)>=1:
flag=True
else:
flag=False
return ans,flag
def solve(n,m):
for i in range(m):
wt,lt=list(map(int,input().split()))
wt-=1;lt-=1
g[wt].append(lt)
indeg[lt]+=1
ans,flag=Topologicalsort(n)
return ans,flag
n=int(input())
m=int(input())
indeg=[0]*n
g=[[] for _ in range(n)]
ans=[]
ans,flag=solve(n,m)
if flag:
for i in range(len(ans)):
print((ans[i]+1))
print((1))
else:
for i in range(n):
print((ans[i]+1))
print((0))
|
from collections import deque
def Topologicalsort(v):
start=deque()
for i in range(v):
if indeg[i]==0 :
start.append(i)
if len(start)>1:
flag=True
else:
flag=False
while len(start)>0:
i=start.popleft()
ans.append(i)
tmp=[]
for j in g[i]:
indeg[j]-=1
if indeg[j]==0:
tmp.append(j)
start.append(j)
if len(tmp)>1:
flag=True
return ans,flag
def solve(n,m):
for i in range(m):
wt,lt=list(map(int,input().split()))
wt-=1;lt-=1
g[wt].append(lt)
indeg[lt]+=1
ans,flag=Topologicalsort(n)
return ans,flag
n=int(input())
m=int(input())
indeg=[0]*n
g=[[] for _ in range(n)]
ans=[]
ans,flag=solve(n,m)
if flag:
for i in range(len(ans)):
print((ans[i]+1))
print((1))
else:
for i in range(n):
print((ans[i]+1))
print((0))
|
[["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 47], ["-", 0, 57, 64, 196, 0, 57, 75, 76, 0, 95], ["-", 0, 57, 64, 196, 0, 57, 75, 76, 0, 102], ["-", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["-", 75, 76, 8, 196, 0, 1, 0, 662, 12, 147]]
| 5
| 309
|
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
public class Main {
static PrintWriter out;
static InputReader ir;
static int[] p = new int[101], q = new int[101], r = new int[101],
b = new int[101], par = new int[101];
static void solve() {
int n;
while ((n = ir.nextInt()) != 0) {
Arrays.fill(par, -1);
for (int i = 1; i <= n; i++) {
p[i] = ir.nextInt();
q[i] = ir.nextInt();
r[i] = ir.nextInt();
b[i] = ir.nextInt();
par[r[i]] = par[b[i]] = i;
long g = gcd(p[i], q[i]);
p[i] /= (int)g;
q[i] /= (int)g;
}
int pp = -1;
for (int i = 1; i <= n; i++)
if (par[i] == -1)
pp = i;
out.println(dfs(pp));
}
}
public static long dfs(int now) {
if (r[now] == 0 && b[now] == 0)
return (long)p[now] + (long)q[now];
if (r[now] == 0) {
long bb = dfs(b[now]);
return bb / gcd(q[now], bb) * (p[now] + q[now]);
}
if (b[now] == 0) {
long rr = dfs(r[now]);
return rr / gcd(p[now], rr) * (p[now] + q[now]);
}
long bb = dfs(b[now]), rr = dfs(r[now]);
long l = lcm(bb * p[now], rr * q[now]);
return l / p[now] + l / q[now];
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b) { return a * b / gcd(a, b); }
public static void main(String[] args) throws Exception {
ir = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() { return Double.parseDouble(next()); }
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
}
|
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
public class Main {
static PrintWriter out;
static InputReader ir;
static int[] p = new int[101], q = new int[101], r = new int[101],
b = new int[101], par = new int[101];
static void solve() {
int n;
while ((n = ir.nextInt()) != 0) {
Arrays.fill(par, -1);
for (int i = 1; i <= n; i++) {
p[i] = ir.nextInt();
q[i] = ir.nextInt();
r[i] = ir.nextInt();
b[i] = ir.nextInt();
par[r[i]] = par[b[i]] = i;
long g = gcd(p[i], q[i]);
p[i] /= (int)g;
q[i] /= (int)g;
}
int pp = -1;
for (int i = 1; i <= n; i++)
if (par[i] == -1)
pp = i;
out.println(dfs(pp));
}
}
public static long dfs(int now) {
if (r[now] == 0 && b[now] == 0)
return (long)p[now] + (long)q[now];
if (r[now] == 0) {
long bb = dfs(b[now]);
return bb / gcd(p[now], bb) * (p[now] + q[now]);
}
if (b[now] == 0) {
long rr = dfs(r[now]);
return rr / gcd(q[now], rr) * (p[now] + q[now]);
}
long bb = dfs(b[now]), rr = dfs(r[now]);
long l = lcm(bb * q[now], rr * p[now]);
return l / p[now] + l / q[now];
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b) { return a * b / gcd(a, b); }
public static void main(String[] args) throws Exception {
ir = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() { return Double.parseDouble(next()); }
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
}
|
[["-", 31, 16, 12, 492, 3, 4, 0, 504, 516, 22], ["+", 31, 16, 12, 492, 3, 4, 0, 504, 516, 22], ["-", 51, 492, 3, 4, 0, 16, 12, 504, 516, 22], ["+", 51, 492, 3, 4, 0, 16, 12, 504, 516, 22]]
| 3
| 1,287
|
#include <iostream>
#include <vector>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int m, long long int n) {
if (m == 0 || n == 0)
return 0;
return ((m / gcd(m, n)) * n);
}
int main() {
while (true) {
long long int n;
cin >> n;
if (n == 0)
break;
vector<long long int> p, q, r, b;
for (long long int i = 0; i < n; i++) {
long long int in_p, in_q, in_r, in_b;
cin >> in_p >> in_q >> in_r >> in_b;
p.push_back(in_p);
q.push_back(in_q);
r.push_back(in_r);
b.push_back(in_b);
}
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < n; j++) {
if (r[j] <= 0 && b[j] <= 0) {
if (r[j] == 0) {
r[j] = 1;
} else {
r[j] = -r[j];
}
long long int r2 = r[j] * q[j];
if (b[j] == 0) {
b[j] = 1;
} else {
b[j] = -b[j];
}
long long int b2 = b[j] * p[j];
long long int h = lcm(r2, b2) / p[j] + lcm(r2, b2) / q[j];
r[j] = n + 2;
b[j] = n + 2;
for (long long int k = 0; k < n; k++) {
if (i == n - 1) {
cout << h << endl;
break;
}
if (r[k] == j + 1) {
r[k] = -h;
break;
}
if (b[k] == j + 1) {
b[k] = -h;
break;
}
}
break;
}
}
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int m, long long int n) {
if (m == 0 || n == 0)
return 0;
return ((m / gcd(m, n)) * n);
}
int main() {
while (true) {
long long int n;
cin >> n;
if (n == 0)
break;
vector<long long int> p, q, r, b;
for (long long int i = 0; i < n; i++) {
long long int in_p, in_q, in_r, in_b;
cin >> in_p >> in_q >> in_r >> in_b;
p.push_back(in_p);
q.push_back(in_q);
r.push_back(in_r);
b.push_back(in_b);
}
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < n; j++) {
if (r[j] <= 0 && b[j] <= 0) {
if (r[j] == 0) {
r[j] = 1;
} else {
r[j] = -r[j];
}
long long int r2 = r[j] * p[j];
if (b[j] == 0) {
b[j] = 1;
} else {
b[j] = -b[j];
}
long long int b2 = b[j] * q[j];
long long int h = lcm(r2, b2) / p[j] + lcm(r2, b2) / q[j];
r[j] = n + 2;
b[j] = n + 2;
for (long long int k = 0; k < n; k++) {
if (i == n - 1) {
cout << h << endl;
break;
}
if (r[k] == j + 1) {
r[k] = -h;
break;
}
if (b[k] == j + 1) {
b[k] = -h;
break;
}
}
break;
}
}
}
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22]]
| 1
| 477
|
#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 <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int p[101] = {};
int q[101] = {};
int r[101] = {};
int s[101] = {};
int gcd(int a, int b) {
while (b) {
int r = a % b;
a = b;
b = r;
}
return a;
}
int cal(int i) {
if (i == 0) {
return 1;
}
int a = cal(r[i]);
int b = cal(s[i]);
int g = gcd(a * q[i], b * p[i]);
int v = a * q[i] / g * b + b * p[i] / g * a;
// cout << i << ", " << v << endl;
return v;
}
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
return 0;
int hasParent[101] = {};
for (int i = 1; i <= n; i++) {
cin >> p[i] >> q[i] >> r[i] >> s[i];
hasParent[r[i]] = true;
hasParent[s[i]] = true;
}
for (int i = 1; i <= n; i++) {
if (!hasParent[i]) {
cout << cal(i) << endl;
}
}
}
}
|
#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 <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int p[101] = {};
int q[101] = {};
int r[101] = {};
int s[101] = {};
int gcd(int a, int b) {
while (b) {
int r = a % b;
a = b;
b = r;
}
return a;
}
int cal(int i) {
if (i == 0) {
return 1;
}
int a = cal(r[i]);
int b = cal(s[i]);
int g = gcd(a * p[i], b * q[i]);
int v = a * p[i] / g * b + b * q[i] / g * a;
// cout << i << ", " << v << endl;
return v;
}
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
return 0;
int hasParent[101] = {};
for (int i = 1; i <= n; i++) {
cin >> p[i] >> q[i] >> r[i] >> s[i];
hasParent[r[i]] = true;
hasParent[s[i]] = true;
}
for (int i = 1; i <= n; i++) {
if (!hasParent[i]) {
cout << cal(i) << endl;
}
}
}
}
|
[["-", 51, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["+", 51, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["-", 31, 16, 31, 16, 31, 16, 12, 69, 28, 22], ["+", 31, 16, 31, 16, 31, 16, 12, 69, 28, 22], ["-", 12, 16, 31, 16, 31, 16, 12, 69, 28, 22], ["+", 12, 16, 31, 16, 31, 16, 12, 69, 28, 22]]
| 1
| 353
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;
const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(c) (c).begin(), (c).end()
struct edge {
int to, cost;
edge(int t, int c) : to(t), cost(c) {}
};
int dxk[] = {1, 1, 1, 0, -1, 0};
int dxg[] = {0, 1, 0, -1, -1, -1};
int dy[] = {-1, 0, 1, 1, 0, -1};
struct node {
LL value, lw, rw, left, right;
};
LL gcd(LL a, LL b) {
if (a < b)
swap(a, b);
return a % b == 0 ? b : gcd(b, a % b);
}
LL sks(LL a, LL b) {
LL g = gcd(a, b);
return a / g * b;
}
LL dfs(int idx, vector<node> &bars) {
if (idx == -1)
return 1LL;
node &node = bars[idx];
if (node.value != 0)
return node.value;
LL r = dfs(node.right, bars), l = dfs(node.left, bars);
int m = 1;
while ((r * node.rw * m) % (l * node.lw) != 0)
m++;
int lm = r * node.rw * m / (l * node.lw);
// r*lの最小公倍数を基礎値としてm:nにする
// LL s = sks(r * node.rw, l * node.lw);
// return node.value = s / node.rw + s / node.lw;
return node.value = m * r + lm * l;
}
int main() {
int n;
while (cin >> n && n) {
vector<node> bars(n);
rep(i, n) {
int p, q, r, b;
cin >> p >> q >> r >> b;
int g = gcd(p, q);
bars[i].rw = p / g;
bars[i].lw = q / g;
bars[i].left = r - 1;
bars[i].right = b - 1;
}
LL ans = 0;
rep(i, n) ans = max(dfs(i, bars), ans);
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;
const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(c) (c).begin(), (c).end()
struct edge {
int to, cost;
edge(int t, int c) : to(t), cost(c) {}
};
int dxk[] = {1, 1, 1, 0, -1, 0};
int dxg[] = {0, 1, 0, -1, -1, -1};
int dy[] = {-1, 0, 1, 1, 0, -1};
struct node {
LL value, lw, rw, left, right;
};
LL gcd(LL a, LL b) {
if (a < b)
swap(a, b);
return a % b == 0 ? b : gcd(b, a % b);
}
LL sks(LL a, LL b) {
LL g = gcd(a, b);
return a / g * b;
}
LL dfs(int idx, vector<node> &bars) {
if (idx == -1)
return 1LL;
node &node = bars[idx];
if (node.value != 0)
return node.value;
LL r = dfs(node.right, bars), l = dfs(node.left, bars);
int m = 1;
while ((r * node.rw * m) % (l * node.lw) != 0)
m++;
int lm = r * node.rw * m / (l * node.lw);
// r*lの最小公倍数を基礎値としてm:nにする
// LL s = sks(r * node.rw, l * node.lw);
// return node.value = s / node.rw + s / node.lw;
return node.value = m * r + lm * l;
}
int main() {
int n;
while (cin >> n && n) {
vector<node> bars(n);
rep(i, n) {
int p, q, r, b;
cin >> p >> q >> r >> b;
int g = gcd(p, q);
bars[i].rw = q / g;
bars[i].lw = p / g;
bars[i].left = r - 1;
bars[i].right = b - 1;
}
LL ans = 0;
rep(i, n) ans = max(dfs(i, bars), ans);
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
| 1
| 537
|
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
long long depth[500];
long long w[500][2];
long long x[500][2];
long long n, root, v[500], a, A, B, C;
pair<long long, long long> DEPTH[500];
long long mobile[500][2];
long long gcd(long long p, long long q) {
long long P = p, Q = q;
while (true) {
if (P % Q == 0) {
return Q;
}
if (Q % P == 0) {
return P;
}
if (P > Q) {
P = P % Q;
} else {
Q = Q % P;
}
}
}
int main() {
while (true) {
memset(depth, 0, sizeof(depth));
memset(w, 0, sizeof(w));
memset(x, 0, sizeof(x));
memset(v, 0, sizeof(v));
memset(DEPTH, 0, sizeof(DEPTH));
memset(mobile, 0, sizeof(mobile));
root = 0;
n = 0;
A = 0;
B = 0;
C = 0;
a = 0;
cin >> n;
if (n == 0) {
break;
}
for (int i = 1; i <= n; i++) {
v[i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> w[i][0] >> w[i][1] >> x[i][0] >> x[i][1];
v[x[i][0]] = 1;
v[x[i][1]] = 1;
a = gcd(w[i][0], w[i][1]);
w[i][0] /= a;
w[i][1] /= a;
}
for (int i = 1; i <= n; i++) {
if (v[i] == 0) {
root = i;
}
}
// depth.
for (int i = 1; i <= n; i++) {
depth[i] = 1000;
}
depth[root] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (depth[j] != 1000) {
depth[x[j][0]] = min(depth[x[j][0]], depth[j] + 1);
depth[x[j][1]] = min(depth[x[j][1]], depth[j] + 1);
}
}
}
for (int i = 1; i <= n; i++) {
DEPTH[i - 1].first = depth[i];
DEPTH[i - 1].second = i;
}
sort(DEPTH, DEPTH + n);
for (int i = n - 1; i >= 0; i--) {
A = DEPTH[i].first;
B = DEPTH[i].second;
if (x[B][0] == 0 && x[B][1] == 0) {
mobile[B][0] = w[B][1];
mobile[B][1] = w[B][0];
}
if (x[B][0] == 0 && x[B][1] >= 1) {
mobile[B][1] = mobile[x[B][1]][0] + mobile[x[B][1]][1];
mobile[B][1] = mobile[B][1] * w[B][0] / gcd(mobile[B][1], w[B][0]);
mobile[B][0] = mobile[B][1] * w[B][1] / w[B][0];
}
if (x[B][0] >= 1 && x[B][1] == 0) {
mobile[B][0] = mobile[x[B][0]][0] + mobile[x[B][0]][1];
mobile[B][0] = mobile[B][0] * w[B][1] / gcd(mobile[B][0], w[B][1]);
mobile[B][1] = mobile[B][0] * w[B][0] / w[B][1];
}
if (x[B][0] >= 1 && x[B][1] >= 1) {
mobile[B][0] = mobile[x[B][0]][0] + mobile[x[B][0]][1];
mobile[B][1] = mobile[x[B][1]][0] + mobile[x[B][1]][1];
C = mobile[B][0] * w[B][0] * mobile[B][1] * w[B][1] /
gcd(mobile[B][0] * w[B][0], mobile[B][1] * w[B][1]);
mobile[B][0] = C / w[B][0];
mobile[B][1] = C / w[B][0];
}
}
cout << mobile[root][0] + mobile[root][1] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
long long depth[500];
long long w[500][2];
long long x[500][2];
long long n, root, v[500], a, A, B, C;
pair<long long, long long> DEPTH[500];
long long mobile[500][2];
long long gcd(long long p, long long q) {
long long P = p, Q = q;
while (true) {
if (P % Q == 0) {
return Q;
}
if (Q % P == 0) {
return P;
}
if (P > Q) {
P = P % Q;
} else {
Q = Q % P;
}
}
}
int main() {
while (true) {
memset(depth, 0, sizeof(depth));
memset(w, 0, sizeof(w));
memset(x, 0, sizeof(x));
memset(v, 0, sizeof(v));
memset(DEPTH, 0, sizeof(DEPTH));
memset(mobile, 0, sizeof(mobile));
root = 0;
n = 0;
A = 0;
B = 0;
C = 0;
a = 0;
cin >> n;
if (n == 0) {
break;
}
for (int i = 1; i <= n; i++) {
v[i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> w[i][0] >> w[i][1] >> x[i][0] >> x[i][1];
v[x[i][0]] = 1;
v[x[i][1]] = 1;
a = gcd(w[i][0], w[i][1]);
w[i][0] /= a;
w[i][1] /= a;
}
for (int i = 1; i <= n; i++) {
if (v[i] == 0) {
root = i;
}
}
// depth.
for (int i = 1; i <= n; i++) {
depth[i] = 1000;
}
depth[root] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (depth[j] != 1000) {
depth[x[j][0]] = min(depth[x[j][0]], depth[j] + 1);
depth[x[j][1]] = min(depth[x[j][1]], depth[j] + 1);
}
}
}
for (int i = 1; i <= n; i++) {
DEPTH[i - 1].first = depth[i];
DEPTH[i - 1].second = i;
}
sort(DEPTH, DEPTH + n);
for (int i = n - 1; i >= 0; i--) {
A = DEPTH[i].first;
B = DEPTH[i].second;
if (x[B][0] == 0 && x[B][1] == 0) {
mobile[B][0] = w[B][1];
mobile[B][1] = w[B][0];
}
if (x[B][0] == 0 && x[B][1] >= 1) {
mobile[B][1] = mobile[x[B][1]][0] + mobile[x[B][1]][1];
mobile[B][1] = mobile[B][1] * w[B][0] / gcd(mobile[B][1], w[B][0]);
mobile[B][0] = mobile[B][1] * w[B][1] / w[B][0];
}
if (x[B][0] >= 1 && x[B][1] == 0) {
mobile[B][0] = mobile[x[B][0]][0] + mobile[x[B][0]][1];
mobile[B][0] = mobile[B][0] * w[B][1] / gcd(mobile[B][0], w[B][1]);
mobile[B][1] = mobile[B][0] * w[B][0] / w[B][1];
}
if (x[B][0] >= 1 && x[B][1] >= 1) {
mobile[B][0] = mobile[x[B][0]][0] + mobile[x[B][0]][1];
mobile[B][1] = mobile[x[B][1]][0] + mobile[x[B][1]][1];
C = mobile[B][0] * w[B][0] * mobile[B][1] * w[B][1] /
gcd(mobile[B][0] * w[B][0], mobile[B][1] * w[B][1]);
mobile[B][0] = C / w[B][0];
mobile[B][1] = C / w[B][1];
}
}
cout << mobile[root][0] + mobile[root][1] << endl;
}
return 0;
}
|
[["-", 0, 11, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 13]]
| 1
| 1,225
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, r[200], s[200], t[200], u[200], dp[200];
long long gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
long long dfs(int p) {
if (dp[p] >= 0)
return dp[p];
if (p == 0)
return 1;
long long J1 = dfs(t[p]), J2 = dfs(u[p]);
long long m1 = s[p] * J1, m2 = r[p] * J2;
long long r1 = m2 / gcd(m1, m2), r2 = m1 / gcd(m1, m2);
long long r3 = gcd(r1, r2);
r1 /= r3;
r2 /= r3;
long long minx = J1 * r1 + J2 * r2;
dp[p] = minx;
return minx;
}
int main() {
while (cin >> n, n) {
for (int i = 0; i <= n; i++)
dp[i] = -1;
for (int i = 1; i <= n; i++) {
cin >> r[i] >> s[i] >> t[i] >> u[i];
int H = gcd(r[i], s[i]);
r[i] /= H;
s[i] /= H;
}
long long maxn = 0;
for (int i = 1; i <= n; i++)
maxn = max(maxn, dfs(i));
cout << maxn << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, r[200], s[200], t[200], u[200], dp[200];
long long gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
long long dfs(int p) {
if (dp[p] >= 0)
return dp[p];
if (p == 0)
return 1;
long long J1 = dfs(t[p]), J2 = dfs(u[p]);
long long m1 = r[p] * J1, m2 = s[p] * J2;
long long r1 = m2 / gcd(m1, m2), r2 = m1 / gcd(m1, m2);
long long r3 = gcd(r1, r2);
r1 /= r3;
r2 /= r3;
long long minx = J1 * r1 + J2 * r2;
dp[p] = minx;
return minx;
}
int main() {
while (cin >> n, n) {
for (int i = 0; i <= n; i++)
dp[i] = -1;
for (int i = 1; i <= n; i++) {
cin >> r[i] >> s[i] >> t[i] >> u[i];
int H = gcd(r[i], s[i]);
r[i] /= H;
s[i] /= H;
}
long long maxn = 0;
for (int i = 1; i <= n; i++)
maxn = max(maxn, dfs(i));
cout << maxn << endl;
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 16, 31, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 69, 28, 22]]
| 1
| 355
|
//???????????¢????????§?????°????????¢?????????????§????
//??????????????¨?????¢????????????????????????????°??????¢?????????????§???????????????????????????¨???????????????
//???2 3??§?????£??????????????????????????????4
//6??§?????£?????????????????????????????????????????´?????????
//???????????????????????¨??????????????????????§??????????????????\?????¨????????????
//?§£?±??????????????????¢?????????????????? = ????°??????¢????????? *
//??´??°(>=1)???
//??????????????§?????£????????????????????§?????????????????????????¢?????????????????????????
#include <iostream>
#define int long long
using namespace std;
struct Bou {
int childl;
int childr;
int lengthl;
int lengthr;
void setBou(int p, int q, int r, int s) {
lengthl = p;
lengthr = q;
childl = r;
childr = s;
}
} bou[101];
int gcd(int a, int b) { return ((b > 0) ? gcd(b, a % b) : a); }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int dfs(int ind) {
//?????????
if (ind == 0) {
return 1;
}
//???
int lw = dfs(bou[ind].childl);
//???
int rw = dfs(bou[ind].childr);
int moment = lcm(lw * bou[ind].lengthr, rw * bou[ind].lengthl);
int ret = moment / bou[ind].lengthr + moment / bou[ind].lengthl;
return ret;
}
signed main() {
int n;
bool isRoot[101];
while (cin >> n) {
if (!n)
break;
for (int i = 1; i <= n; i++) {
isRoot[i] = true;
}
for (int i = 0; i < n; i++) {
int p, q, r, s;
cin >> p >> q >> r >> s;
bou[i + 1].setBou(p, q, r, s);
isRoot[r] = (isRoot[s] = false);
}
for (int i = 1; i <= n; i++) {
if (isRoot[i]) {
cout << dfs(i) << endl;
}
}
}
return 0;
}
|
//???????????¢????????§?????°????????¢?????????????§????
//??????????????¨?????¢????????????????????????????°??????¢?????????????§???????????????????????????¨???????????????
//???2 3??§?????£??????????????????????????????4
//6??§?????£?????????????????????????????????????????´?????????
//???????????????????????¨??????????????????????§??????????????????\?????¨????????????
//?§£?±??????????????????¢?????????????????? = ????°??????¢????????? *
//??´??°(>=1)???
//??????????????§?????£????????????????????§?????????????????????????¢?????????????????????????
#include <iostream>
#define int long long
using namespace std;
struct Bou {
int childl;
int childr;
int lengthl;
int lengthr;
void setBou(int p, int q, int r, int s) {
lengthl = p;
lengthr = q;
childl = r;
childr = s;
}
} bou[101];
int gcd(int a, int b) { return ((b > 0) ? gcd(b, a % b) : a); }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int dfs(int ind) {
//?????????
if (ind == 0) {
return 1;
}
//???
int lw = dfs(bou[ind].childl);
//???
int rw = dfs(bou[ind].childr);
int moment = lcm(lw * bou[ind].lengthl, rw * bou[ind].lengthr);
int ret = moment / bou[ind].lengthr + moment / bou[ind].lengthl;
return ret;
}
signed main() {
int n;
bool isRoot[101];
while (cin >> n) {
if (!n)
break;
for (int i = 1; i <= n; i++) {
isRoot[i] = true;
}
for (int i = 0; i < n; i++) {
int p, q, r, s;
cin >> p >> q >> r >> s;
bou[i + 1].setBou(p, q, r, s);
isRoot[r] = (isRoot[s] = false);
}
for (int i = 1; i <= n; i++) {
if (isRoot[i]) {
cout << dfs(i) << endl;
}
}
}
return 0;
}
|
[["-", 51, 2, 3, 4, 0, 16, 12, 118, 119, 120], ["+", 51, 2, 3, 4, 0, 16, 12, 118, 119, 120]]
| 1
| 378
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
long long int gcd(long long int l, long long int r) {
assert(l > 0 && r > 0);
if (l > r)
return gcd(r, l);
else {
const long long int num = r % l;
if (num) {
return gcd(l, num);
} else {
return l;
}
}
}
long long int lca(long long int l, long long int r) {
return l / gcd(l, r) * r;
}
struct mobi {
long long int a;
long long int b;
int lid;
int rid;
};
long long int getans(const int id, const vector<mobi> &ms) {
long long int lw = 0, rw = 0;
if (ms[id].lid != -1) {
lw = getans(ms[id].lid, ms);
} else {
lw = 1;
}
if (ms[id].rid != -1) {
rw = getans(ms[id].rid, ms);
} else {
rw = 1;
}
long long int al = lw * ms[id].b;
long long int ar = rw * ms[id].a;
long long int alca = lca(al, ar);
return alca / al * lw + alca / ar * rw;
}
int main() {
while (1) {
int N;
cin >> N;
if (!N)
break;
vector<mobi> ms;
vector<int> pas(N);
for (int i = 0; i < N; ++i) {
long long int a, b;
int lid, rid;
cin >> a >> b >> lid >> rid;
lid--;
rid--;
if (lid != -1)
pas[lid] = true;
if (rid != -1)
pas[rid] = true;
const long long int agcd = gcd(a, b);
a /= agcd;
b /= agcd;
ms.push_back(mobi{a, b, lid, rid});
}
int nopa = find(pas.begin(), pas.end(), 0) - pas.begin();
long long int ans = getans(nopa, ms);
cout << ans << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
long long int gcd(long long int l, long long int r) {
assert(l > 0 && r > 0);
if (l > r)
return gcd(r, l);
else {
const long long int num = r % l;
if (num) {
return gcd(l, num);
} else {
return l;
}
}
}
long long int lca(long long int l, long long int r) {
return l / gcd(l, r) * r;
}
struct mobi {
long long int a;
long long int b;
int lid;
int rid;
};
long long int getans(const int id, const vector<mobi> &ms) {
long long int lw = 0, rw = 0;
if (ms[id].lid != -1) {
lw = getans(ms[id].lid, ms);
} else {
lw = 1;
}
if (ms[id].rid != -1) {
rw = getans(ms[id].rid, ms);
} else {
rw = 1;
}
long long int al = lw * ms[id].a;
long long int ar = rw * ms[id].b;
long long int alca = lca(al, ar);
return alca / al * lw + alca / ar * rw;
}
int main() {
while (1) {
int N;
cin >> N;
if (!N)
break;
vector<mobi> ms;
vector<int> pas(N);
for (int i = 0; i < N; ++i) {
long long int a, b;
int lid, rid;
cin >> a >> b >> lid >> rid;
lid--;
rid--;
if (lid != -1)
pas[lid] = true;
if (rid != -1)
pas[rid] = true;
const long long int agcd = gcd(a, b);
a /= agcd;
b /= agcd;
ms.push_back(mobi{a, b, lid, rid});
}
int nopa = find(pas.begin(), pas.end(), 0) - pas.begin();
long long int ans = getans(nopa, ms);
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 16, 12, 118, 119, 120], ["+", 0, 43, 49, 50, 51, 16, 12, 118, 119, 120]]
| 1
| 513
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
#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); i >= 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;
const ll INF = 1 << 30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
int n;
struct stick {
int pr, qb, ri, bi;
};
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
long long g = gcd(a, b);
return a / g * b;
}
int dfs(int now, vector<vector<stick>> &st) {
int p = st[now][0].pr;
int q = st[now][0].qb;
int r = st[now][0].ri;
int b = st[now][0].bi;
int wr = 1;
int wb = 1;
if (r == 0 && b == 0)
return p + q;
if (r != 0)
wr = dfs(r, st);
if (b != 0)
wb = dfs(b, st);
int l = lcm(wr * q, wb * p);
return l / p + l / q;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
while (n != 0) {
vector<vector<stick>> st(105);
int cnt[105] = {};
rep(i, n) {
int p, q, r, b;
cin >> p >> q >> r >> b;
int g = gcd(p, q);
p /= g;
q /= g;
st[i + 1].pb(stick{p, q, r, b});
cnt[r] += 1;
cnt[b] += 1;
}
int s = 0;
// rep(i, 10) cout << cnt[i] << endl;
rep(i, n + 1) if (cnt[i] == 0) {
s = i;
break;
}
int ans = dfs(s, st);
cout << ans << endl;
cin >> n;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
#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); i >= 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;
const ll INF = 1 << 30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
int n;
struct stick {
int pr, qb, ri, bi;
};
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
long long g = gcd(a, b);
return a / g * b;
}
int dfs(int now, vector<vector<stick>> &st) {
int p = st[now][0].pr;
int q = st[now][0].qb;
int r = st[now][0].ri;
int b = st[now][0].bi;
int wr = 1;
int wb = 1;
if (r == 0 && b == 0)
return p + q;
if (r != 0)
wr = dfs(r, st);
if (b != 0)
wb = dfs(b, st);
int l = lcm(wr * p, wb * q);
return l / p + l / q;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
while (n != 0) {
vector<vector<stick>> st(105);
int cnt[105] = {};
rep(i, n) {
int p, q, r, b;
cin >> p >> q >> r >> b;
int g = gcd(p, q);
p /= g;
q /= g;
st[i + 1].pb(stick{p, q, r, b});
cnt[r] += 1;
cnt[b] += 1;
}
int s = 0;
rep(i, n + 1) if (cnt[i] == 0) {
s = i;
break;
}
int ans = dfs(s, st);
cout << ans << endl;
cin >> n;
}
}
|
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 12, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 648
|
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
struct Mobile {
int l, r, left, right, parent;
};
int n;
Mobile m[100];
int solve(int x) {
int Left, Right;
if (m[x].left == 0)
Left = 1;
else
Left = solve(m[x].left - 1);
if (m[x].right == 0)
Right = 1;
else
Right = solve(m[x].right - 1);
return lcm(Left * m[x].r, Right * m[x].l) / m[x].r +
lcm(Left * m[x].r, Right * m[x].l) / m[x].l;
}
int main() {
while (cin >> n, n) {
for (int i = 0; i < n; i++) {
m[i].l = 0, m[i].r = 0, m[i].left = 0, m[i].right = 0;
m[i].parent = -1;
}
for (int i = 0; i < n; i++) {
cin >> m[i].l >> m[i].r >> m[i].left >> m[i].right;
if (m[i].left != 0)
m[m[i].left - 1].parent = i;
if (m[i].right != 0)
m[m[i].right - 1].parent = i;
{
int l = m[i].l, r = m[i].r;
m[i].l = m[i].l / gcd(l, r), m[i].r = m[i].r / gcd(l, r);
}
}
int x = 0;
while (1) {
if (m[x].parent == -1) {
break;
}
x = m[x].parent;
}
cout << solve(x) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
struct Mobile {
int l, r, left, right, parent;
};
int n;
Mobile m[100];
int solve(int x) {
int Left, Right;
if (m[x].left == 0)
Left = 1;
else
Left = solve(m[x].left - 1);
if (m[x].right == 0)
Right = 1;
else
Right = solve(m[x].right - 1);
return lcm(Left * m[x].l, Right * m[x].r) / m[x].r +
lcm(Left * m[x].l, Right * m[x].r) / m[x].l;
}
int main() {
while (cin >> n, n) {
for (int i = 0; i < n; i++) {
m[i].l = 0, m[i].r = 0, m[i].left = 0, m[i].right = 0;
m[i].parent = -1;
}
for (int i = 0; i < n; i++) {
cin >> m[i].l >> m[i].r >> m[i].left >> m[i].right;
if (m[i].left != 0)
m[m[i].left - 1].parent = i;
if (m[i].right != 0)
m[m[i].right - 1].parent = i;
{
int l = m[i].l, r = m[i].r;
m[i].l = m[i].l / gcd(l, r), m[i].r = m[i].r / gcd(l, r);
}
}
int x = 0;
while (1) {
if (m[x].parent == -1) {
break;
}
x = m[x].parent;
}
cout << solve(x) << endl;
}
return 0;
}
|
[["-", 31, 2, 3, 4, 0, 16, 12, 118, 119, 120], ["+", 31, 2, 3, 4, 0, 16, 12, 118, 119, 120]]
| 1
| 503
|
#include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>
using namespace std;
long long gcd(long long x, long long y) {
while (y) {
long long t = x % y;
x = y;
y = t;
}
return x;
}
int rs[100], bs[100];
long long ps[100], qs[100], memo[100];
bool changed;
long long calc(int i) {
if (i == -1)
return 1;
if (memo[i] >= 0)
return memo[i];
changed = true;
long long r = calc(rs[i]);
long long b = calc(bs[i]);
long long p = ps[i];
long long q = qs[i];
long long left_factor = r * q; // b*left_factor
long long right_factor = b * p; // r*right_factor
long long fgcd = gcd(left_factor, right_factor);
left_factor /= fgcd;
right_factor /= fgcd;
memo[i] = b * left_factor + r * right_factor;
return memo[i];
}
int main() {
while (true) {
int n;
scanf("%d", &n);
if (n == 0)
break;
fill(memo, memo + n, -1);
for (int i = 0; i < n; i++) {
scanf("%lld%lld%d%d", ps + i, qs + i, rs + i, bs + i);
rs[i]--;
bs[i]--;
}
long long max_val = 0;
for (int i = 0; i < n; i++) {
changed = false;
long long val = calc(i);
if (changed)
max_val = val;
}
printf("%lld\n", max_val);
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>
using namespace std;
long long gcd(long long x, long long y) {
while (y) {
long long t = x % y;
x = y;
y = t;
}
return x;
}
int rs[100], bs[100];
long long ps[100], qs[100], memo[100];
bool changed;
long long calc(int i) {
if (i == -1)
return 1;
if (memo[i] >= 0)
return memo[i];
changed = true;
long long r = calc(rs[i]);
long long b = calc(bs[i]);
long long p = ps[i];
long long q = qs[i];
long long left_factor = r * p; // b*left_factor
long long right_factor = b * q; // r*right_factor
long long fgcd = gcd(left_factor, right_factor);
left_factor /= fgcd;
right_factor /= fgcd;
memo[i] = b * left_factor + r * right_factor;
return memo[i];
}
int main() {
while (true) {
int n;
scanf("%d", &n);
if (n == 0)
break;
fill(memo, memo + n, -1);
for (int i = 0; i < n; i++) {
scanf("%lld%lld%d%d", ps + i, qs + i, rs + i, bs + i);
rs[i]--;
bs[i]--;
}
long long max_val = 0;
for (int i = 0; i < n; i++) {
changed = false;
long long val = calc(i);
if (changed)
max_val = val;
}
printf("%lld\n", max_val);
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22]]
| 1
| 368
|
#include <cstdio>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef unsigned long long ull;
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
struct Node {
int p, q, l, r;
Node() {}
Node(int P, int Q, int L, int R) : p(P), q(Q), l(L), r(R) {}
} node[100];
ull dfs(int u) {
if (u == -1)
return 1;
int p = node[u].p, q = node[u].q, l = node[u].l, r = node[u].r;
ull wl = dfs(l), wr = dfs(r);
ull g = gcd(q * wl, p * wr);
ull m = p * wr / g, n = q * wl / g;
return m * wl + n * wr;
}
int main() {
for (int n; scanf("%d", &n), n;) {
rep(i, n) {
int p, q, l, r;
scanf("%d%d%d%d", &p, &q, &l, &r);
int g = gcd(p, q);
node[i] = Node(p / g, q / g, l - 1, r - 1);
}
int root;
bool b[100] = {};
rep(i, n) {
if (~node[i].l)
b[node[i].l] = true;
if (~node[i].r)
b[node[i].r] = true;
}
rep(i, n) if (!b[i]) {
root = i;
break;
}
printf("%llu\n", dfs(root));
}
return 0;
}
|
#include <cstdio>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef unsigned long long ull;
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
struct Node {
int p, q, l, r;
Node() {}
Node(int P, int Q, int L, int R) : p(P), q(Q), l(L), r(R) {}
} node[100];
ull dfs(int u) {
if (u == -1)
return 1;
int p = node[u].p, q = node[u].q, l = node[u].l, r = node[u].r;
ull wl = dfs(l), wr = dfs(r);
ull g = gcd(p * wl, q * wr);
ull m = q * wr / g, n = p * wl / g;
return m * wl + n * wr;
}
int main() {
for (int n; scanf("%d", &n), n;) {
rep(i, n) {
int p, q, l, r;
scanf("%d%d%d%d", &p, &q, &l, &r);
int g = gcd(p, q);
node[i] = Node(p / g, q / g, l - 1, r - 1);
}
int root;
bool b[100] = {};
rep(i, n) {
if (~node[i].l)
b[node[i].l] = true;
if (~node[i].r)
b[node[i].r] = true;
}
rep(i, n) if (!b[i]) {
root = i;
break;
}
printf("%llu\n", dfs(root));
}
return 0;
}
|
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22], ["-", 0, 43, 49, 50, 51, 16, 31, 16, 31, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 31, 22]]
| 1
| 412
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long gcd(long long a, long long b) { // Ååöñ
if (a == 0 || b == 0)
return 0;
if (b > a)
swap(a, b);
long long tmp;
while ((tmp = a % b) != 0) {
a = b;
b = tmp;
}
return b;
}
long long lcm(long long a, long long b) { // Ŭö{
return a / gcd(a, b) * b;
}
long long solve(vector<vector<int>> &stick, int i) {
if (i == 0)
return 1;
long long p = stick[i][0];
long long q = stick[i][1];
long long a = solve(stick, stick[i][2]);
long long b = solve(stick, stick[i][3]);
long long tmp = lcm(q * a, p * b);
a = tmp / q;
b = tmp / p;
return a + b;
}
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<vector<int>> stick(n + 1, vector<int>(4));
vector<bool> check(n + 1, false);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 4; ++j) {
cin >> stick[i][j];
}
check[stick[i][2]] = check[stick[i][3]] = true;
}
long long ret = 0;
for (int i = 1; i <= n; ++i) {
if (!check[i])
ret += solve(stick, i);
}
cout << ret << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long gcd(long long a, long long b) { // 最大公約数
if (a == 0 || b == 0)
return 0;
if (b > a)
swap(a, b);
long long tmp;
while ((tmp = a % b) != 0) {
a = b;
b = tmp;
}
return b;
}
long long lcm(long long a, long long b) { // 最小公倍数
return a / gcd(a, b) * b;
}
long long solve(vector<vector<int>> &stick, int i) {
if (i == 0)
return 1;
long long p = stick[i][0];
long long q = stick[i][1];
long long a = solve(stick, stick[i][2]);
long long b = solve(stick, stick[i][3]);
long long tmp = lcm(p * a, q * b);
a = tmp / p;
b = tmp / q;
return a + b;
}
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<vector<int>> stick(n + 1, vector<int>(4));
vector<bool> check(n + 1, false);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 4; ++j) {
cin >> stick[i][j];
}
check[stick[i][2]] = check[stick[i][3]] = true;
}
long long ret = 0;
for (int i = 1; i <= n; ++i) {
if (!check[i])
ret += solve(stick, i);
}
cout << ret << endl;
}
}
|
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
| 1
| 426
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c) \
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;
int gcd(int a, int b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int p[101], q[101], r[101], b[101];
int dfs(int s) {
if (s == 0)
return 1;
int red = dfs(r[s]), blue = dfs(b[s]);
int t = lcm(red * q[s], blue * p[s]);
return t / p[s] + t / q[s];
}
int main() {
int n;
while (~scanf("%d", &n) && n) {
bool root[101];
fill(root, root + 101, true);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d%d", p + i, q + i, r + i, b + i);
root[r[i]] = root[b[i]] = false;
}
int res = 0;
for (int i = 1; i <= n; ++i)
if (root[i])
res = dfs(i);
printf("%d\n", res);
}
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c) \
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;
int gcd(int a, int b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int p[101], q[101], r[101], b[101];
int dfs(int s) {
if (s == 0)
return 1;
int red = dfs(r[s]), blue = dfs(b[s]);
int t = lcm(red * p[s], blue * q[s]);
return t / p[s] + t / q[s];
}
int main() {
int n;
while (~scanf("%d", &n) && n) {
bool root[101];
fill(root, root + 101, true);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d%d", p + i, q + i, r + i, b + i);
root[r[i]] = root[b[i]] = false;
}
int res = 0;
for (int i = 1; i <= n; ++i)
if (root[i])
res = dfs(i);
printf("%d\n", res);
}
}
|
[["-", 51, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["+", 51, 2, 3, 4, 0, 16, 12, 69, 28, 22]]
| 1
| 430
|
#include <cstdio>
int n, tn, hn, turn, card;
bool t[201], h[201];
int main() {
while (scanf("%d", &n)) {
if (n == 0)
break;
tn = n;
hn = n;
turn = 1;
card = 0;
for (int i = 1; i <= 200; i++) {
t[i] = false;
h[i] = false;
}
for (int i = 1; i <= n; i++) {
int tmp;
scanf("%d", &tmp);
t[tmp] = true;
}
for (int i = 1; i <= 2 * n; i++)
if (!t[i])
h[i] = true;
while (true) {
bool ok = true;
if (tn == 0 || hn == 0) {
printf("%d\n%d\n", hn, tn);
break;
}
if (turn == 1) {
for (int i = card + 1; i <= 2 * n; i++) {
if (t[i]) {
t[i] = false;
card = i;
turn = 2;
tn--;
ok = false;
break;
}
}
if (ok) {
turn = 2;
card = 0;
}
} else {
for (int i = card + 1; i <= 2 * n; i++) {
if (h[i]) {
h[i] = false;
card = i;
turn = 1;
hn--;
break;
}
}
if (ok) {
turn = 1;
card = 0;
}
}
}
}
}
|
#include <cstdio>
int n, tn, hn, turn, card;
bool t[201], h[201];
int main() {
while (scanf("%d", &n)) {
if (n == 0)
break;
tn = n;
hn = n;
turn = 1;
card = 0;
for (int i = 1; i <= 200; i++) {
t[i] = false;
h[i] = false;
}
for (int i = 1; i <= n; i++) {
int tmp;
scanf("%d", &tmp);
t[tmp] = true;
}
for (int i = 1; i <= 2 * n; i++)
if (!t[i])
h[i] = true;
while (true) {
bool ok = true;
if (tn == 0 || hn == 0) {
printf("%d\n%d\n", hn, tn);
break;
}
if (turn == 1) {
for (int i = card + 1; i <= 2 * n; i++) {
if (t[i]) {
t[i] = false;
card = i;
turn = 2;
tn--;
ok = false;
break;
}
}
if (ok) {
turn = 2;
card = 0;
}
} else {
for (int i = card + 1; i <= 2 * n; i++) {
if (h[i]) {
h[i] = false;
card = i;
turn = 1;
hn--;
ok = false;
break;
}
}
if (ok) {
turn = 1;
card = 0;
}
}
}
}
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 147], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 345
|
#include <stdio.h>
int main(void) {
int n;
int t[10000], h[10000];
int jun, ba, tc, hc;
int flg[10000];
int ban[10000];
int i, j, temp;
scanf("%d", &n);
while (n != 0) {
for (i = 1; i <= 2 * n; i++) {
flg[i] == 0;
ban[i] = i;
}
for (i = 1; i <= n; i++) {
scanf("%d", &t[i]);
}
for (i = 1; i <= n - 1; i++) {
for (j = i + 1; j <= n; j++) {
if (t[i] > t[j]) {
temp = t[i];
t[i] = t[j];
t[j] = temp;
}
}
}
for (i = 1; i <= n * 2; i++) {
for (j = 1; j <= n; j++) {
if (t[j] == ban[i]) {
flg[i] = 1;
}
}
}
j = 1;
for (i = 1; i <= 2 * n; i++) {
if (flg[i] == 0) {
h[j] = i;
j++;
}
}
tc = n;
hc = n;
ba = 0;
jun = 0;
while (!(tc == 0 || hc == 0)) {
if (jun == 0) {
for (i = 1; i <= n; i++) {
if (ba < t[i]) {
jun = 1;
tc--;
ba = t[i];
t[i] = 0;
break;
}
}
if (i == n + 1) {
jun = 1;
ba = 0;
}
} else if (jun == 1) {
for (i = 1; i <= n; i++) {
if (ba < h[i]) {
jun = 0;
hc--;
ba = h[i];
h[i] = 0;
break;
}
}
if (i == n + 1) {
ba = 0;
jun = 0;
}
}
}
printf("%d\n%d", hc, tc);
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n;
int t[10000], h[10000];
int jun, ba, tc, hc;
int flg[10000];
int ban[10000];
int i, j, temp;
scanf("%d", &n);
while (n != 0) {
for (i = 1; i <= 2 * n; i++) {
flg[i] = 0;
ban[i] = i;
}
for (i = 1; i <= n; i++) {
scanf("%d", &t[i]);
}
for (i = 1; i <= n - 1; i++) {
for (j = i + 1; j <= n; j++) {
if (t[i] > t[j]) {
temp = t[i];
t[i] = t[j];
t[j] = temp;
}
}
}
for (i = 1; i <= 2 * n; i++) {
for (j = 1; j <= n; j++) {
if (t[j] == ban[i]) {
flg[i] = 1;
}
}
}
j = 1;
for (i = 1; i <= 2 * n; i++) {
if (flg[i] == 0) {
h[j] = i;
j++;
}
}
tc = n;
hc = n;
ba = 0;
jun = 0;
while (!(tc == 0 || hc == 0)) {
if (jun == 0) {
for (i = 1; i <= n; i++) {
if (ba < t[i]) {
jun = 1;
tc--;
ba = t[i];
t[i] = 0;
break;
}
}
if (i == n + 1) {
jun = 1;
ba = 0;
}
} else if (jun == 1) {
for (i = 1; i <= n; i++) {
if (ba < h[i]) {
jun = 0;
hc--;
ba = h[i];
h[i] = 0;
break;
}
}
if (i == n + 1) {
ba = 0;
jun = 0;
}
}
}
printf("%d\n%d\n", hc, tc);
scanf("%d", &n);
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 16, 17, 60], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 503
|
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
int n;
int taro[200];
while (true) {
set<int> cards[2];
int top = 0;
cin >> n;
if (n == 0) {
return 0;
}
for (int i = 0; i < n; ++i) {
cin >> taro[i];
}
cards[0].clear();
cards[1].clear();
for (int i = 0; i < n; ++i) {
cards[0].insert(taro[i]);
}
for (int i = 1; i <= 2 * n; ++i) {
if (cards[0].count(i) == 0) {
cards[1].insert(i);
}
}
for (int i = 0; cards[0].size() * cards[0].size() > 0; ++i) {
set<int>::iterator iter =
upper_bound(cards[i % 2].begin(), cards[i % 2].end(), top);
if (iter == cards[i % 2].end()) {
top = 0;
} else {
top = *iter;
cards[i % 2].erase(iter);
}
}
cout << cards[1].size() << endl << cards[0].size() << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
int n;
int taro[200];
while (true) {
set<int> cards[2];
int top = 0;
cin >> n;
if (n == 0) {
return 0;
}
for (int i = 0; i < n; ++i) {
cin >> taro[i];
}
cards[0].clear();
cards[1].clear();
for (int i = 0; i < n; ++i) {
cards[0].insert(taro[i]);
}
for (int i = 1; i <= 2 * n; ++i) {
if (cards[0].count(i) == 0) {
cards[1].insert(i);
}
}
for (int i = 0; cards[0].size() * cards[1].size() > 0; ++i) {
set<int>::iterator iter =
upper_bound(cards[i % 2].begin(), cards[i % 2].end(), top);
if (iter == cards[i % 2].end()) {
top = 0;
} else {
top = *iter;
cards[i % 2].erase(iter);
}
}
cout << cards[1].size() << endl << cards[0].size() << endl;
}
}
|
[["-", 12, 2, 63, 118, 28, 69, 341, 342, 0, 13], ["+", 12, 2, 63, 118, 28, 69, 341, 342, 0, 13]]
| 1
| 306
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int i;
int n;
int tcard[100];
int hcard[100];
int ncard = 0, turn = 0;
int tscore[100];
int hscore[100];
for (i = 0;; i++) {
cin >> n;
if (n == 0) {
break;
}
ncard = 0;
turn = 0;
for (int a = 0; a < n; a++) {
tcard[a] = 0;
hcard[a] = 0;
}
tscore[i] = n;
hscore[i] = n;
for (int a = 0; a < n; a++) {
cin >> tcard[a];
}
sort(tcard, tcard + n);
int b = 0;
int c = 1;
for (int a = 0; a < n;) {
if (c < tcard[b]) {
hcard[a] = c;
a++;
c++;
} else {
b++;
c++;
}
}
for (;;) {
if (turn == 0) {
for (int b = 0; b <= n; b++) {
if (b == n) {
ncard = 0;
turn = 1;
}
if (ncard < tcard[b]) {
ncard = tcard[b];
tcard[b] = -1;
hscore[i]--;
turn = 1;
break;
}
}
}
if (hscore[i] == 0 || tscore[i] == 0) {
break;
}
if (turn == 1) {
for (int b = 0; b <= n; b++) {
if (b == n) {
ncard = 0;
turn = 0;
}
if (ncard < hcard[b]) {
ncard = hcard[b];
hcard[b] = -1;
tscore[i]--;
turn = 0;
break;
}
}
}
if (hscore[i] == 0 || tscore[i] == 0) {
break;
}
}
}
for (int a = 0; a < i; a++) {
cout << tscore[a] << endl;
cout << hscore[a] << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int i;
int n;
int tcard[100];
int hcard[100];
int ncard = 0, turn = 0;
int tscore[100];
int hscore[100];
for (i = 0;; i++) {
cin >> n;
if (n == 0) {
break;
}
ncard = 0;
turn = 0;
for (int a = 0; a < n; a++) {
tcard[a] = 0;
hcard[a] = 0;
}
tscore[i] = n;
hscore[i] = n;
for (int a = 0; a < n; a++) {
cin >> tcard[a];
}
sort(tcard, tcard + n);
int b = 0;
int c = 1;
for (int a = 0; a < n;) {
if (c < tcard[b]) {
hcard[a] = c;
a++;
c++;
} else {
b++;
c++;
}
}
for (;;) {
if (turn == 0) {
for (int b = 0; b <= n; b++) {
if (b == n) {
ncard = 0;
turn = 1;
} else if (ncard < tcard[b]) {
ncard = tcard[b];
tcard[b] = -1;
hscore[i]--;
turn = 1;
break;
}
}
}
if (hscore[i] == 0 || tscore[i] == 0) {
break;
}
if (turn == 1) {
for (int b = 0; b <= n; b++) {
if (b == n) {
ncard = 0;
turn = 0;
} else if (ncard < hcard[b]) {
ncard = hcard[b];
hcard[b] = -1;
tscore[i]--;
turn = 0;
break;
}
}
}
if (hscore[i] == 0 || tscore[i] == 0) {
break;
}
}
}
for (int a = 0; a < i; a++) {
cout << tscore[a] << endl;
cout << hscore[a] << endl;
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 458
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N, C;
vector<int> Card[2];
vector<bool> A;
int main() {
while (true) {
cin >> N;
if (N == 0) {
break;
}
A.clear();
A = vector<bool>(2 * N + 1, false);
for (int i = 0; i < N; i++) {
cin >> C;
A[C] = true;
}
Card[1].clear();
Card[2].clear();
for (int i = 1; i <= 2 * N; i++) {
if (A[i] == true) {
Card[0].push_back(i);
} else {
Card[1].push_back(i);
}
}
int turn = 0;
int max_card = 0;
while (Card[0].size() != 0 && Card[1].size() != 0) {
int ptr = distance(
Card[turn].begin(),
lower_bound(Card[turn].begin(), Card[turn].end(), max_card + 1));
if (ptr != Card[turn].size()) {
max_card = Card[turn][ptr];
Card[turn].erase(Card[turn].begin() + ptr);
} else {
max_card = 0;
}
if (turn == 0) {
turn = 1;
} else {
turn = 0;
}
}
cout << Card[1].size() << endl;
cout << Card[0].size() << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N, C;
vector<int> Card[2];
vector<bool> A;
int main() {
while (true) {
cin >> N;
if (N == 0) {
break;
}
A.clear();
A = vector<bool>(2 * N + 1, false);
for (int i = 0; i < N; i++) {
cin >> C;
A[C] = true;
}
Card[0].clear();
Card[1].clear();
for (int i = 1; i <= 2 * N; i++) {
if (A[i] == true) {
Card[0].push_back(i);
} else {
Card[1].push_back(i);
}
}
int turn = 0;
int max_card = 0;
while (Card[0].size() != 0 && Card[1].size() != 0) {
int ptr = distance(
Card[turn].begin(),
lower_bound(Card[turn].begin(), Card[turn].end(), max_card + 1));
if (ptr != Card[turn].size()) {
max_card = Card[turn][ptr];
Card[turn].erase(Card[turn].begin() + ptr);
} else {
max_card = 0;
}
if (turn == 0) {
turn = 1;
} else {
turn = 0;
}
}
cout << Card[1].size() << endl;
cout << Card[0].size() << endl;
}
return 0;
}
|
[["-", 0, 2, 63, 118, 28, 69, 341, 342, 0, 13], ["+", 0, 2, 63, 118, 28, 69, 341, 342, 0, 13]]
| 1
| 350
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, h;
while (cin >> n, n) {
t = h = n;
bool taro[2 * n] = {false}, hana[2 * n] = {false};
for (int i = 0; i < n; i++) {
int num;
cin >> num;
taro[num] = true;
}
for (int i = 1; i <= 2 * n; i++)
if (!taro[i])
hana[i] = true;
bool f;
int field = 0;
while (1) {
f = false;
for (int i = field + 1; i <= 2 * n; i++) {
if (taro[i]) {
taro[i] = false;
field = i;
f = true;
t--;
break;
}
}
if (t == 0 || h == 0) {
cout << h << '\n' << t << '\n';
break;
}
if (!f)
field = 0;
else
f = false;
for (int i = field + 1; i <= 2 * n; i++) {
if (hana[i]) {
hana[i] = false;
field = i;
f = true;
h--;
break;
}
}
if (!f)
field = 0;
else
f = false;
if (t == 0 || h == 0) {
cout << h << '\n' << t << '\n';
break;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, h;
while (cin >> n, n) {
t = h = n;
bool taro[2 * n + 5] = {false}, hana[2 * n + 5] = {false};
for (int i = 0; i < n; i++) {
int num;
cin >> num;
taro[num] = true;
}
for (int i = 1; i <= 2 * n; i++)
if (!taro[i])
hana[i] = true;
bool f;
int field = 0;
while (1) {
f = false;
for (int i = field + 1; i <= 2 * n; i++) {
if (taro[i]) {
taro[i] = false;
field = i;
f = true;
t--;
break;
}
}
if (t == 0 || h == 0) {
cout << h << '\n' << t << '\n';
break;
}
if (!f)
field = 0;
else
f = false;
for (int i = field + 1; i <= 2 * n; i++) {
if (hana[i]) {
hana[i] = false;
field = i;
f = true;
h--;
break;
}
}
if (!f)
field = 0;
else
f = false;
if (t == 0 || h == 0) {
cout << h << '\n' << t << '\n';
break;
}
}
}
}
|
[["+", 0, 43, 49, 50, 49, 80, 81, 16, 17, 72], ["+", 0, 43, 49, 50, 49, 80, 81, 16, 12, 13]]
| 1
| 319
|
#include <bits/stdc++.h>
using namespace std;
//{{{
/********************************************************************/
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;
#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)
#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)
const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
vector<string> split(const string &s, char delim) {
vector<string> elems;
string item;
for (char ch : s) {
if (ch == delim) {
if (!item.empty())
elems.push_back(item);
item.clear();
} else
item += ch;
}
if (!item.empty())
elems.push_back(item);
return elems;
}
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline int in() {
int x;
std::cin >> x;
return x;
}
template <typename T> void print(std::vector<T> &v, char c = ' ') {
REP(i, v.size()) {
if (i != 0)
std::cout << c;
std::cout << v[i];
}
std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }
/****************************************************************/
//}}}
vector<set<int>> s(2);
int n;
void game(int a, int player) {
if (!sz(s[0]) or !sz(s[1]))
return;
auto itr = s[player].upper_bound(a);
if (itr == s[player].end()) {
game(0, abs(player - 1));
return;
}
s[player].erase(*itr);
game(*itr, abs(player - 1));
}
signed main() {
while (cin >> n, n) {
rep(i, 2) s[0].clear();
rep(i, n) s[0].insert(in());
reps(i, 1, n * 2 + 1) if (s[0].find(i) == s[0].end()) s[1].insert(i);
game(0, 0);
reverse(all(s));
for (auto a : s)
print(sz(a));
}
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
//{{{
/********************************************************************/
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;
#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)
#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)
const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
vector<string> split(const string &s, char delim) {
vector<string> elems;
string item;
for (char ch : s) {
if (ch == delim) {
if (!item.empty())
elems.push_back(item);
item.clear();
} else
item += ch;
}
if (!item.empty())
elems.push_back(item);
return elems;
}
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline int in() {
int x;
std::cin >> x;
return x;
}
template <typename T> void print(std::vector<T> &v, char c = ' ') {
REP(i, v.size()) {
if (i != 0)
std::cout << c;
std::cout << v[i];
}
std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }
/****************************************************************/
//}}}
vector<set<int>> s(2);
int n;
void game(int a, int player) {
if (!sz(s[0]) or !sz(s[1]))
return;
auto itr = s[player].upper_bound(a);
if (itr == s[player].end()) {
game(0, abs(player - 1));
return;
}
s[player].erase(*itr);
game(*itr, abs(player - 1));
}
signed main() {
while (cin >> n, n) {
rep(i, 2) s[i].clear();
rep(i, n) s[0].insert(in());
reps(i, 1, n * 2 + 1) if (s[0].find(i) == s[0].end()) s[1].insert(i);
game(0, 0);
reverse(all(s));
for (auto a : s)
print(sz(a));
}
return (0);
}
|
[["-", 0, 2, 63, 118, 28, 69, 341, 342, 0, 13], ["+", 0, 2, 63, 118, 28, 69, 341, 342, 0, 22]]
| 1
| 732
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n;
while (cin >> n, n) {
set<int> s;
s.insert(0);
vector<int> a, b;
int c = 0, t;
r(i, n) cin >> t, a.push_back(t), s.insert(t);
r(i, n * 2 + 1) if (!s.count(i)) b.push_back(i);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
while (1) {
int cc = 0;
r(i, a.size()) if (a[i] > c) {
c = a[i];
cc++;
a.erase(a.begin() + i);
break;
}
if (!a.size())
break;
if (!cc)
c = 0;
cc = 0;
r(i, b.size()) if (b[i] > c) {
c = b[i];
cc++;
b.erase(b.begin() + i);
break;
}
if (!b.size())
break;
if (!cc)
c = 0;
}
cout << b.size() << ' ' << a.size() << endl;
}
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n;
while (cin >> n, n) {
set<int> s;
s.insert(0);
vector<int> a, b;
int c = 0, t;
r(i, n) cin >> t, a.push_back(t), s.insert(t);
r(i, n * 2 + 1) if (!s.count(i)) b.push_back(i);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
while (1) {
int cc = 0;
r(i, a.size()) if (a[i] > c) {
c = a[i];
cc++;
a.erase(a.begin() + i);
break;
}
if (!a.size())
break;
if (!cc)
c = 0;
cc = 0;
r(i, b.size()) if (b[i] > c) {
c = b[i];
cc++;
b.erase(b.begin() + i);
break;
}
if (!b.size())
break;
if (!cc)
c = 0;
}
cout << b.size() << endl << a.size() << endl;
}
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 104], ["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 125], ["+", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22]]
| 1
| 313
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); ++i)
#define in cin
#define out cout
#define pb push_back
using namespace std;
int main() {
int n;
while (in >> n) {
if (!n)
break;
int a[100], b[100];
int id = 0;
REP(i, n) { in >> a[i]; }
FOR(i, 1, n * 2) {
int c = 0;
REP(j, n) {
if (a[j] == i) {
c = 1;
break;
}
}
if (!c) {
b[id++] = i;
}
}
int ba = 0, te = 0;
while (1) {
int dasita = 0;
sort(a, a + n);
sort(b, b + n);
if (a[0] == 999 || b[0] == 999)
break;
if (!ba) {
if (!te) {
ba = a[0];
te ^= 1;
a[0] = 999;
} else {
ba = b[0];
te ^= 1;
b[0] = 999;
}
} else {
if (!te) {
REP(i, n) {
if (ba < a[i] && a[i] != 999) {
ba = a[i];
a[i] = 999;
dasita = 1;
break;
}
}
if (!dasita)
ba = 0;
te ^= 1;
} else {
REP(i, n) {
if (ba < b[i] && b[i] != 999) {
ba = b[i];
b[i] = 999;
dasita = 1;
break;
}
}
if (!dasita)
ba = 0;
te ^= 1;
}
}
}
int ac = 0, bc = 0;
REP(i, n) {
if (a[i] != 999)
ac++;
if (b[i] != 999)
bc++;
}
out << "aaa" << bc << endl << ac << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); ++i)
#define in cin
#define out cout
#define pb push_back
using namespace std;
int main() {
int n;
while (in >> n) {
if (!n)
break;
int a[100], b[100];
int id = 0;
REP(i, n) { in >> a[i]; }
FOR(i, 1, n * 2) {
int c = 0;
REP(j, n) {
if (a[j] == i) {
c = 1;
break;
}
}
if (!c) {
b[id++] = i;
}
}
int ba = 0, te = 0;
while (1) {
int dasita = 0;
sort(a, a + n);
sort(b, b + n);
if (a[0] == 999 || b[0] == 999)
break;
if (!ba) {
if (!te) {
ba = a[0];
te ^= 1;
a[0] = 999;
} else {
ba = b[0];
te ^= 1;
b[0] = 999;
}
} else {
if (!te) {
REP(i, n) {
if (ba < a[i] && a[i] != 999) {
ba = a[i];
a[i] = 999;
dasita = 1;
break;
}
}
if (!dasita)
ba = 0;
te ^= 1;
} else {
REP(i, n) {
if (ba < b[i] && b[i] != 999) {
ba = b[i];
b[i] = 999;
dasita = 1;
break;
}
}
if (!dasita)
ba = 0;
te ^= 1;
}
}
}
int ac = 0, bc = 0;
REP(i, n) {
if (a[i] != 999)
ac++;
if (b[i] != 999)
bc++;
}
out << bc << endl << ac << endl;
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 151]]
| 1
| 477
|
#include <iostream>
using namespace std;
int main() {
int n;
int H[101];
int T[101];
while (1) {
cin >> n;
int C = 0;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> T[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (T[i] > T[j])
swap(T[i], T[j]);
}
}
int s = 0;
for (int i = 1; i <= 2 * n; i++) {
for (int j = 0; j < n; j++) {
if (i == T[j])
break;
else if (j == n - 1) {
H[s++] = i;
}
}
}
int t = 0;
int n_t = n, n_h = n;
while (!(n_t == 0) && !(n_h == 0)) {
for (int i = 0; i < n; i++) {
if (T[i] > C) {
C = T[i];
T[i] = 0;
n_t--;
break;
} else if (i == n - 1) {
C = 0;
}
}
if (n_t == 0 || n_h == 0)
break;
for (int i = 0; i < n; i++) {
if (H[i] > C) {
C = H[i];
H[i] = 0;
n_h--;
break;
} else if (i == n - 1) {
C = 0;
}
}
t++;
}
cout << n_t << endl;
cout << n_h << endl;
}
}
|
// ?????? ??????????????????
#include <iostream>
using namespace std;
int main() {
int n;
int H[101];
int T[101];
while (1) {
cin >> n;
int C = 0;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> T[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (T[i] > T[j])
swap(T[i], T[j]);
}
}
int s = 0;
for (int i = 1; i <= 2 * n; i++) {
for (int j = 0; j < n; j++) {
if (i == T[j])
break;
else if (j == n - 1) {
H[s++] = i;
}
}
}
int t = 0;
int n_t = n, n_h = n;
while (!(n_t == 0) && !(n_h == 0)) {
for (int i = 0; i < n; i++) {
if (T[i] > C) {
C = T[i];
T[i] = 0;
n_t--;
break;
} else if (i == n - 1) {
C = 0;
}
}
if (n_t == 0 || n_h == 0)
break;
for (int i = 0; i < n; i++) {
if (H[i] > C) {
C = H[i];
H[i] = 0;
n_h--;
break;
} else if (i == n - 1) {
C = 0;
}
}
t++;
}
cout << n_h << endl;
cout << n_t << endl;
}
}
|
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 384
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a, t) for (int a = 0; a < t; a++)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pop_front(a) a.erase(a.begin())
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
forever {
vector<int> taro, hanako;
cin >> n;
if (n == 0) {
break;
}
loop(i, n) {
int u;
cin >> u;
taro.push_back(u);
}
Sort(taro);
for (int i = 1; i <= 2 * n; i++) {
bool flag = false;
for (int j = 0; j < taro.size(); j++) {
if (taro[j] == i) {
flag = true;
}
}
if (!flag) {
hanako.push_back(i);
}
}
int now_card = 0; //今のカード
bool turn = true; // true taro, false hanako
forever {
if (taro.size() == 0 || hanako.size() == 0) {
cout << taro.size() << endl << hanako.size() << endl;
break;
}
if (turn) {
for (int i = 0; i < taro.size(); i++) {
if (taro[i] > now_card) {
now_card = taro[i];
taro.erase(taro.begin() + i);
break;
}
if (i == taro.size() - 1) {
now_card = 0;
}
}
} else {
for (int i = 0; i < hanako.size(); i++) {
if (hanako[i] > now_card) {
now_card = hanako[i];
hanako.erase(hanako.begin() + i);
break;
}
if (i == hanako.size() - 1) {
now_card = 0;
}
}
}
turn = !turn;
}
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a, t) for (int a = 0; a < t; a++)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pop_front(a) a.erase(a.begin())
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
forever {
vector<int> taro, hanako;
cin >> n;
if (n == 0) {
break;
}
loop(i, n) {
int u;
cin >> u;
taro.push_back(u);
}
Sort(taro);
for (int i = 1; i <= 2 * n; i++) {
bool flag = false;
for (int j = 0; j < taro.size(); j++) {
if (taro[j] == i) {
flag = true;
}
}
if (!flag) {
hanako.push_back(i);
}
}
int now_card = 0; //今のカード
bool turn = true; // true taro, false hanako
forever {
if (taro.size() == 0 || hanako.size() == 0) {
cout << hanako.size() << endl << taro.size() << endl;
break;
}
if (turn) {
for (int i = 0; i < taro.size(); i++) {
if (taro[i] > now_card) {
now_card = taro[i];
taro.erase(taro.begin() + i);
break;
}
if (i == taro.size() - 1) {
now_card = 0;
}
}
} else {
for (int i = 0; i < hanako.size(); i++) {
if (hanako[i] > now_card) {
now_card = hanako[i];
hanako.erase(hanako.begin() + i);
break;
}
if (i == hanako.size() - 1) {
now_card = 0;
}
}
}
turn = !turn;
}
}
return 0;
}
|
[["-", 31, 16, 31, 16, 12, 2, 63, 118, 28, 22], ["+", 31, 16, 31, 16, 12, 2, 63, 118, 28, 22], ["-", 0, 16, 31, 16, 12, 2, 63, 118, 28, 22], ["+", 0, 16, 31, 16, 12, 2, 63, 118, 28, 22]]
| 1
| 448
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.