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
| change_count
int64 0
100
|
|---|---|---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int hand[5], result[5];
int rock, scissors, paper, win;
while (cin >> hand[0], hand[0]) {
cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
rock = scissors = paper = 0;
for (int i = 0; i < 5; ++i) {
switch (hand[i]) {
case 1:
++rock;
break;
case 2:
++scissors;
break;
case 3:
++paper;
break;
default:
break;
}
}
if (rock == 5 || scissors == 5 || paper == 5 ||
(rock > 0 && scissors > 0 && paper > 0)) {
for (int i = 0; i < 5; ++i)
result[i] = 3;
} else {
if (rock == 0)
win = 2;
else if (scissors = 0)
win = 3;
else
win = 1;
for (int i = 0; i < 5; ++i) {
if (hand[i] == win)
result[i] = 1;
else
result[i] = 2;
}
}
for (int i = 0; i < 5; ++i)
cout << result[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int hand[5], result[5];
int rock, scissors, paper, win;
while (cin >> hand[0], hand[0]) {
cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
rock = scissors = paper = 0;
for (int i = 0; i < 5; ++i) {
switch (hand[i]) {
case 1:
++rock;
break;
case 2:
++scissors;
break;
case 3:
++paper;
break;
default:
break;
}
}
if (rock == 5 || scissors == 5 || paper == 5 ||
(rock > 0 && scissors > 0 && paper > 0)) {
for (int i = 0; i < 5; ++i)
result[i] = 3;
} else {
if (rock == 0)
win = 2;
else if (scissors == 0)
win = 3;
else
win = 1;
for (int i = 0; i < 5; ++i) {
if (hand[i] == win)
result[i] = 1;
else
result[i] = 2;
}
}
for (int i = 0; i < 5; ++i)
cout << result[i] << endl;
}
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 277
| 2
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while (1) {
int a, b, c, d, e;
cin >> a;
if (a == 0)
break;
cin >> b >> c >> d >> e;
if (a == b == c == d == e) {
cout << "3\n3\n3\n3\n3\n";
continue;
}
vector<int> f(5);
vector<int> q(5);
f[0] = a;
f[1] = b;
f[2] = c;
f[3] = d;
f[4] = e;
q[0] = a;
q[1] = b;
q[2] = c;
q[3] = d;
q[4] = e;
sort(f.begin(), f.end());
if (f[0] == 1 && (f[1] == 2 || f[2] == 2 || f[3] == 2) && f[4] == 3) {
cout << "3\n3\n3\n3\n3\n";
continue;
}
if (f[0] == 2) {
for (int i = 0; i < 5; i++) {
if (q[i] == 2)
cout << 1 << endl;
else
cout << 2 << endl;
}
continue;
}
if (f[4] == 3) {
for (int i = 0; i < 5; i++) {
if (q[i] == 3)
cout << 1 << endl;
else
cout << 2 << endl;
}
continue;
} else {
for (int i = 0; i < 5; i++) {
if (q[i] == 1)
cout << 1 << endl;
else
cout << 2 << endl;
}
continue;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while (1) {
int a, b, c, d, e;
cin >> a;
if (a == 0)
break;
cin >> b >> c >> d >> e;
if (a == b && b == c && c == d && d == e) {
cout << "3\n3\n3\n3\n3\n";
continue;
}
vector<int> f(5);
vector<int> q(5);
f[0] = a;
f[1] = b;
f[2] = c;
f[3] = d;
f[4] = e;
q[0] = a;
q[1] = b;
q[2] = c;
q[3] = d;
q[4] = e;
sort(f.begin(), f.end());
if (f[0] == 1 && (f[1] == 2 || f[2] == 2 || f[3] == 2) && f[4] == 3) {
cout << "3\n3\n3\n3\n3\n";
continue;
}
if (f[0] == 2) {
for (int i = 0; i < 5; i++) {
if (q[i] == 2)
cout << 1 << endl;
else
cout << 2 << endl;
}
continue;
}
if (f[4] == 3) {
for (int i = 0; i < 5; i++) {
if (q[i] == 3)
cout << 1 << endl;
else
cout << 2 << endl;
}
continue;
} else {
for (int i = 0; i < 5; i++) {
if (q[i] == 1)
cout << 1 << endl;
else
cout << 2 << endl;
}
continue;
}
}
}
|
[["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 98], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 98], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 394
| 6
|
#include <iostream>
using namespace std;
int main() {
int a[5], i, flg, j;
while (1) {
int g = 0, t = 0, p = 0;
int mflg, kflg;
int aaflg;
flg = 0;
for (i = 0; i < 5; i++) {
cin >> a[i];
if (a[i] == 0)
break;
if (a[i] == 1)
g = 1;
else if (a[i] == 2)
t = 1;
else
p = 1;
}
if (a[i] == 0)
break;
aaflg = 0;
for (i = 1; i < 5; i++) {
if (a[0] != a[i])
aaflg = 1;
}
if (g == 1 && t == 1 && p == 1 || aaflg == 0) {
for (i = 0; i < 5; i++)
cout << "3" << endl;
} else {
for (i = 0; i < 5; i++) {
mflg = 0;
kflg = 0;
for (j = 0; j < 5; j++) {
if (a[i] == a[j])
;
else if (a[i] == 1 && a[j] == 3 || a[i] == 2 && a[j] == 1 ||
a[i] == 3 && a[j] == 2)
mflg = 1;
else
kflg = 1;
}
if (mflg == 1)
cout << "2" << endl;
else
cout << "1" << endl;
}
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a[5], i, flg, j;
while (1) {
int g = 0, t = 0, p = 0;
int mflg, kflg;
int aaflg;
flg = 0;
for (i = 0; i < 5; i++) {
cin >> a[i];
if (a[i] == 0)
break;
if (a[i] == 1)
g = 1;
else if (a[i] == 2)
t = 1;
else
p = 1;
}
if (a[0] == 0)
break;
aaflg = 0;
for (i = 1; i < 5; i++) {
if (a[0] != a[i])
aaflg = 1;
}
if (g == 1 && t == 1 && p == 1 || aaflg == 0) {
for (i = 0; i < 5; i++)
cout << "3" << endl;
} else {
for (i = 0; i < 5; i++) {
mflg = 0;
kflg = 0;
for (j = 0; j < 5; j++) {
if (a[i] == a[j])
;
else if (a[i] == 1 && a[j] == 3 || a[i] == 2 && a[j] == 1 ||
a[i] == 3 && a[j] == 2)
mflg = 1;
else
kflg = 1;
}
if (mflg == 1)
cout << "2" << endl;
else
cout << "1" << endl;
}
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13]]
| 1
| 341
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
int i, j;
vi hand(5);
while (1) {
vi n(3, 0);
cin >> hand[0];
if (hand[0] == 0)
break;
hand[0]--;
n[hand[0]]++;
rep(i, 4) {
cin >> hand[1 + i];
hand[1 + i]--;
n[hand[1 + i]]++;
}
if (n[0] && n[1] && n[2])
rep(i, 5) cout << "3" << endl;
else if (n[0] == 5 || n[1] == 5 || n[2] == 5)
rep(i, 5) cout << "3" << endl;
else if (n[0] && n[1]) // gu choki
rep(i, 5) if (hand[i]) cout << "2" << endl;
else
cout << "1" << endl;
else if (n[0] && n[1]) // gu pa
rep(i, 5) if (hand[i]) cout
<< "1" << endl;
else cout << "2" << endl;
else rep(i, 5) if (hand[i] == 1) cout << "1" << endl;
else cout << "2" << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
int i, j;
vi hand(5);
while (1) {
vi n(3, 0);
cin >> hand[0];
if (hand[0] == 0)
break;
hand[0]--;
n[hand[0]]++;
rep(i, 4) {
cin >> hand[1 + i];
hand[1 + i]--;
n[hand[1 + i]]++;
}
if (n[0] && n[1] && n[2])
rep(i, 5) cout << "3" << endl;
else if (n[0] == 5 || n[1] == 5 || n[2] == 5)
rep(i, 5) cout << "3" << endl;
else if (n[0] && n[1]) // gu choki
rep(i, 5) if (hand[i]) cout << "2" << endl;
else
cout << "1" << endl;
else if (n[0] && n[2]) // gu pa
rep(i, 5) if (hand[i]) cout
<< "1" << endl;
else cout << "2" << endl;
else rep(i, 5) if (hand[i] == 1) cout << "1" << endl;
else cout << "2" << endl;
}
}
|
[["-", 15, 339, 51, 16, 12, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 13]]
| 1
| 384
| 2
|
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int arr[5];
int arr_2[5];
int main() {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
else
arr[0] = n;
for (int i = 1; i < 5; i++)
cin >> arr[i];
int min = 4;
int max = 0;
for (int i = 0; i < 5; i++)
arr_2[i] = arr[i];
sort(arr_2, arr_2 + 5);
int count = 0;
for (int i = 0; i < 4; i++) {
if ((arr_2[i + 1] - arr_2[i]) == 1)
count++;
}
if (count == 2) {
int count2 = 5;
while (count2--)
cout << "3" << endl;
}
for (int i = 0; i < 5; i++) {
if (arr[i] > max)
max = arr[i];
if (arr[i] < min)
min = arr[i];
}
if (min == 1 && max == 2) {
for (int i = 0; i < 5; i++) {
if (arr[i] == 1)
cout << "1" << endl;
else
cout << "2" << endl;
}
} else if (min == 2 && max == 3) {
for (int i = 0; i < 5; i++) {
if (arr[i] == 2)
cout << "1" << endl;
else
cout << "2" << endl;
}
} else if (min == 1 && max == 3) {
for (int i = 0; i < 5; i++) {
if (arr[i] == 1)
cout << "2" << endl;
else
cout << "1" << endl;
}
} else if (min == max) {
int count3 = 5;
while (count3--)
cout << "3" << endl;
}
}
// while(1);
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int arr[5];
int arr_2[5];
int main() {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
else
arr[0] = n;
for (int i = 1; i < 5; i++)
cin >> arr[i];
int min = 4;
int max = 0;
for (int i = 0; i < 5; i++)
arr_2[i] = arr[i];
sort(arr_2, arr_2 + 5);
int count = 0;
for (int i = 0; i < 4; i++) {
if ((arr_2[i + 1] - arr_2[i]) == 1)
count++;
}
if (count == 2) {
int count2 = 5;
while (count2--)
cout << "3" << endl;
} else {
for (int i = 0; i < 5; i++) {
if (arr[i] > max)
max = arr[i];
if (arr[i] < min)
min = arr[i];
}
if (min == 1 && max == 2) {
for (int i = 0; i < 5; i++) {
if (arr[i] == 1)
cout << "1" << endl;
else
cout << "2" << endl;
}
} else if (min == 2 && max == 3) {
for (int i = 0; i < 5; i++) {
if (arr[i] == 2)
cout << "1" << endl;
else
cout << "2" << endl;
}
} else if (min == 1 && max == 3) {
for (int i = 0; i < 5; i++) {
if (arr[i] == 1)
cout << "2" << endl;
else
cout << "1" << endl;
}
} else if (min == max) {
int count3 = 5;
while (count3--)
cout << "3" << endl;
}
}
}
// while(1);
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46]]
| 1
| 454
| 3
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to, cost; };
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
vector<int> h(5);
while (cin >> h[0] && h[0]) {
REP(i, 1, 5) cin >> h[i];
set<int> s;
rep(i, 5) s.insert(h[i]);
if (!s.count(1) && s.count(2) && s.count(3)) {
rep(i, 5) { cout << (h[i] == 2 ? 1 : 2) << endl; }
} else if (!s.count(2) && s.count(1) && s.count(3)) {
rep(i, 5) { cout << (h[i] == 3 ? 1 : 2) << endl; }
} else if (!s.count(3) && s.count(1) && s.count(2)) {
rep(i, 5) { cout << (h[i] == 1 ? 1 : 2) << endl; }
} else {
cout << 3 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to, cost; };
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
vector<int> h(5);
while (cin >> h[0] && h[0]) {
REP(i, 1, 5) cin >> h[i];
set<int> s;
rep(i, 5) s.insert(h[i]);
if (!s.count(1) && s.count(2) && s.count(3)) {
rep(i, 5) { cout << (h[i] == 2 ? 1 : 2) << endl; }
} else if (!s.count(2) && s.count(1) && s.count(3)) {
rep(i, 5) { cout << (h[i] == 3 ? 1 : 2) << endl; }
} else if (!s.count(3) && s.count(1) && s.count(2)) {
rep(i, 5) { cout << (h[i] == 1 ? 1 : 2) << endl; }
} else {
rep(i, 5) cout << 3 << endl;
}
}
return 0;
}
|
[["+", 0, 1, 0, 16, 31, 16, 31, 2, 63, 22], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 22], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 21], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 25]]
| 1
| 367
| 6
|
#include <iostream>
using namespace std;
int main() {
int h[5], cnt[3];
while (cin >> h[0], h[0] != 0) {
for (int i = 1; i < 5; i++)
cin >> h[i];
cnt[1] = 0;
cnt[2] = 0;
cnt[3] = 0;
for (int i = 0; i < 5; i++)
cnt[h[i]]++;
for (int i = 0; i < 5; i++) {
if (cnt[1] == 5 || cnt[2] == 5 || cnt[3] == 5)
cout << 3 << endl;
else if (cnt[1] != 0 && cnt[2] != 0 && cnt[3] != 0)
cout << 3 << endl;
else if (cnt[1] == 0) {
if (h[i] == 2)
cout << 1 << endl;
if (h[i] == 3)
cout << 2 << endl;
} else if (cnt[2] == 0) {
if (h[i] == 3)
cout << 1 << endl;
if (h[i] == 1)
cout << 2 << endl;
} else if (cnt[3] == 0) {
if (h[i] == 1)
cout << 1 << endl;
if (h[i] == 2)
cout << 2 << endl;
}
}
}
return (0);
}
|
#include <iostream>
using namespace std;
int main() {
int h[5], cnt[4];
while (cin >> h[0], h[0] != 0) {
for (int i = 1; i < 5; i++)
cin >> h[i];
cnt[1] = 0;
cnt[2] = 0;
cnt[3] = 0;
for (int i = 0; i < 5; i++)
cnt[h[i]]++;
for (int i = 0; i < 5; i++) {
if (cnt[1] == 5 || cnt[2] == 5 || cnt[3] == 5)
cout << 3 << endl;
else if (cnt[1] != 0 && cnt[2] != 0 && cnt[3] != 0)
cout << 3 << endl;
else if (cnt[1] == 0) {
if (h[i] == 2)
cout << 1 << endl;
if (h[i] == 3)
cout << 2 << endl;
} else if (cnt[2] == 0) {
if (h[i] == 3)
cout << 1 << endl;
if (h[i] == 1)
cout << 2 << endl;
} else if (cnt[3] == 0) {
if (h[i] == 1)
cout << 1 << endl;
if (h[i] == 2)
cout << 2 << endl;
}
}
}
return (0);
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
| 1
| 312
| 2
|
#include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
double dat[100][100];
int dp[1000001]; //動的計画法
int prime[1000001];
int main() {
int hand[5];
int gcnt, ccnt, pcnt;
int ans[5];
while (cin >> hand[0], hand[0]) {
gcnt = ccnt = pcnt = 0;
for (int i = 1; i < 5; i++) {
cin >> hand[i];
}
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
gcnt++;
else if (hand[i] == 2)
ccnt++;
else
pcnt++;
}
if (gcnt > 0 && ccnt > 0 && pcnt > 0) {
for (int i = 0; i < 5; i++) {
ans[i] = 3;
cout << ans[i] << endl;
}
continue;
} else if (gcnt == 5 || ccnt == 5 || pcnt == 5) {
for (int i = 0; i < 5; i++) {
ans[i] = 3;
cout << ans[i] << endl;
}
continue;
} else {
if (pcnt == 0) {
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
ans[i] = 1;
else
ans[i] = 2;
}
} else if (gcnt == 0) {
for (int i = 0; i < 5; i++) {
if (hand[i] == 2)
ans[i] = 1;
else
hand[i] = 2;
}
} else {
for (int i = 0; i < 5; i++) {
if (hand[i] == 3)
ans[i] = 1;
else
hand[i] = 2;
}
}
for (int i = 0; i < 5; i++) {
cout << ans[i] << endl;
}
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
double dat[100][100];
int dp[1000001]; //動的計画法
int prime[1000001];
int main() {
int hand[5];
int gcnt, ccnt, pcnt;
int ans[5];
while (cin >> hand[0], hand[0]) {
gcnt = ccnt = pcnt = 0;
for (int i = 1; i < 5; i++) {
cin >> hand[i];
}
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
gcnt++;
else if (hand[i] == 2)
ccnt++;
else
pcnt++;
}
if (gcnt > 0 && ccnt > 0 && pcnt > 0) {
for (int i = 0; i < 5; i++) {
ans[i] = 3;
cout << ans[i] << endl;
}
continue;
} else if (gcnt == 5 || ccnt == 5 || pcnt == 5) {
for (int i = 0; i < 5; i++) {
ans[i] = 3;
cout << ans[i] << endl;
}
continue;
} else {
if (pcnt == 0) {
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
ans[i] = 1;
else
ans[i] = 2;
}
} else if (gcnt == 0) {
for (int i = 0; i < 5; i++) {
if (hand[i] == 2)
ans[i] = 1;
else
ans[i] = 2;
}
} else {
for (int i = 0; i < 5; i++) {
if (hand[i] == 3)
ans[i] = 1;
else
ans[i] = 2;
}
}
for (int i = 0; i < 5; i++) {
cout << ans[i] << endl;
}
}
}
return 0;
}
|
[["-", 75, 76, 0, 1, 0, 11, 31, 69, 28, 22], ["+", 75, 76, 0, 1, 0, 11, 31, 69, 28, 22]]
| 1
| 442
| 4
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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() {
int A[5], B[5];
while (cin >> A[0] && A[0]) {
int state = 0;
for (int i = 1; i < 5; ++i) {
cin >> A[i];
state |= 1 << A[i];
}
if (state == (1 << 1 | 1 << 2)) {
for (int i = 0; i < 5; ++i) {
B[i] = A[i] == 1 ? 1 : 2;
}
} else if (state == (1 << 2 | 1 << 3)) {
for (int i = 0; i < 5; ++i) {
B[i] = A[i] == 2 ? 1 : 2;
}
} else if (state == (1 << 3 | 1 << 1)) {
for (int i = 0; i < 5; ++i) {
B[i] = A[i] == 3 ? 1 : 2;
}
} else {
for (int i = 0; i < 5; ++i) {
B[i] = 3;
}
}
for (int i = 0; i < 5; ++i) {
cout << B[i] << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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() {
int A[5], B[5];
while (cin >> A[0] && A[0]) {
int state = 1 << A[0];
for (int i = 1; i < 5; ++i) {
cin >> A[i];
state |= 1 << A[i];
}
if (state == (1 << 1 | 1 << 2)) {
for (int i = 0; i < 5; ++i) {
B[i] = A[i] == 1 ? 1 : 2;
}
} else if (state == (1 << 2 | 1 << 3)) {
for (int i = 0; i < 5; ++i) {
B[i] = A[i] == 2 ? 1 : 2;
}
} else if (state == (1 << 3 | 1 << 1)) {
for (int i = 0; i < 5; ++i) {
B[i] = A[i] == 3 ? 1 : 2;
}
} else {
for (int i = 0; i < 5; ++i) {
B[i] = 3;
}
}
for (int i = 0; i < 5; ++i) {
cout << B[i] << endl;
}
}
return 0;
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 31, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 151], ["+", 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, 73]]
| 1
| 306
| 5
|
#include <iostream>
#define G 1
#define C 2
#define P 3
#define N 5
using namespace std;
int a[N];
void calc() {
int g, c, p;
g = 0;
c = 0;
p = 0;
for (int i = 0; i < N; i++) {
if (a[i] == G)
g = 1;
if (a[i] == C)
c = 1;
if (a[i] == P)
p = 1;
}
for (int i = 0; i < N; i++) {
if (((g == c) && (c == p)) || (g && c && p)) {
cout << 3 << endl;
} else {
if (g == 1) {
if (a[i] == G) {
if (c == 1)
cout << 1 << endl;
else if (p == 1)
cout << 2 << endl;
else
cout << 3 << endl;
}
if (a[i] == C) {
cout << 2 << endl;
}
if (a[i] == P) {
cout << 1 << endl;
}
} else if (c == 1) {
if (a[i] == G) {
cout << 2 << endl;
}
if (a[i] == C) {
if (g == 1)
cout << 2 << endl;
else if (p == 1)
cout << 1 << endl;
else
cout << 3 << endl;
}
if (a[i] == P) {
cout << 1 << endl;
}
} else if (p == 1) {
if (a[i] == G) {
cout << 1 << endl;
}
if (a[i] == C) {
cout << 2 << endl;
}
if (a[i] == P) {
if (g == 1)
cout << 1 << endl;
else if (c == 1)
cout << 2 << endl;
else
cout << 3 << endl;
}
}
}
}
}
int main() {
while (true) {
bool skip = false;
for (int i = 0; i < N; i++) {
cin >> a[i];
if (a[i] == 0) {
return 0;
}
}
if (a == 0)
break;
calc();
}
}
|
#include <iostream>
#define G 1
#define C 2
#define P 3
#define N 5
using namespace std;
int a[N];
void calc() {
int g, c, p;
g = 0;
c = 0;
p = 0;
for (int i = 0; i < N; i++) {
if (a[i] == G)
g = 1;
if (a[i] == C)
c = 1;
if (a[i] == P)
p = 1;
}
for (int i = 0; i < N; i++) {
if (((g == c) && (c == p)) || (g && c && p)) {
cout << 3 << endl;
} else {
if (g == 1) {
if (a[i] == G) {
if (c == 1)
cout << 1 << endl;
else if (p == 1)
cout << 2 << endl;
else
cout << 3 << endl;
}
if (a[i] == C) {
cout << 2 << endl;
}
if (a[i] == P) {
cout << 1 << endl;
}
} else if (c == 1) {
if (a[i] == G) {
cout << 1 << endl;
}
if (a[i] == C) {
if (g == 1)
cout << 2 << endl;
else if (p == 1)
cout << 1 << endl;
else
cout << 3 << endl;
}
if (a[i] == P) {
cout << 2 << endl;
}
} else if (p == 1) {
if (a[i] == G) {
cout << 1 << endl;
}
if (a[i] == C) {
cout << 2 << endl;
}
if (a[i] == P) {
if (g == 1)
cout << 1 << endl;
else if (c == 1)
cout << 2 << endl;
else
cout << 3 << endl;
}
}
}
}
}
int main() {
while (true) {
bool skip = false;
for (int i = 0; i < N; i++) {
cin >> a[i];
if (a[i] == 0) {
return 0;
}
}
if (a == 0)
break;
calc();
}
}
|
[["-", 64, 9, 0, 1, 0, 16, 31, 16, 12, 13], ["+", 64, 9, 0, 1, 0, 16, 31, 16, 12, 13]]
| 1
| 478
| 4
|
#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 (;;) {
vector<int> a(5);
vector<int> b(4);
for (int i = 0; i < 5; ++i) {
cin >> a[i];
if (a[i] == 0)
return 0;
++b[a[i]];
}
if (b[1] == 5 || b[2] == 5 || b[3] == 5 ||
(b[1] > 0 && b[2] > 0 && b[3] > 0)) {
a.assign(5, 3);
} else {
if (b[1] = 0) {
replace(a.begin(), a.end(), 2, 1);
replace(a.begin(), a.end(), 3, 2);
} else if (b[2] == 0) {
replace(a.begin(), a.end(), 1, 2);
replace(a.begin(), a.end(), 3, 1);
}
}
for (int i = 0; i < 5; ++i)
cout << a[i] << 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 (;;) {
vector<int> a(5);
vector<int> b(4);
for (int i = 0; i < 5; ++i) {
cin >> a[i];
if (a[i] == 0)
return 0;
++b[a[i]];
}
if (b[1] == 5 || b[2] == 5 || b[3] == 5 ||
(b[1] > 0 && b[2] > 0 && b[3] > 0)) {
a.assign(5, 3);
} else {
if (b[1] == 0) {
replace(a.begin(), a.end(), 2, 1);
replace(a.begin(), a.end(), 3, 2);
} else if (b[2] == 0) {
replace(a.begin(), a.end(), 1, 2);
replace(a.begin(), a.end(), 3, 1);
}
}
for (int i = 0; i < 5; ++i)
cout << a[i] << endl;
}
}
|
[["-", 0, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 293
| 2
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
int main() {
for (vi a(5); cin >> a[0], a[0];) {
repi(i, 1, 5) cin >> a[i];
int flg = 0;
rep(i, 5) flg |= 1 << a[i] - 1;
if (flg == 7 || __builtin_popcount(flg) == 1)
rep(i, 5) cout << 3 << endl;
else if (flg == 3)
rep(i, 5) cout << (a[i] == 1 ? 1 : 2) << endl;
else if (flg == 5)
rep(i, 5) cout << (a[i] == 4 ? 1 : 2) << endl;
else if (flg == 7)
rep(i, 5) cout << (a[i] == 2 ? 1 : 2) << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
int main() {
for (vi a(5); cin >> a[0], a[0];) {
repi(i, 1, 5) cin >> a[i];
int flg = 0;
rep(i, 5) flg |= 1 << (a[i] - 1);
if (flg == 7 || __builtin_popcount(flg) == 1)
rep(i, 5) cout << 3 << endl;
else if (flg == 3)
rep(i, 5) cout << (a[i] == 1 ? 1 : 2) << endl;
else if (flg == 5)
rep(i, 5) cout << (a[i] == 3 ? 1 : 2) << endl;
else if (flg == 6)
rep(i, 5) cout << (a[i] == 2 ? 1 : 2) << endl;
}
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 31, 16, 12, 23, 0, 41, 15, 16, 12, 13], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 350
| 6
|
#include <cstdio>
#include <vector>
using namespace std;
vector<int> hand;
int main() {
int self;
while (1) {
hand.clear();
scanf("%d", &self);
if (self == 0) {
break;
}
hand.push_back(self);
for (int i = 1; i < 5; i++) {
scanf("%d", &self);
hand.push_back(self);
}
bool flag[4];
flag[0] = false;
flag[1] = false;
flag[2] = false;
flag[3] = false;
vector<int>::iterator it;
for (it = hand.begin(); it < hand.end(); it++) {
flag[*it] = true;
}
int re[4];
if ((flag[1] && flag[2] && flag[3]) || (flag[1] && !flag[2] && !flag[3]) ||
(!flag[1] && flag[2] && !flag[3]) ||
(!flag[1] && !flag[2] && flag[3])) {
re[1] = 3; // O[
re[2] = 3; // `L
re[3] = 3; // p[
}
if (flag[1] && flag[2] && !flag[3]) {
re[1] = 1; // O[
re[2] = 2; // `L
re[3] = 0; // p[
}
if (flag[1] && !flag[2] && flag[3]) {
re[1] = 2; // O[
re[2] = 0; // `L
re[3] = 1; // p[
}
if (!flag[1] && flag[2] && flag[3]) {
re[1] = 0; // O[
re[2] = 1; // `L
re[3] = 0; // p[
}
for (it = hand.begin(); it < hand.end(); it++) {
printf("%d\n", re[*it]);
}
}
return 0;
}
|
#include <cstdio>
#include <vector>
using namespace std;
vector<int> hand;
int main() {
int self;
while (1) {
hand.clear();
scanf("%d", &self);
if (self == 0) {
break;
}
hand.push_back(self);
for (int i = 1; i < 5; i++) {
scanf("%d", &self);
hand.push_back(self);
}
bool flag[4];
flag[0] = false;
flag[1] = false;
flag[2] = false;
flag[3] = false;
vector<int>::iterator it;
for (it = hand.begin(); it < hand.end(); it++) {
flag[*it] = true;
}
int re[4];
if ((flag[1] && flag[2] && flag[3]) || (flag[1] && !flag[2] && !flag[3]) ||
(!flag[1] && flag[2] && !flag[3]) ||
(!flag[1] && !flag[2] && flag[3])) {
re[1] = 3; // O[
re[2] = 3; // `L
re[3] = 3; // p[
}
if (flag[1] && flag[2] && !flag[3]) {
re[1] = 1; // O[
re[2] = 2; // `L
re[3] = 0; // p[
}
if (flag[1] && !flag[2] && flag[3]) {
re[1] = 2; // O[
re[2] = 0; // `L
re[3] = 1; // p[
}
if (!flag[1] && flag[2] && flag[3]) {
re[1] = 0; // O[
re[2] = 1; // `L
re[3] = 2; // p[
}
for (it = hand.begin(); it < hand.end(); it++) {
printf("%d\n", re[*it]);
}
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 448
| 2
|
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
bool flag[4];
int hand[5];
int ans[5];
void solve() {
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
flag[1] = true; //O[
if (hand[i] == 2)
flag[2] = true; //`L
if (hand[i] == 3)
flag[3] = true; //p[
}
}
int main() {
while (cin >> hand[0], hand[0]) {
for (int i = 1; i < 5; i++)
cin >> hand[i];
for (int i = 1; i < 4; i++)
flag[i] = false;
solve();
for (int i = 0; i < 5; i++) {
if (flag[1] == true && flag[2] == true && flag[3] == false) {
if (hand[i] == 1)
ans[i] = 1;
if (hand[i] == 2)
ans[i] = 2;
} else if (flag[1] == false && flag[2] == true && flag[3] == true) {
if (hand[i] == 2)
ans[i] = 1;
if (hand[i] == 3)
ans[i] = 2;
} else if (flag[1] == true && flag[2] == false && flag[3] == true) {
if (flag[i] == 3)
ans[i] = 1;
if (flag[i] == 1)
ans[i] = 2;
} else
ans[i] = 3;
}
for (int i = 0; i < 5; i++) {
cout << ans[i] << endl;
}
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
bool flag[4];
int hand[5];
int ans[5];
void solve() {
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
flag[1] = true; //O[
if (hand[i] == 2)
flag[2] = true; //`L
if (hand[i] == 3)
flag[3] = true; //p[
}
}
int main() {
while (cin >> hand[0], hand[0]) {
for (int i = 1; i < 5; i++)
cin >> hand[i];
for (int i = 1; i < 4; i++)
flag[i] = false;
solve();
for (int i = 0; i < 5; i++) {
if (flag[1] == true && flag[2] == true && flag[3] == false) {
if (hand[i] == 1)
ans[i] = 1;
if (hand[i] == 2)
ans[i] = 2;
} else if (flag[1] == false && flag[2] == true && flag[3] == true) {
if (hand[i] == 2)
ans[i] = 1;
if (hand[i] == 3)
ans[i] = 2;
} else if (flag[1] == true && flag[2] == false && flag[3] == true) {
if (hand[i] == 3)
ans[i] = 1;
if (hand[i] == 1)
ans[i] = 2;
} else
ans[i] = 3;
}
for (int i = 0; i < 5; i++) {
cout << ans[i] << endl;
}
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22]]
| 1
| 394
| 4
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, hand[3] = {0};
cin >> n;
if (n == 0)
break;
hand[n - 1] = 1;
for (int i = 1; i < 5; i++) {
int h;
cin >> h;
hand[h - 1] = 1 << i;
}
for (int i = 0; i < 5; i++) {
int h = 0;
while (!(hand[h] & 1 << i))
h++;
int ans = 0;
if (hand[(h + 1) % 3])
ans += 1;
if (hand[(3 + h - 1) % 3])
ans += 2;
if (ans == 0)
ans = 3;
cout << ans << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, hand[3] = {0};
cin >> n;
if (n == 0)
break;
hand[n - 1] = 1;
for (int i = 1; i < 5; i++) {
int h;
cin >> h;
hand[h - 1] |= 1 << i;
}
for (int i = 0; i < 5; i++) {
int h = 0;
while (!(hand[h] & 1 << i))
h++;
int ans = 0;
if (hand[(h + 1) % 3])
ans += 1;
if (hand[(3 + h - 1) % 3])
ans += 2;
if (ans == 0)
ans = 3;
cout << ans << endl;
}
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 160]]
| 1
| 183
| 2
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int n[5];
int c1 = 0, c2 = 0, c3 = 0;
cin >> n[0];
if (n[0] == 0)
break;
for (int i = 1; i < 5; i++)
cin >> n[i];
for (int i = 0; i < 4; i++) {
if (n[i] != n[i + 1])
break;
if (i == 3) {
for (int i = 0; i < 5; i++)
cout << '3' << endl;
break;
}
}
for (int i = 0; i < 5; i++) {
if (n[i] == 1)
c1++;
else if (n[i] == 2)
c2++;
else if (n[i] == 3)
c3++;
}
if (c1 != 0 && c2 != 0 && c3 != 0)
for (int i = 0; i < 5; i++)
cout << '3' << endl;
else {
if (c1 > 0 && c2 > 0 && c3 == 0) {
for (int i = 0; i < 5; i++) {
if (n[i] == 1)
cout << '1' << endl;
else
cout << '2' << endl;
}
} else if (c1 > 0 && c2 == 0 && c3 > 0) {
for (int i = 0; i < 5; i++) {
if (n[i] == 1)
cout << '2' << endl;
else
cout << '1' << endl;
}
} else if (c1 == 0 && c2 > 0 && c3 > 0) {
for (int i = 0; i < 5; i++) {
if (n[i] == 2)
cout << '2' << endl;
else
cout << '1' << endl;
}
}
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int n[5];
int c1 = 0, c2 = 0, c3 = 0;
cin >> n[0];
if (n[0] == 0)
break;
for (int i = 1; i < 5; i++)
cin >> n[i];
for (int i = 0; i < 4; i++) {
if (n[i] != n[i + 1])
break;
if (i == 3) {
for (int i = 0; i < 5; i++)
cout << '3' << endl;
break;
}
}
for (int i = 0; i < 5; i++) {
if (n[i] == 1)
c1++;
else if (n[i] == 2)
c2++;
else if (n[i] == 3)
c3++;
}
if (c1 != 0 && c2 != 0 && c3 != 0)
for (int i = 0; i < 5; i++)
cout << '3' << endl;
else {
if (c1 > 0 && c2 > 0 && c3 == 0) {
for (int i = 0; i < 5; i++) {
if (n[i] == 1)
cout << '1' << endl;
else
cout << '2' << endl;
}
} else if (c1 > 0 && c2 == 0 && c3 > 0) {
for (int i = 0; i < 5; i++) {
if (n[i] == 1)
cout << '2' << endl;
else
cout << '1' << endl;
}
} else if (c1 == 0 && c2 > 0 && c3 > 0) {
for (int i = 0; i < 5; i++) {
if (n[i] == 3)
cout << '2' << endl;
else
cout << '1' << endl;
}
}
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 412
| 2
|
#include <iostream>
using namespace std;
int main() {
int st[5], res[5];
int g[3], n = 0;
int val = 0;
while (1) {
for (int i = 0; i < 3; i++)
g[i] = 0;
n = 0;
val = 0; // val -> winner
// Input
for (int i = 0; i < 5; i++) {
cin >> st[i];
if (st[i] == 0)
break;
if (!g[st[i] - 1]) {
n++;
g[st[i] - 1] = 1;
if (val == 0)
val = st[i];
if (val - 1 == st[i])
val = st[i];
}
}
if (st[0] == 0)
break;
if (n == 2) {
for (int i = 0; i < 5; i++)
if (val == st[i])
res[i] = 1;
else
res[i] = 2;
} else {
for (int i = 0; i < 5; i++)
res[i] = 3;
}
// Output
for (int i = 0; i < 5; i++)
cout << res[i] << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int st[5], res[5];
int g[3], n = 0;
int val = 0;
while (1) {
for (int i = 0; i < 3; i++)
g[i] = 0;
n = 0;
val = 0; // val -> winner
// Input
for (int i = 0; i < 5; i++) {
cin >> st[i];
if (st[i] == 0)
break;
if (!g[st[i] - 1]) {
n++;
g[st[i] - 1] = 1;
if (val == 0)
val = st[i];
if (val - 1 == (st[i] % 3))
val = st[i];
}
}
if (st[0] == 0)
break;
if (n == 2) {
for (int i = 0; i < 5; i++)
if (val == st[i])
res[i] = 1;
else
res[i] = 2;
} else {
for (int i = 0; i < 5; i++)
res[i] = 3;
}
// Output
for (int i = 0; i < 5; i++)
cout << res[i] << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 109], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 25]]
| 1
| 278
| 4
|
#include <iostream>
using namespace std;
int array[5];
int ret[4];
void p(int a, int b, int c) {
for (int i = 0; i < 5; i++) {
if (array[i] == a)
cout << 1 << endl;
else if (array[i] == b)
cout << 2 << endl;
else
cout << 3 << endl;
}
}
int main() {
while (cin >> array[0], array[0]) {
fill(ret, ret + 4, 0);
ret[array[0] - 1] = 1;
for (int i = 1; i < 5; i++) {
cin >> array[i];
ret[array[i]] = 1;
}
if (ret[1] != 0 && ret[2] != 0 && ret[3] == 0) {
p(1, 2, 3);
} else if (ret[2] != 0 && ret[3] != 0 && ret[1] == 0) {
p(2, 3, 1);
} else if (ret[1] != 0 && ret[3] != 0 && ret[2] == 0) {
p(3, 1, 2);
} else
p(4, 4, 4);
}
}
|
#include <iostream>
using namespace std;
int array[5];
int ret[4];
void p(int a, int b, int c) {
for (int i = 0; i < 5; i++) {
if (array[i] == a)
cout << 1 << endl;
else if (array[i] == b)
cout << 2 << endl;
else
cout << 3 << endl;
}
}
int main() {
while (cin >> array[0], array[0]) {
fill(ret, ret + 4, 0);
ret[array[0]] = 1;
for (int i = 1; i < 5; i++) {
cin >> array[i];
ret[array[i]] = 1;
}
if (ret[1] != 0 && ret[2] != 0 && ret[3] == 0) {
p(1, 2, 3);
} else if (ret[2] != 0 && ret[3] != 0 && ret[1] == 0) {
p(2, 3, 1);
} else if (ret[1] != 0 && ret[3] != 0 && ret[2] == 0) {
p(3, 1, 2);
} else
p(4, 4, 4);
}
}
|
[["-", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 31, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 278
| 2
|
#include <iostream>
using namespace std;
int main(void) {
int j[5];
bool R, S, P;
while (cin >> j[0], j[0]) {
for (int i = 1; i < 5; i++) {
cin >> j[i];
}
R = S = P = false;
for (int i = 0; i < 5; i++) {
if (j[i] == 1)
R = true;
if (j[i] == 2)
S = true;
if (j[i] == 3)
P = true;
}
if (R && S && P)
for (int i = 0; i < 5; i++)
cout << "3" << endl;
else if (R && S && !P) // パーなし
for (int i = 0; i < 5; i++) {
switch (j[i]) {
case 1:
cout << "1" << endl;
break;
case 2:
cout << "2" << endl;
break;
}
}
else if (R && !S && P) // チョキなし
for (int i = 0; i < 5; i++) {
switch (j[i]) {
case 1:
cout << "2" << endl;
break;
case 2:
cout << "1" << endl;
break;
}
}
else if (!R && S && P) // グーなし
for (int i = 0; i < 5; i++) {
switch (j[i]) {
case 2:
cout << "1" << endl;
break;
case 3:
cout << "2" << endl;
break;
}
}
else if ((!R && !S && P) || (!R && S && !P) || (R && !S && !P)) {
for (int i = 0; i < 5; i++)
cout << "3" << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
int j[5];
bool R, S, P;
while (cin >> j[0], j[0]) {
for (int i = 1; i < 5; i++) {
cin >> j[i];
}
R = S = P = false;
for (int i = 0; i < 5; i++) {
if (j[i] == 1)
R = true;
if (j[i] == 2)
S = true;
if (j[i] == 3)
P = true;
}
if (R && S && P)
for (int i = 0; i < 5; i++)
cout << "3" << endl;
else if (R && S && !P) // パーなし
for (int i = 0; i < 5; i++) {
switch (j[i]) {
case 1:
cout << "1" << endl;
break;
case 2:
cout << "2" << endl;
break;
}
}
else if (R && !S && P) // チョキなし
for (int i = 0; i < 5; i++) {
switch (j[i]) {
case 1:
cout << "2" << endl;
break;
case 3:
cout << "1" << endl;
break;
}
}
else if (!R && S && P) // グーなし
for (int i = 0; i < 5; i++) {
switch (j[i]) {
case 2:
cout << "1" << endl;
break;
case 3:
cout << "2" << endl;
break;
}
}
else if ((!R && !S && P) || (!R && S && !P) || (R && !S && !P)) {
for (int i = 0; i < 5; i++)
cout << "3" << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 99, 8, 9, 0, 100, 51, 13], ["+", 8, 9, 0, 99, 8, 9, 0, 100, 51, 13]]
| 1
| 404
| 2
|
#include <stdio.h>
int main(void) {
int t[5] = {0}, i, R, P, S;
while (0 == 0) {
R = P = S = 0;
scanf("%d", &t[0]);
if (t[0] == 0)
break;
else if (t[0] == 1)
R++;
else if (t[0] == 2)
S++;
else
P++;
for (i = 1; i < 5; i++) {
scanf("%d", &t[i]);
if (t[i] == 1)
R++;
else if (t[i] == 2)
S++;
else
P++;
}
if (R == 0) {
if (P != 0 && S != 0)
for (i = 0; i < 5; i++) {
if (t[i] == 2)
t[i] = 1;
else
t[i] = 2;
}
} else if (S == 0) {
if (P != 0 && R != 0)
for (i = 0; i < 5; i++) {
if (t[i] == 3)
t[i] = 1;
else
t[i] = 2;
}
} else if (P == 0) {
if (S != 0 && R != 0)
for (i = 0; i < 5; i++) {
if (t[i] == 1)
t[i] = 1;
else
t[i] = 2;
}
}
else if (R == 5 || S == 5 || P == 5 || (R != 0 && S != 0 && P != 0))
for (i = 0; i < 5; i++)
t[i] = 3;
for (i = 0; i < 5; i++)
printf("%d\n", t[i]);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int t[5] = {0}, i, R, P, S;
while (0 == 0) {
R = P = S = 0;
scanf("%d", &t[0]);
if (t[0] == 0)
break;
else if (t[0] == 1)
R++;
else if (t[0] == 2)
S++;
else
P++;
for (i = 1; i < 5; i++) {
scanf("%d", &t[i]);
if (t[i] == 1)
R++;
else if (t[i] == 2)
S++;
else
P++;
}
if (R == 0) {
if (P != 0 && S != 0)
for (i = 0; i < 5; i++) {
if (t[i] == 2)
t[i] = 1;
else
t[i] = 2;
}
}
if (S == 0) {
if (P != 0 && R != 0)
for (i = 0; i < 5; i++) {
if (t[i] == 3)
t[i] = 1;
else
t[i] = 2;
}
}
if (P == 0) {
if (S != 0 && R != 0)
for (i = 0; i < 5; i++) {
if (t[i] == 1)
t[i] = 1;
else
t[i] = 2;
}
}
if (R == 5 || S == 5 || P == 5 || (R != 0 && S != 0 && P != 0))
for (i = 0; i < 5; i++)
t[i] = 3;
for (i = 0; i < 5; i++)
printf("%d\n", t[i]);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95], ["-", 0, 57, 75, 76, 0, 57, 75, 76, 0, 95]]
| 1
| 405
| 3
|
puts readlines[0..-2].map(&:to_i).each_slice(5).map{|a|b=a.uniq.sort;b==[1,2]?a:b==[1,3]?a.map{|i|i==3?1:2}:a==[2,3]?a.map{|i|i==2?1:2}:[3]*5}
|
puts readlines[0..-2].map(&:to_i).each_slice(5).map{|a|b=a.uniq.sort;b==[1,2]?a:b==[1,3]?a.map{|i|i==3?1:2}:b==[2,3]?a.map{|i|i==2?1:2}:[3]*5}
|
[["-", 0, 754, 75, 754, 75, 754, 15, 738, 31, 22], ["+", 0, 754, 75, 754, 75, 754, 15, 738, 31, 22]]
| 4
| 97
| 2
|
St = Win = 1
Sc = Lose = 2
Pa = Draw = 3
def getWinHand hand
st = hand.include? St
sc = hand.include? Sc
pa = hand.include? Pa
if (st && sc && pa) || (st && !sc && !pa) || (!st && sc && !pa) || (!st && !sc && pa)
Draw
elsif st && pa
Pa
elsif st && sc
St
elsif sc && pa
Sc
end
end
def getResult hand, winHand
if winHand == Draw
Draw
elsif hand == winHand
Win
else
Lose
end
end
def showResult hand
winHand = getWinHand hand
hand.each do |h|
p getResult(h, winHand)
end
end
until (n = $stdin.gets.to_i) == 0
hand = [n]
4.times do
hand << $stdin.gets.to_i
end
showResult(hand)
end
|
St = Win = 1
Sc = Lose = 2
Pa = Draw = 3
NoWin = -1
def getWinHand hand
st = hand.include? St
sc = hand.include? Sc
pa = hand.include? Pa
if (st && sc && pa) || (st && !sc && !pa) || (!st && sc && !pa) || (!st && !sc && pa)
NoWin
elsif st && pa
Pa
elsif st && sc
St
elsif sc && pa
Sc
end
end
def getResult hand, winHand
if winHand == NoWin
Draw
elsif hand == winHand
Win
else
Lose
end
end
def showResult hand
winHand = getWinHand hand
hand.each do |h|
p getResult(h, winHand)
end
end
until (n = $stdin.gets.to_i) == 0
hand = [n]
4.times do
hand << $stdin.gets.to_i
end
showResult(hand)
end
|
[["+", 36, 36, 36, 36, 0, 493, 0, 662, 31, 743], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 0, 32], ["+", 36, 36, 0, 493, 0, 662, 12, 748, 17, 33], ["+", 36, 36, 0, 493, 0, 662, 12, 748, 439, 612], ["-", 0, 735, 8, 736, 0, 121, 64, 749, 0, 743], ["+", 0, 735, 8, 736, 0, 121, 64, 749, 0, 743], ["-", 0, 735, 8, 736, 0, 121, 15, 738, 12, 743], ["+", 0, 735, 8, 736, 0, 121, 15, 738, 12, 743]]
| 4
| 168
| 8
|
while True:
h = int(input())
if h == 0:
break
dataset = [h] + [int(input()) for _ in range(4)]
if len(set(dataset)) == 3 or len(set(dataset)) == 1:
print(*[3]*5, sep="\n")
for data in dataset:
if data == 1:
print(2 if 3 in dataset else 1)
elif data == 2:
print(2 if 1 in dataset else 1)
else:
print(2 if 2 in dataset else 1)
|
while True:
h = int(input())
if h == 0:
break
dataset = [h] + [int(input()) for _ in range(4)]
if len(set(dataset)) == 3 or len(set(dataset)) == 1:
print(*[3]*5, sep="\n")
continue
for data in dataset:
if data == 1:
print(2 if 3 in dataset else 1)
elif data == 2:
print(2 if 1 in dataset else 1)
else:
print(2 if 2 in dataset else 1)
|
[["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117]]
| 5
| 121
| 1
|
# -*- coding: utf-8 -*-
#import pdb; pdb.set_trace()
import sys
def solv(v):
w = set(v)
if len(w)==1 or len(w)==3:
d={1:2, 2:2, 3:2}
elif 1 in w and 2 in w:
d={1:1, 2:2}
elif 2 in w and 3 in w:
d={2:1, 3:2}
else:
d={3:1, 1:2}
return(list(map(lambda x:d[x], v) ))
def main():
if True:
fh = sys.stdin
else:
fh = open('vol2_0205.txt', 'r')
try:
while True:
te = []
for _ in range(5):
x=int(fh.readline().strip())
if x==0:
raise Exception
te.append(x)
b=(solv(te))
for i in b:
print(i)
except Exception:
1
fh.close()
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
#import pdb; pdb.set_trace()
import sys
def solv(v):
w = set(v)
if len(w)==1 or len(w)==3:
d={1:3, 2:3, 3:3}
elif 1 in w and 2 in w:
d={1:1, 2:2}
elif 2 in w and 3 in w:
d={2:1, 3:2}
else:
d={3:1, 1:2}
return(list(map(lambda x:d[x], v) ))
def main():
if True:
fh = sys.stdin
else:
fh = open('vol2_0205.txt', 'r')
try:
while True:
te = []
for _ in range(5):
x=int(fh.readline().strip())
if x==0:
raise Exception
te.append(x)
b=(solv(te))
for i in b:
print(i)
except Exception:
1
fh.close()
if __name__ == '__main__':
main()
|
[["-", 0, 1, 0, 662, 12, 680, 0, 569, 51, 612], ["+", 0, 1, 0, 662, 12, 680, 0, 569, 51, 612]]
| 5
| 224
| 6
|
def judge(h, hset):
rest = hset - {h}
if len(rest) in (0, 2):
return 3
if (h + 1) % 3 in rest:
return 1
else:
return 2
while True:
h1 = int(input())
if h1 == 0:
break
hlst = []
hset = set()
hlst.append(h1)
hset.add(h1)
for _ in range(4):
h = int(input())
hlst.append(h)
hset.add(h)
for h in hlst:
print(judge(h, hset))
|
def judge(h, hset):
rest = hset - {h}
if len(rest) in (0, 2):
return 3
if h % 3 + 1 in rest:
return 1
else:
return 2
while True:
h1 = int(input())
if h1 == 0:
break
hlst = []
hset = set()
hlst.append(h1)
hset.add(h1)
for _ in range(4):
h = int(input())
hlst.append(h)
hset.add(h)
for h in hlst:
print(judge(h, hset))
|
[["-", 0, 57, 15, 666, 0, 657, 31, 23, 0, 24], ["-", 15, 666, 0, 657, 31, 23, 0, 657, 17, 72], ["-", 15, 666, 0, 657, 31, 23, 0, 657, 12, 612], ["-", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612]]
| 5
| 126
| 6
|
while True:
try:
h=[eval(input()) for i in [1]*5]
if (1 in h and 2 in h and 3) in h or max(h.count(1),h.count(2),h.count(3))==5:
for i in h:
print(3)
elif 1 in h:
if 2 in h:
for i in h:
print(1 if i==1 else 2)
else:
for i in h:
print(1 if i==3 else 2)
elif 2 in h:
for i in h:
print(1 if i==2 else 1)
except:
break
|
while True:
try:
h=[eval(input()) for i in [1]*5]
if (1 in h and 2 in h and 3) in h or max(h.count(1),h.count(2),h.count(3))==5:
for i in h:print(3)
elif 1 in h:
if 2 in h:
for i in h:print(1 if i==1 else 2)
else:
for i in h:print(1 if i==3 else 2)
elif 2 in h:
for i in h:print(1 if i==2 else 2)
except:
break
|
[["-", 0, 1, 0, 652, 3, 4, 0, 41, 0, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 41, 0, 612]]
| 5
| 138
| 2
|
while True:
try:
h=[eval(input()) for i in [1]*5]
if 1 and 2 in h:w=1
elif 1 and 3 in h:w=3
else:w=2
if len(set(h))!=2:
for i in h:print(3)
else:
for i in h:print(1 if i==w else 2)
except:break
|
while True:
try:
h=[eval(input()) for i in [1]*5]
if 1 in h and 2 in h:w=1
elif 1 in h:w=3
else:w=2
if len(set( h))!=2:
for i in h:print(3)
else:
for i in h:print(1 if i==w else 2)
except:break
|
[["+", 8, 196, 0, 57, 15, 679, 31, 666, 667, 267], ["+", 8, 196, 0, 57, 15, 679, 31, 666, 0, 22], ["-", 8, 196, 0, 57, 75, 665, 15, 679, 17, 355], ["-", 0, 57, 75, 665, 15, 679, 12, 666, 0, 612]]
| 5
| 88
| 4
|
import static java.lang.System.*;
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
boolean F = false;
int saving = 0;
int[] a = new int[12], b = new int[12];
for (int i = 0; i < 12; i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
for (int i = 0; i < 12; i++) {
saving += a[i] - b[i];
if (saving >= n) {
out.println(i + 1);
F = true;
break;
}
}
if (F)
out.println("NA");
}
}
}
|
import static java.lang.System.*;
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
boolean F = false;
int saving = 0;
int[] a = new int[12], b = new int[12];
for (int i = 0; i < 12; i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
for (int i = 0; i < 12; i++) {
saving += a[i] - b[i];
if (saving >= n) {
out.println(i + 1);
F = true;
break;
}
}
if (!F)
out.println("NA");
}
}
}
|
[["+", 8, 196, 0, 57, 15, 15, 0, 91, 17, 111]]
| 3
| 200
| 1
|
import java.util.*;
class Main {
public static void main(String[] z) {
Scanner s = new Scanner(System.in);
String r;
for (int m, t; (m = s.nextInt()) > 0; System.out.println(r))
for (r = "NA", t = 12; t-- > 0;)
if ((m -= s.nextInt() - s.nextInt()) <= 0 && r == "NA")
r = "" + t;
}
}
|
import java.util.*;
class Main {
public static void main(String[] z) {
Scanner s = new Scanner(System.in);
String r;
for (int m, t; (m = s.nextInt()) > 0; System.out.println(r))
for (r = "NA", t = 0; t++ < 12;)
if ((m -= s.nextInt() - s.nextInt()) <= 0 && r == "NA")
r = "" + t;
}
}
|
[["-", 8, 196, 0, 7, 8, 7, 502, 11, 12, 499], ["+", 8, 196, 0, 7, 8, 7, 502, 11, 12, 499], ["-", 0, 7, 8, 7, 15, 16, 31, 27, 0, 68], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 17, 47], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 12, 499], ["+", 0, 7, 8, 7, 15, 16, 31, 27, 0, 29], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 12, 499]]
| 3
| 116
| 8
|
import java.util.Scanner;
class exe0206 {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
while (true) {
int l = scan.nextInt();
if (l == 0)
break;
int sum = 0, x = 0;
for (int i = 0; i < 12; i++) {
int m, n;
m = scan.nextInt();
n = scan.nextInt();
sum += m - n;
if (sum >= l && x == 0)
x = i;
}
if (sum >= l)
System.out.println(x + 1);
else
System.out.println("NA");
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
while (true) {
int l = scan.nextInt();
if (l == 0)
break;
int sum = 0, x = 0;
for (int i = 1; i <= 12; i++) {
int m, n;
m = scan.nextInt();
n = scan.nextInt();
sum += m - n;
if (sum >= l && x == 0)
x = i;
}
if (sum >= l)
System.out.println(x);
else
System.out.println("NA");
}
}
}
|
[["-", 36, 36, 36, 36, 0, 493, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 235, 141, 22], ["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 64, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["-", 64, 1, 0, 492, 3, 4, 0, 16, 12, 499]]
| 3
| 152
| 8
|
#include <stdio.h>
int main(void) {
int L, M, N, sum, num, i;
while (scanf("%d", &L), L != 0) {
num = 0;
sum = 0;
for (i = 0; i < 12; i++) {
scanf("%d %d", &M, &N);
sum += M - N;
if (num == 0 && sum >= L) {
num = i + 1;
}
}
if (num == 0) {
printf("NA\n");
} else {
printf("%d", num);
}
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int L, M, N, sum, num, i;
while (scanf("%d", &L), L) {
num = 0;
sum = 0;
for (i = 0; i < 12; i++) {
scanf("%d %d", &M, &N);
sum += M - N;
if (num == 0 && sum >= L) {
num = i + 1;
}
}
if (num == 0) {
printf("NA\n");
} else {
printf("%d\n", num);
}
}
return (0);
}
|
[["-", 0, 52, 15, 23, 0, 34, 12, 16, 17, 79], ["-", 0, 52, 15, 23, 0, 34, 12, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 133
| 3
|
#include <stdio.h>
int main(void) {
int ryohi, in, out, sum;
int i, k;
scanf("%d", &ryohi);
while (ryohi) {
k = 0;
sum = 0;
for (i = 0; i < 12; i++) {
scanf("%d", &in);
scanf("%d", &out);
sum += (in - out);
if (sum < ryohi)
k++;
}
if (k == 12) {
puts("NA\n");
} else {
printf("%d\n", k + 1);
}
scanf("%d", &ryohi);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int ryohi, in, out, sum;
int i, k;
scanf("%d", &ryohi);
while (ryohi) {
k = 0;
sum = 0;
for (i = 0; i < 12; i++) {
scanf("%d", &in);
scanf("%d", &out);
sum += (in - out);
if (sum < ryohi)
k++;
}
if (k == 12) {
puts("NA");
} else {
printf("%d\n", k + 1);
}
scanf("%d", &ryohi);
}
return (0);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 145
| 1
|
#include <stdio.h>
int main() {
int i = 0, l, n, m, a[12], b;
while (1) {
b = 0;
scanf("%d", &l);
if (l == 0) {
break;
}
for (i = 0; i < 12; i++) {
scanf("%d%d", &m, &n);
a[i] = m - n;
}
for (i = 0; i < 12; i++) {
b = b + a[i];
if (b >= l) {
printf("%d", i + 1);
break;
}
}
if (b < l) {
printf("NA");
}
}
}
|
#include <stdio.h>
int main() {
int i = 0, l, n, m, a[12], b;
while (1) {
b = 0;
scanf("%d", &l);
if (l == 0) {
break;
}
for (i = 0; i < 12; i++) {
scanf("%d%d", &m, &n);
a[i] = m - n;
}
for (i = 0; i < 12; i++) {
b = b + a[i];
if (b >= l) {
printf("%d\n", i + 1);
break;
}
}
if (b < l) {
printf("NA\n");
}
}
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 153
| 2
|
#include <stdio.h>
int main(void) {
int L, M1, M2, sum, i, month;
while (1) {
sum = 0;
month = 0;
scanf("%d", &L);
if (L == 0)
break;
for (i = 0; i < 12; i++) {
scanf("%d %d", &M1, &M2);
sum += M1 - M2;
if (sum >= L && month == 0) {
month = i + 1;
}
}
if (month <= 12)
printf("%d\n", month);
else
puts("NA");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int L, M1, M2, sum, i, month;
while (1) {
sum = 0;
month = 0;
scanf("%d", &L);
if (L == 0)
break;
for (i = 0; i < 12; i++) {
scanf("%d %d", &M1, &M2);
sum += M1 - M2;
if (sum >= L && month == 0) {
month = i + 1;
}
}
if (month > 0 && month <= 12)
printf("%d\n", month);
else
puts("NA");
}
return 0;
}
|
[["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22]]
| 0
| 133
| 4
|
#include <stdio.h>
int main() {
int l, n, m, i, count;
while (1) {
count = 0;
scanf("%d", &l);
if (l == 0)
break;
for (i = 0; i < 12; i++) {
scanf("%d %d", &m, &n);
l = l - (m - n);
if (l > 0)
count++;
}
if (count >= 11 && l != 0)
printf("NA\n");
else
printf("%d\n", count + 1);
}
return 0;
}
|
#include <stdio.h>
int main() {
int l, n, m, i, count;
while (1) {
count = 0;
scanf("%d", &l);
if (l == 0)
break;
for (i = 0; i < 12; i++) {
scanf("%d %d", &m, &n);
l = l - (m - n);
if (l > 0)
count++;
}
if (count >= 11 && l > 0)
printf("NA\n");
else
printf("%d\n", count + 1);
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47]]
| 0
| 128
| 2
|
L, m, a, i;
main(n) {
for (; scanf("%d", &L) * L; printf(a ? "%d\n" : "NA", a))
for (a = i = 0; ++i<13; a = a | L> 0 ? a : i)
scanf("%d%d", &m, &n), L -= m - n;
}
|
L, m, a, i;
main(n) {
for (; scanf("%d", &L) * L; printf(a ? "%d\n" : "NA\n", a))
for (a = i = 0; ++i<13; a = a | L> 0 ? a : i)
scanf("%d%d", &m, &n), L -= m - n;
}
|
[["+", 26, 2, 3, 4, 0, 41, 75, 5, 0, 44]]
| 0
| 89
| 1
|
#include <stdio.h>
main() {
int m, n, l, i, s, p;
while (1) {
scanf("%d", &l);
if (l == 0) {
break;
}
i = s = p = 0;
while (i < 12) {
i++;
scanf("%d %d", &m, &n);
s += (m - n);
if (s >= l && p == 0) {
p = i;
}
}
if (p != 12 && p != 0) {
printf("%d\n", p);
} else {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
main() {
int m, n, l, i, s, p;
while (1) {
scanf("%d", &l);
if (l == 0) {
break;
}
i = s = p = 0;
while (i < 12) {
i++;
scanf("%d %d", &m, &n);
s += (m - n);
if (s >= l && p == 0) {
p = i;
}
}
if (p != 0) {
printf("%d\n", p);
} else {
printf("NA\n");
}
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 79]]
| 0
| 139
| 4
|
#include <stdio.h>
int main(void) {
int i, M, N, L, total, month, f = 0;
for (;;) {
total = 0, month = 0;
scanf("%d", &L);
if (L == 0)
break;
for (i = 1; i <= 12; i++) {
scanf("%d%d", &M, &N);
total = total + M - N;
if (total >= L && f == 0) {
month = i;
f++;
}
}
if (total >= L)
printf("%d\n", month);
else
printf("NA\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, M, N, L, total, month, f = 0;
for (;;) {
total = 0, month = 0, f = 0;
scanf("%d", &L);
if (L == 0)
break;
for (i = 1; i <= 12; i++) {
scanf("%d%d", &M, &N);
total = total + M - N;
if (total >= L && f == 0) {
month = i;
f++;
}
}
if (total >= L)
printf("%d\n", month);
else
printf("NA\n");
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 34, 12, 34, 0, 21], ["+", 0, 1, 0, 34, 12, 34, 12, 11, 31, 22], ["+", 0, 1, 0, 34, 12, 34, 12, 11, 17, 32], ["+", 0, 1, 0, 34, 12, 34, 12, 11, 12, 13]]
| 0
| 142
| 4
|
#include <iostream>
using namespace std;
int main() {
// your code goes here
int n, m, s, sum;
while (cin >> n && n != 0) {
sum = 0;
int i;
for (i = 0; i < 12; i++) {
cin >> m >> s;
sum += m - s;
if (sum >= n) {
cout << i + 1 << endl;
break;
}
}
for (; i < 12; i++)
cin >> m >> s;
if (sum < n)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
// your code goes here
int n, m, s, sum;
while (cin >> n && n != 0) {
sum = 0;
int i;
for (i = 0; i < 12; i++) {
cin >> m >> s;
sum += m - s;
if (sum >= n) {
cout << i + 1 << endl;
break;
}
}
for (i = i + 1; i < 12; i++)
cin >> m >> s;
if (sum < n)
cout << "NA" << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 7, 10, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 17, 32], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
| 1
| 119
| 5
|
q,w,e=range,(lambda: eval(input())),input
while True:
n=w()
if n==0:break
d={}
for i in q(n):
o=e().split()
d[o[0]]=int(o[1])
for j in q(w()):
t=e().split()
a=sum([d[i] for i in t[2:]])
d[t[0]]=a if a<d[t[0]] else d[t[0]]
print(d[e()])
|
q,w,e=range,(lambda: eval(input())),input
while True:
n=w()
if n==0:break
d={}
for i in q(n):
o=e().split()
d[o[0]]=int(o[1])
for j in q(w()):
t=e().split()
a=sum([d[i] if i in d else 0 for i in t[2:]])
d[t[0]]=a if a<d[t[0]] else d[t[0]]
print(d[e()])
|
[["+", 12, 652, 3, 4, 0, 658, 8, 41, 0, 121], ["+", 3, 4, 0, 658, 8, 41, 0, 666, 0, 22], ["+", 3, 4, 0, 658, 8, 41, 0, 666, 667, 267], ["+", 12, 652, 3, 4, 0, 658, 8, 41, 0, 95], ["+", 12, 652, 3, 4, 0, 658, 8, 41, 0, 612]]
| 5
| 144
| 6
|
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
private void run() throws IOException {
Scanner scanner = new Scanner(System.in);
int MAX = 1000000;
boolean[] prime = new boolean[MAX + 1];
for (int i = 2; i <= MAX; i++) {
if (!prime[i]) {
for (int j = i * 2; j <= MAX; j += i) {
prime[j] = true;
}
}
}
while (true) {
int n = scanner.nextInt();
int m = scanner.nextInt();
if ((n | m) == 0)
break;
int[] a = new int[n];
int min = Integer.MAX_VALUE;
boolean[] f = new boolean[m + 1];
f[0] = true;
for (int i = 0; i < n; i++) {
int s = scanner.nextInt();
min = Math.min(s, min);
a[i] = s;
for (int j = s; j <= m; j += s) {
f[j] = true;
}
}
int max = 0;
for (int i = min; i <= m; i++) {
if (f[i])
continue;
for (int j = 0; j < n; j++) {
if (i - a[j] >= 0 && f[i - a[j]]) {
f[i] = true;
break;
}
}
if (f[i] && !prime[i])
max = i;
}
System.out.println(max == 0 ? "NA" : max);
}
}
}
|
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
private void run() throws IOException {
Scanner scanner = new Scanner(System.in);
int MAX = 1000000;
boolean[] prime = new boolean[MAX + 1];
for (int i = 2; i <= MAX; i++) {
if (!prime[i]) {
for (int j = i * 2; j <= MAX; j += i) {
prime[j] = true;
}
}
}
while (true) {
int n = scanner.nextInt();
int m = scanner.nextInt();
if ((n | m) == 0)
break;
int[] a = new int[n];
int min = Integer.MAX_VALUE;
boolean[] f = new boolean[m + 1];
f[0] = true;
for (int i = 0; i < n; i++) {
int s = scanner.nextInt();
min = Math.min(s, min);
a[i] = s;
for (int j = s; j <= m; j += s) {
f[j] = true;
}
}
int max = 0;
for (int i = min; i <= m; i++) {
if (!f[i])
for (int j = 0; j < n; j++) {
if (i - a[j] >= 0 && f[i - a[j]]) {
f[i] = true;
break;
}
}
if (f[i] && !prime[i])
max = i;
}
System.out.println(max == 0 ? "NA" : max);
}
}
}
|
[["+", 8, 196, 0, 57, 15, 15, 0, 91, 17, 111], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
| 3
| 385
| 3
|
/**
* At Boss's Expense
*/
import static java.lang.Integer.parseInt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
static boolean[] primes = new boolean[1000001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
//
Arrays.fill(primes, true);
for (int i = 2; i < 1000000 / 2 + 1; i++) {
if (primes[i]) {
for (int j = i; j < 1000000 + 1; j += i) {
primes[i + j] = false;
}
}
}
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = parseInt(line.substring(0, line.indexOf(' ')));
int x = parseInt(line.substring(line.indexOf(' ') + 1));
if ((n | x) == 0)
break;
int max = 0;
int[] dp = new int[x + 1];
int[] c = new int[n];
for (int i = 0; i < n; i++)
c[i] = parseInt(br.readLine());
for (int i = 0; i < n; i++) {
for (int j = c[i]; j <= x; j++) {
dp[j] = Math.max(dp[j], dp[j - c[i]] + c[i]);
if (primes[dp[j]])
max = Math.max(max, dp[j]);
}
}
System.out.println(max != 0 ? max : "NA");
} // end while
} // end main
}
|
/**
* At Boss's Expense
*/
import static java.lang.Integer.parseInt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
static boolean[] primes = new boolean[1000001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
//
Arrays.fill(primes, true);
for (int i = 2; i < 1000000 / 2 + 1; i++) {
if (primes[i]) {
for (int j = 2 * i; j < 1000000 + 1; j += i) {
primes[j] = false;
}
}
}
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = parseInt(line.substring(0, line.indexOf(' ')));
int x = parseInt(line.substring(line.indexOf(' ') + 1));
if ((n | x) == 0)
break;
int max = 0;
int[] dp = new int[x + 1];
int[] c = new int[n];
for (int i = 0; i < n; i++)
c[i] = parseInt(br.readLine());
for (int i = 0; i < n; i++) {
for (int j = c[i]; j <= x; j++) {
dp[j] = Math.max(dp[j], dp[j - c[i]] + c[i]);
if (primes[dp[j]])
max = Math.max(max, dp[j]);
}
}
System.out.println(max != 0 ? max : "NA");
} // end while
} // end main
}
|
[["+", 0, 7, 502, 503, 49, 200, 51, 16, 31, 499], ["+", 0, 7, 502, 503, 49, 200, 51, 16, 17, 48], ["-", 0, 1, 0, 11, 31, 504, 71, 16, 31, 22], ["-", 0, 1, 0, 11, 31, 504, 71, 16, 17, 72]]
| 3
| 395
| 4
|
import java.util.*;
class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
while (scan.hasNext()) {
int n = scan.nextInt();
int money = scan.nextInt();
boolean[] dp = new boolean[money + 1];
if (n == 0) {
break;
}
int[] menu = new int[30];
for (int i = 0; i < n; i++) {
menu[i] = scan.nextInt();
}
solve(dp, menu);
int i;
for (i = dp.length - 1; i >= 0; i--) {
if (dp[i] && prime(i)) {
break;
}
}
if (i < 0) {
System.out.println("NA");
} else {
System.out.println(i);
}
}
}
public static void solve(boolean dp[], int menu[]) {
for (int i = 0; i < menu.length; i++) {
if (menu[i] > dp.length) {
continue;
}
dp[menu[i]] = true;
for (int j = 1; j < dp.length; j++) {
if (dp[j] && j + menu[i] < dp.length) {
dp[j + menu[i]] = true;
}
}
}
}
public static boolean prime(int a) {
if (a <= 3) {
return true;
} else {
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
return false;
}
}
}
return true;
}
}
|
import java.util.*;
class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
while (scan.hasNext()) {
int n = scan.nextInt();
int money = scan.nextInt();
boolean[] dp = new boolean[money + 1];
if (n == 0) {
break;
}
int[] menu = new int[30];
for (int i = 0; i < n; i++) {
menu[i] = scan.nextInt();
}
solve(dp, menu);
int i;
for (i = dp.length - 1; i >= 0; i--) {
if (dp[i] && prime(i)) {
break;
}
}
if (i < 1) {
System.out.println("NA");
} else {
System.out.println(i);
}
}
}
public static void solve(boolean dp[], int menu[]) {
for (int i = 0; i < menu.length; i++) {
if (menu[i] > dp.length) {
continue;
}
dp[menu[i]] = true;
for (int j = 1; j < dp.length; j++) {
if (dp[j] && j + menu[i] < dp.length) {
dp[j + menu[i]] = true;
}
}
}
}
public static boolean prime(int a) {
if (a <= 3) {
return true;
} else {
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
return false;
}
}
}
return true;
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
| 3
| 368
| 2
|
import java.util.*;
class Main {
public static void main(String args[]) {
boolean[] prime = new boolean[1000001];
prime[0] = true;
prime[1] = true;
for (int i = 0; i < 1000001; i++) {
if (!prime[i]) {
int j = 2;
while (i * j < 1000001) {
prime[i * j] = true;
j++;
}
}
}
try (Scanner sc = new Scanner(System.in)) {
while (true) {
long n = sc.nextLong(), x = sc.nextLong();
if (n == 0 && x == 0) {
break;
}
long ans = -1;
boolean[] vs = new boolean[(int)x + 1];
vs[0] = true;
for (long i = 0; i < n; i++) {
long v = sc.nextLong();
for (long j = 0; j < x - v; j++) {
if (vs[(int)j]) {
vs[(int)(j + v)] = true;
if (!prime[(int)(j + v)]) {
ans = Math.max(j + v, ans);
}
}
}
}
if (ans == -1) {
System.out.println("NA");
} else {
System.out.println(ans);
}
}
}
}
}
|
import java.util.*;
class Main {
public static void main(String args[]) {
boolean[] prime = new boolean[1000001];
prime[0] = true;
prime[1] = true;
for (int i = 0; i < 1000001; i++) {
if (!prime[i]) {
int j = 2;
while (i * j < 1000001) {
prime[i * j] = true;
j++;
}
}
}
try (Scanner sc = new Scanner(System.in)) {
while (true) {
long n = sc.nextLong(), x = sc.nextLong();
if (n == 0 && x == 0) {
break;
}
long ans = -1;
boolean[] vs = new boolean[(int)x + 1];
vs[0] = true;
for (long i = 0; i < n; i++) {
long v = sc.nextLong();
for (long j = 0; j <= x - v; j++) {
if (vs[(int)j]) {
vs[(int)(j + v)] = true;
if (!prime[(int)(j + v)]) {
ans = Math.max(j + v, ans);
}
}
}
}
if (ans == -1) {
System.out.println("NA");
} else {
System.out.println(ans);
}
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 313
| 2
|
#define M 1000001
T[M], t[M], a;
main(m, n, x, i, j) {
for (i = 2; i < M; i++)
if (!T[i])
for (j = i * 2; j < M; j += i)
T[j] = 1;
for (; scanf("%d%d", &n, &x), n; printf(m ? "%d\n" : "NA\n", m)) {
for (memset(t, 0, sizeof(t)), t[0] = 1, m = i = 0; i < n; i++) {
for (scanf("%d", &a), j = 0; j + a <= x; j++)
if (t[j])
if (t[j + a] = 1, !T[j + a])
m = j + a;
}
}
exit(0);
}
|
#define M 1000001
T[M], t[M], a;
main(m, n, x, i, j) {
for (i = 2; i < M; i++)
if (!T[i])
for (j = i * 2; j < M; j += i)
T[j] = 1;
for (; scanf("%d%d", &n, &x), n; printf(m ? "%d\n" : "NA\n", m)) {
for (memset(t, 0, sizeof(t)), t[0] = 1, m = i = 0; i < n; i++) {
for (scanf("%d", &a), j = 0; j + a <= x; j++)
if (t[j])
if (t[j + a] = 1, !T[j + a] && m < j + a)
m = j + a;
}
}
exit(0);
}
|
[["+", 64, 57, 15, 23, 0, 34, 12, 16, 17, 98], ["+", 15, 23, 0, 34, 12, 16, 12, 16, 31, 22], ["+", 15, 23, 0, 34, 12, 16, 12, 16, 17, 18], ["+", 0, 34, 12, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 34, 12, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 34, 12, 16, 12, 16, 12, 16, 12, 22]]
| 0
| 209
| 6
|
#include <stdio.h>
#define S 1000001
#define N 30
int dp[S] = {0}; // dp[i] := 商品の金額和がSとなるか
int main(void) {
int isprime[S];
int i, j;
for (i = 0; i < S; i++)
isprime[i] = 1;
isprime[2] = 1;
for (i = 2; i < S; i++) {
if (isprime[i]) {
for (j = i + i; j < S; j += i) {
isprime[j] = 0;
}
}
}
while (1) {
int n, x;
int prices[N];
scanf("%d %d", &n, &x);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &prices[i]);
}
for (i = 0; i < S; i++) {
dp[i] = 0;
}
dp[0] = 1;
for (i = 0; i < S; i++) {
if (dp[i]) {
for (j = 0; j < N; j++) {
if (i + prices[j] <= x) {
dp[i + prices[j]] = 1;
}
}
}
}
int ans = 0;
for (i = x; i >= 0; i--) {
if (dp[i] && isprime[i]) {
ans = i;
break;
}
}
if (ans) {
printf("%d\n", ans);
} else {
printf("NA\n");
}
}
return 0;
}
|
#include <stdio.h>
#define S 1000001
#define N 30
int dp[S] = {0}; // dp[i] := 商品の金額和がSとなるか
int main(void) {
int isprime[S];
int i, j;
for (i = 0; i < S; i++)
isprime[i] = 1;
isprime[2] = 1;
for (i = 2; i < S; i++) {
if (isprime[i]) {
for (j = i + i; j < S; j += i) {
isprime[j] = 0;
}
}
}
while (1) {
int n, x;
int prices[N];
scanf("%d %d", &n, &x);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &prices[i]);
}
for (i = 0; i < S; i++) {
dp[i] = 0;
}
dp[0] = 1;
for (i = 0; i <= x; i++) {
if (dp[i]) {
for (j = 0; j < n; j++) {
if (i + prices[j] <= x) {
dp[i + prices[j]] = 1;
}
}
}
}
int ans = 0;
for (i = x; i >= 0; i--) {
if (dp[i] && isprime[i]) {
ans = i;
break;
}
}
if (ans) {
printf("%d\n", ans);
} else {
printf("NA\n");
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22]]
| 0
| 342
| 6
|
#include <iostream>
using namespace std;
int main() {
bool nonprime[1000001] = {};
nonprime[0] = nonprime[1] = true;
for (int i = 2; i <= 1000000; i++) {
if (!nonprime[i]) {
for (int j = i + i; j <= 1000000; j += i) {
nonprime[j] = true;
}
}
}
while (1) {
int n, x;
cin >> n >> x;
if (n + x == 0)
break;
bool valid[x + 1] = {};
valid[0] = true;
int v;
for (int i = 0; i < n; i++) {
cin >> v;
for (int j = 0; j <= x - v; j++) {
if (valid[j])
valid[j + v] = true;
}
}
int ans = -1;
for (int i = x; i >= 1; i--) {
if (!nonprime[i]) {
ans = i;
break;
}
}
if (ans == -1)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
bool nonprime[1000001] = {};
nonprime[0] = nonprime[1] = true;
for (int i = 2; i <= 1000000; i++) {
if (!nonprime[i]) {
for (int j = i + i; j <= 1000000; j += i) {
nonprime[j] = true;
}
}
}
while (1) {
int n, x;
cin >> n >> x;
if (n + x == 0)
break;
bool valid[x + 1] = {};
valid[0] = true;
int v;
for (int i = 0; i < n; i++) {
cin >> v;
for (int j = 0; j <= x - v; j++) {
if (valid[j])
valid[j + v] = true;
}
}
int ans = -1;
for (int i = x; i >= 1; i--) {
if (valid[i] && !nonprime[i]) {
ans = i;
break;
}
}
if (ans == -1)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 248
| 5
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define REP2(i, d, n) for (int i = (d); i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define CLR(a) memset((a), 0, sizeof(a))
#define MCLR(a) memset((a), -1, sizeof(a))
#define RANGE(x, y, maxX, maxY) \
(0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};
bool dp[1000000];
const int MAX_N = 1000000;
vector<int> prime;
bool is_prime[MAX_N + 1];
// n以下の素数を生成する
void create_prime(int n) {
// 初期化
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
is_prime[i] = true;
}
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime.push_back(i);
for (int j = 2 * i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
}
int main() {
int n, x;
create_prime(MAX_N);
while (true) {
cin >> n >> x;
if (n == 0 && x == 0)
break;
REP(i, x + 1) { dp[i] = false; }
VI data;
int buf;
REP(i, n) {
cin >> buf;
data.PB(buf);
}
dp[0] = true;
REP(i, x) {
if (dp[i]) {
REP(j, n) {
if (i + data[j] < x)
dp[i + data[j]] = true;
}
}
}
int ans = 0;
REP(i, prime.size()) {
if (x <= prime[i])
break;
if (dp[prime[i]]) {
ans = prime[i];
}
}
if (ans != 0) {
cout << ans << endl;
} else {
cout << "NA" << endl;
}
}
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define REP2(i, d, n) for (int i = (d); i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define CLR(a) memset((a), 0, sizeof(a))
#define MCLR(a) memset((a), -1, sizeof(a))
#define RANGE(x, y, maxX, maxY) \
(0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};
bool dp[1000000];
const int MAX_N = 1000000;
vector<int> prime;
bool is_prime[MAX_N + 1];
// n以下の素数を生成する
void create_prime(int n) {
// 初期化
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
is_prime[i] = true;
}
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime.push_back(i);
for (int j = 2 * i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
}
int main() {
int n, x;
create_prime(MAX_N);
while (true) {
cin >> n >> x;
if (n == 0 && x == 0)
break;
REP(i, x + 1) { dp[i] = false; }
VI data;
int buf;
REP(i, n) {
cin >> buf;
data.PB(buf);
}
dp[0] = true;
REP(i, x) {
if (dp[i]) {
REP(j, n) {
if (i + data[j] <= x)
dp[i + data[j]] = true;
}
}
}
int ans = 0;
REP(i, prime.size()) {
if (x < prime[i])
break;
if (dp[prime[i]]) {
ans = prime[i];
}
}
if (ans != 0) {
cout << ans << endl;
} else {
cout << "NA" << endl;
}
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 547
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
bool dp[1000120];
bool notPrime[1000120];
int main() {
notPrime[0] = notPrime[1] = true;
for (int i = 2; i * i < 1000010; i++) {
for (int j = 2 * i; j < 1000010; j += i) {
notPrime[j] = true;
}
}
int n, x;
while (cin >> n >> x, n) {
dp[0] = true;
while (n--) {
int a;
cin >> a;
for (int i = 0; i <= x; i++) {
if (dp[i] && i + a <= 100010)
dp[i + a] = true;
}
}
bool flg = false;
for (int i = x; i >= 2; i--) {
if (!notPrime[i] & dp[i]) {
cout << i << endl;
flg = true;
break;
}
}
if (!flg)
cout << "NA" << endl;
for (int i = 0; i < 1000020; i++)
dp[i] = false;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
bool dp[1000120];
bool notPrime[1000120];
int main() {
notPrime[0] = notPrime[1] = true;
for (int i = 2; i * i < 1000010; i++) {
for (int j = 2 * i; j < 1000010; j += i) {
notPrime[j] = true;
}
}
int n, x;
while (cin >> n >> x, n) {
dp[0] = true;
while (n--) {
int a;
cin >> a;
for (int i = 0; i <= x; i++) {
if (dp[i] && i + a <= 1000010)
dp[i + a] = true;
}
}
bool flg = false;
for (int i = x; i >= 2; i--) {
if (!notPrime[i] & dp[i]) {
cout << i << endl;
flg = true;
break;
}
}
if (!flg)
cout << "NA" << endl;
for (int i = 0; i < 1000020; i++)
dp[i] = false;
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 240
| 2
|
#include <bits/stdc++.h>
#ifndef INCLUDE_BOOL_ARRAY_HPP
#define INCLUDE_BOOL_ARRAY_HPP
#include <cassert>
#include <cstring>
#include <limits>
namespace orliv {
template <unsigned int CAP> struct BoolArray {
typedef int memory_t;
memory_t K;
memory_t data[CAP];
BoolArray() { clear_deep(); }
void clear_deep() {
std::memset(data, sizeof(data), 0);
K = 1;
}
void clear() { K++; }
bool within_k(int x, int k) { return data[x] + k >= K; }
inline bool get(int x) { return data[x] == K; }
inline void set(int x) { data[x] = K; }
};
} // namespace orliv
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template <typename T> inline
#define TTF_ template <typename T, typename F> inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
T x;
cin >> x;
return x;
}
TT_ void Out(T &x) { cout << x; }
TT_ void sort(T &v) { sort(begin(v), end(v)); }
TT_ void revs(T &v) { reverse(begin(v), end(v)); }
TT_ void uniq(T &v) {
sort(v);
v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T &v, typename T::value_type x) {
return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T &v, typename T::value_type x) {
return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T &v, int n, F f) {
for (v.reserve(n); n--; v.emplace_back(f()))
;
}
TTF_ void show(T &v, F f, string d = " ", string e = "\n") {
int i = 0;
for (auto &x : v)
i++ && (cout << d), f(x);
cout << e;
}
TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); }
inline void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
ll r = 1;
for (; k > 0; a = a * a % m, k >>= 1)
if (k & 1)
r = r * a % m;
return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple
const int MAX_N = 10100100;
orliv::BoolArray<MAX_N> dp;
bool sieve[MAX_N];
int main() {
sieve[0] = sieve[1] = true;
for (int i = 2; i * i <= MAX_N; i++) {
if (sieve[i])
continue;
for (int j = i * i; j <= MAX_N; j += i) {
sieve[j] = true;
}
}
int n, x;
while (n = in(), x = in(), n) {
dp.set(0);
for (int i = 0; i < n; i++) {
int cost = in();
for (int j = 0; j + cost <= x; j++) {
if (dp.get(j))
dp.set(j + cost);
}
}
for (int i = x; i > 0; i--) {
if (sieve[i] && dp.get(i)) {
printf("%d\n", i);
goto END;
}
}
puts("NA");
END:;
dp.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
#ifndef INCLUDE_BOOL_ARRAY_HPP
#define INCLUDE_BOOL_ARRAY_HPP
#include <cassert>
#include <cstring>
#include <limits>
namespace orliv {
template <unsigned int CAP> struct BoolArray {
typedef int memory_t;
memory_t K;
memory_t data[CAP];
BoolArray() { clear_deep(); }
void clear_deep() {
std::memset(data, sizeof(data), 0);
K = 1;
}
void clear() { K++; }
bool within_k(int x, int k) { return data[x] + k >= K; }
inline bool get(int x) { return data[x] == K; }
inline void set(int x) { data[x] = K; }
};
} // namespace orliv
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template <typename T> inline
#define TTF_ template <typename T, typename F> inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
T x;
cin >> x;
return x;
}
TT_ void Out(T &x) { cout << x; }
TT_ void sort(T &v) { sort(begin(v), end(v)); }
TT_ void revs(T &v) { reverse(begin(v), end(v)); }
TT_ void uniq(T &v) {
sort(v);
v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T &v, typename T::value_type x) {
return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T &v, typename T::value_type x) {
return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T &v, int n, F f) {
for (v.reserve(n); n--; v.emplace_back(f()))
;
}
TTF_ void show(T &v, F f, string d = " ", string e = "\n") {
int i = 0;
for (auto &x : v)
i++ && (cout << d), f(x);
cout << e;
}
TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); }
inline void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
ll r = 1;
for (; k > 0; a = a * a % m, k >>= 1)
if (k & 1)
r = r * a % m;
return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple
const int MAX_N = 10100100;
orliv::BoolArray<MAX_N> dp;
bool sieve[MAX_N];
int main() {
sieve[0] = sieve[1] = true;
for (int i = 2; i * i <= MAX_N; i++) {
if (sieve[i])
continue;
for (int j = i * i; j <= MAX_N; j += i) {
sieve[j] = true;
}
}
int n, x;
while (n = in(), x = in(), n) {
dp.set(0);
for (int i = 0; i < n; i++) {
int cost = in();
for (int j = 0; j + cost <= x; j++) {
if (dp.get(j))
dp.set(j + cost);
}
}
for (int i = x; i > 0; i--) {
if (!sieve[i] && dp.get(i)) {
printf("%d\n", i);
goto END;
}
}
puts("NA");
END:;
dp.clear();
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 91, 17, 111]]
| 1
| 949
| 1
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template <typename T> inline
#define TTF_ template <typename T, typename F> inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
T x;
cin >> x;
return x;
}
TT_ void Out(T &x) { cout << x; }
TT_ void sort(T &v) { sort(begin(v), end(v)); }
TT_ void revs(T &v) { reverse(begin(v), end(v)); }
TT_ void uniq(T &v) {
sort(v);
v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T &v, typename T::value_type x) {
return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T &v, typename T::value_type x) {
return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T &v, int n, F f) {
for (v.reserve(n); n--; v.emplace_back(f()))
;
}
TTF_ void show(T &v, F f, string d = " ", string e = "\n") {
int i = 0;
for (auto &x : v)
i++ && (cout << d), f(x);
cout << e;
}
TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); }
inline void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
ll r = 1;
for (; k > 0; a = a * a % m, k >>= 1)
if (k & 1)
r = r * a % m;
return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple
const int MAX_N = 10100100;
int dp[MAX_N];
bool sieve[MAX_N];
int main() {
sieve[0] = sieve[1] = true;
for (int i = 2; i * i <= MAX_N; i++) {
if (sieve[i])
continue;
for (int j = i * i; j <= MAX_N; j += i) {
sieve[j] = true;
}
}
int n, x, K = 1;
while (n = in(), x = in(), n) {
int ans = -1;
dp[0] = K;
for (int i = 0; i < n; i++) {
int cost = in();
for (int j = 0; j + cost <= x; j++) {
if (dp[j] == K) {
dp[j + cost] = K;
if (!sieve[j + cost])
ans = max(ans, j + cost);
}
}
}
if (ans < 0)
puts("NA");
else
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template <typename T> inline
#define TTF_ template <typename T, typename F> inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
T x;
cin >> x;
return x;
}
TT_ void Out(T &x) { cout << x; }
TT_ void sort(T &v) { sort(begin(v), end(v)); }
TT_ void revs(T &v) { reverse(begin(v), end(v)); }
TT_ void uniq(T &v) {
sort(v);
v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T &v, typename T::value_type x) {
return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T &v, typename T::value_type x) {
return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T &v, int n, F f) {
for (v.reserve(n); n--; v.emplace_back(f()))
;
}
TTF_ void show(T &v, F f, string d = " ", string e = "\n") {
int i = 0;
for (auto &x : v)
i++ && (cout << d), f(x);
cout << e;
}
TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); }
inline void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
ll r = 1;
for (; k > 0; a = a * a % m, k >>= 1)
if (k & 1)
r = r * a % m;
return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple
const int MAX_N = 10100100;
int dp[MAX_N];
bool sieve[MAX_N];
int main() {
sieve[0] = sieve[1] = true;
for (int i = 2; i * i <= MAX_N; i++) {
if (sieve[i])
continue;
for (int j = i * i; j <= MAX_N; j += i) {
sieve[j] = true;
}
}
int n, x, K = 1;
while (n = in(), x = in(), n) {
int ans = -1;
dp[0] = K;
for (int i = 0; i < n; i++) {
int cost = in();
for (int j = 0; j + cost <= x; j++) {
if (dp[j] == K) {
dp[j + cost] = K;
if (!sieve[j + cost])
ans = max(ans, j + cost);
}
}
}
K++;
if (ans < 0)
puts("NA");
else
printf("%d\n", ans);
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 806
| 3
|
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 1e9
int main() {
int N = 1e6 + 1;
vector<bool> isPrime(N, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i < N; i++) {
if (!isPrime[i])
continue;
for (int j = i * i; j < N; j += i)
isPrime[j] = false;
}
while (true) {
int n, x;
cin >> n >> x;
if (n == 0 && x == 0) {
break;
}
vector<int> dishes(n, 0);
FOR(i, 0, n) { cin >> dishes[i]; }
vector<bool> dp(x + 1, false);
dp[0] = true;
int ans = 0;
for (auto dish : dishes) {
FOR(i, 0, x + 1) {
if ((i + dish < x + 1) && dp[i]) {
if (isPrime[i + dish])
ans = i + dish;
dp[i + dish] = true;
}
}
}
if (ans == 0)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 1e9
int main() {
int N = 1e6 + 1;
vector<bool> isPrime(N, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i < N; i++) {
if (!isPrime[i])
continue;
for (int j = i * i; j < N; j += i)
isPrime[j] = false;
}
while (true) {
int n, x;
cin >> n >> x;
if (n == 0 && x == 0) {
break;
}
vector<int> dishes(n, 0);
FOR(i, 0, n) { cin >> dishes[i]; }
vector<bool> dp(x + 1, false);
dp[0] = true;
int ans = 0;
for (auto dish : dishes) {
FOR(i, 0, x + 1) {
if ((i + dish < x + 1) && dp[i]) {
if (isPrime[i + dish])
ans = max(ans, i + dish);
dp[i + dish] = true;
}
}
}
if (ans == 0)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 57, 64, 1, 0, 11, 12, 2, 63, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
| 1
| 310
| 5
|
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
bool FF[1000002];
int main() {
for (int i = 3; i < 1000001; i += 2) {
FF[i] = true;
for (int j = 3; j * j <= i; j += 2)
if (i % j == 0) {
FF[i] = false;
break;
}
}
FF[2] = true;
int Q, M;
while (1) {
cin >> Q >> M;
if (Q == 0 && M == 0)
break;
int D[35] = {};
bool F[1000002];
for (int i = 0; i < Q; i++)
cin >> D[i];
int P = 0;
for (int i = 0; i <= M; i++)
F[i] = false;
for (int i = 0; i < Q; i++) {
for (int j = 2; j <= M; j++) {
if (j == D[i])
F[j] = true;
if (j - D[i] > 0 && F[j - D[i]] == true)
F[j] = true;
if (F[j] == true && FF[j] == true)
P = j;
}
}
if (P > 0)
cout << P << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
bool FF[1000002];
int main() {
for (int i = 3; i < 1000001; i += 2) {
FF[i] = true;
for (int j = 3; j * j <= i; j += 2)
if (i % j == 0) {
FF[i] = false;
break;
}
}
FF[2] = true;
int Q, M;
while (1) {
cin >> Q >> M;
if (Q == 0 && M == 0)
break;
int D[35] = {};
bool F[1000002];
for (int i = 0; i < Q; i++)
cin >> D[i];
int P = 0;
for (int i = 0; i <= M; i++)
F[i] = false;
for (int i = 0; i < Q; i++) {
for (int j = 0; j <= M; j++) {
if (j == D[i])
F[j] = true;
if (j - D[i] > 0 && F[j - D[i]] == true)
F[j] = true;
if (F[j] == true && FF[j] == true)
P = j;
}
}
if (P > 0)
cout << P << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 304
| 2
|
#include <iostream>
using namespace std;
const int INF = (1 << 25);
bool dp[1000001];
int price[31];
int n, x;
int checkprime(int num) {
for (int i = 2; i * i <= num; i++) {
if (num % i == 0)
return true;
}
return x == 1;
}
int main() {
while (cin >> n >> x, n || x) {
for (int i = 0; i < n; i++) {
cin >> price[i];
}
dp[0] = true;
for (int i = 1; i <= x; i++) {
dp[i] = false;
}
for (int i = 0; i < n; i++) {
for (int j = price[i]; j <= x; j++) {
if (dp[j - price[i]]) {
dp[j] = true;
}
}
}
int ans = INF;
for (int i = x - 1; i > 1; i--) {
if (dp[i] && !checkprime(i)) {
ans = i;
break;
}
}
if (ans == INF)
cout << "NA" << endl;
else
cout << ans << endl;
}
}
|
#include <iostream>
using namespace std;
const int INF = (1 << 25);
bool dp[1000001];
int price[31];
int n, x;
int checkprime(int num) {
for (int i = 2; i * i <= num; i++) {
if (num % i == 0)
return true;
}
return x == 1;
}
int main() {
while (cin >> n >> x, n || x) {
for (int i = 0; i < n; i++) {
cin >> price[i];
}
dp[0] = true;
for (int i = 1; i <= x; i++) {
dp[i] = false;
}
for (int i = 0; i < n; i++) {
for (int j = price[i]; j <= x; j++) {
if (dp[j - price[i]]) {
dp[j] = true;
}
}
}
int ans = INF;
for (int i = x; i > 0; i--) {
if (dp[i] && !checkprime(i)) {
ans = i;
break;
}
}
if (ans == INF)
cout << "NA" << endl;
else
cout << ans << endl;
}
}
|
[["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 33], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 269
| 4
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
int main() {
vector<int> primes;
primes.PB(2);
for (int i = 3; i <= 999991; i++) {
bool flg = true;
for (int j = 0; primes[j] * primes[j] <= i; j++) {
if (i % primes[j] == 0)
flg = false;
}
if (flg)
primes.PB(i);
}
while (true) {
int ans = 0;
int n, x;
cin >> n >> x;
if (n == 0 && x == 0)
break;
bool d[1000001] = {false};
d[0] = true;
REP(i, n) {
int a;
cin >> a;
for (int i = 0; i + a <= 1e6; i++) {
if (d[i])
d[i + a] = d[i];
}
}
int s = lower_bound(ALL(primes), x) - primes.begin();
RREP(i, s) {
if (d[primes[i]]) {
ans = primes[i];
break;
}
}
if (ans == 0)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
int main() {
vector<int> primes;
primes.PB(2);
for (int i = 3; i <= 1000001; i++) {
bool flg = true;
for (int j = 0; primes[j] * primes[j] <= i; j++) {
if (i % primes[j] == 0)
flg = false;
}
if (flg)
primes.PB(i);
}
while (true) {
int ans = 0;
int n, x;
cin >> n >> x;
if (n == 0 && x == 0)
break;
bool d[1000001] = {false};
d[0] = true;
REP(i, n) {
int a;
cin >> a;
for (int i = 0; i + a <= 1e6; i++) {
if (d[i])
d[i + a] = d[i];
}
}
int s = upper_bound(ALL(primes), x) - primes.begin();
RREP(i, s) {
if (d[primes[i]]) {
ans = primes[i];
break;
}
}
if (ans == 0)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 43, 49, 50, 51, 16, 31, 2, 63, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 2, 63, 22]]
| 1
| 337
| 4
|
#include <stdio.h>
int n, x, a[30];
bool dp[1000001], prime[1000001];
int main() {
for (int i = 2; i <= 1000000; i++)
prime[i] = true;
for (int i = 2; i <= 1000; i++) {
if (!prime[i])
continue;
for (int j = i * i; j <= 1000000; j += i)
prime[j] = false;
}
while (scanf("%d%d", &n, &x), n) {
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < x; i++)
dp[i + 1] = false;
dp[0] = true;
for (int i = 1; i <= x; i++) {
for (int j = 0; j < n; j++) {
if (i - a[j] >= 0)
dp[i] = dp[i] || dp[i - a[j]];
}
}
bool flag = false;
for (int i = x; i >= 1; i--) {
if (dp[i]) {
printf("%d\n", i);
flag = true;
break;
}
}
if (!flag)
printf("NA\n");
}
}
|
#include <stdio.h>
int n, x, a[30];
bool dp[1000001], prime[1000001];
int main() {
for (int i = 2; i <= 1000000; i++)
prime[i] = true;
for (int i = 2; i <= 1000; i++) {
if (!prime[i])
continue;
for (int j = i * i; j <= 1000000; j += i)
prime[j] = false;
}
while (scanf("%d%d", &n, &x), n) {
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < x; i++)
dp[i + 1] = false;
dp[0] = true;
for (int i = 1; i <= x; i++) {
for (int j = 0; j < n; j++) {
if (i - a[j] >= 0)
dp[i] = dp[i] || dp[i - a[j]];
}
}
bool flag = false;
for (int i = x; i >= 1; i--) {
if (dp[i] && prime[i]) {
printf("%d\n", i);
flag = true;
break;
}
}
if (!flag)
printf("NA\n");
}
}
|
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 73]]
| 1
| 298
| 28
|
#include <iostream>
using namespace std;
bool isprime[1000001]; // false????´???°
int main() {
isprime[1] = true;
int n, x;
int price[30];
for (int i = 2; i <= 1000000; i++) {
if (!isprime[i]) {
for (int j = i * 2; j <= 1000000; j += i) {
isprime[j] = true;
}
}
}
while (cin >> n >> x, n * x) {
bool isprice[1000001]; //??????????????????????????????true
for (int i = 0; i < n; i++) {
cin >> price[i];
isprice[price[i]] = true;
}
for (int i = 1; i <= x; i++) {
if (isprice[i]) {
for (int j = 0; j < n; j++) {
if (i + price[j] <= x) {
isprice[i + price[j]] = true;
}
}
}
}
int ans = 99999999;
for (int i = x; i >= 1; i--) {
if (!isprime[i] && isprice[i]) {
ans = i;
break;
}
}
if (ans == 99999999)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
bool isprime[1000001]; // false????´???°
int main() {
isprime[1] = true;
int n, x;
int price[30];
for (int i = 2; i <= 1000000; i++) {
if (!isprime[i]) {
for (int j = i * 2; j <= 1000000; j += i) {
isprime[j] = true;
}
}
}
while (cin >> n >> x, n * x) {
bool isprice[1000001] = {}; //??????????????????????????????true
for (int i = 0; i < n; i++) {
cin >> price[i];
isprice[price[i]] = true;
}
for (int i = 1; i <= x; i++) {
if (isprice[i]) {
for (int j = 0; j < n; j++) {
if (i + price[j] <= x) {
isprice[i + price[j]] = true;
}
}
}
}
int ans = 99999999;
for (int i = x; i >= 1; i--) {
if (!isprime[i] && isprice[i]) {
ans = i;
break;
}
}
if (ans == 99999999)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 45], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46]]
| 1
| 275
| 3
|
#include <cstring>
#include <iostream>
using namespace std;
int is[1000001];
bool isprime[1000001];
int main() {
isprime[0] = isprime[1] = true;
for (int i = 4; i <= 1000000; i += 2)
isprime[i] = true;
for (int i = 3; i * i <= 1000000; i += 2)
for (int j = 2; i * j <= 1000000; ++j)
isprime[i * j] = true;
int n, x, s;
while (cin >> n >> x, n | x) {
memset(is, -1, sizeof(is));
is[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> s;
for (int j = 0; j <= x; ++j) {
if (is[j] >= i)
continue;
if (is[j] >= 0) {
for (int k = 1; j + s * k <= x; ++k)
is[j + s * k] = i;
}
}
}
for (int j = x; j >= 0; --j) {
if (is[j] && !isprime[j]) {
cout << j << endl;
goto NEXT;
}
}
cout << "NA" << endl;
NEXT:;
}
}
|
#include <cstring>
#include <iostream>
using namespace std;
int is[1000001];
bool isprime[1000001];
int main() {
isprime[0] = isprime[1] = true;
for (int i = 4; i <= 1000000; i += 2)
isprime[i] = true;
for (int i = 3; i * i <= 1000000; i += 2)
for (int j = 2; i * j <= 1000000; ++j)
isprime[i * j] = true;
int n, x, s;
while (cin >> n >> x, n | x) {
memset(is, -1, sizeof(is));
is[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> s;
for (int j = 0; j <= x; ++j) {
if (is[j] >= i)
continue;
if (is[j] >= 0) {
for (int k = 1; j + s * k <= x; ++k)
is[j + s * k] = i;
}
}
}
for (int j = x; j >= 0; --j) {
if (is[j] >= 0 && !isprime[j]) {
cout << j << endl;
goto NEXT;
}
}
cout << "NA" << endl;
NEXT:;
}
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
| 1
| 280
| 2
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, b, n) for (int i = b; i < n; i++)
#define RFOR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define LIMIT 1000010
using namespace std;
bool isnotprime[LIMIT] = {0};
bool dp[31][LIMIT] = {0};
int n, x;
int dishes[31];
void erathos() {
CLR(isnotprime);
FOR(i, 2, LIMIT) {
if (!isnotprime[i]) {
for (int j = 2; i * j < LIMIT; j++) {
isnotprime[i * j] = true;
}
}
}
return;
}
int solve() {
int res = 0;
CLR(dp);
FOR(j, 0, n) {
for (int i = dishes[j]; i <= x; i += dishes[j]) {
dp[j][i] = true;
}
if (j > 0)
for (int i = 1; i <= x; i++) {
if ((dp[j - 1][i]) ||
((i - dishes[j] > 0) && dp[j - 1][i - dishes[j]])) {
dp[j][i] = true;
}
}
}
RFOR(i, 0, x + 1) {
if (!isnotprime[i] && dp[n - 1][i]) {
res = i;
break;
}
}
return res;
}
int main() {
erathos();
while (cin >> n >> x, (n || x)) {
FOR(i, 0, n) { cin >> dishes[i]; }
int r = solve();
if (r != 0)
cout << r << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, b, n) for (int i = b; i < n; i++)
#define RFOR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define LIMIT 1000010
using namespace std;
bool isnotprime[LIMIT] = {0};
bool dp[31][LIMIT] = {0};
int n, x;
int dishes[31];
void erathos() {
CLR(isnotprime);
FOR(i, 2, LIMIT) {
if (!isnotprime[i]) {
for (int j = 2; i * j < LIMIT; j++) {
isnotprime[i * j] = true;
}
}
}
return;
}
int solve() {
int res = 0;
CLR(dp);
FOR(j, 0, n) {
for (int i = dishes[j]; i <= x; i += dishes[j]) {
dp[j][i] = true;
}
if (j > 0)
for (int i = 1; i <= x; i++) {
if ((dp[j - 1][i]) || ((i - dishes[j] >= 0) && dp[j][i - dishes[j]])) {
dp[j][i] = true;
}
}
}
RFOR(i, 0, x + 1) {
if (!isnotprime[i] && dp[n - 1][i]) {
res = i;
break;
}
}
return res;
}
int main() {
erathos();
while (cin >> n >> x, (n || x)) {
FOR(i, 0, n) { cin >> dishes[i]; }
int r = solve();
if (r != 0)
cout << r << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
[["-", 12, 23, 0, 16, 31, 23, 0, 16, 17, 47], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 20], ["-", 12, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 69, 28, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 409
| 4
|
#include <cstring>
#include <iostream>
using namespace std;
bool prime[10000001];
bool dp[10000001];
int menu[30];
int n, x;
void make_prime() {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; i < 10000001; i++) {
if (prime[i]) {
for (int j = i + i; j < 10000001; j += i)
prime[j] = false;
}
}
}
int main() {
make_prime();
for (; cin >> n >> x, n;) {
memset(dp, false, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> menu[i];
dp[menu[i]] = true;
}
int ans = -1;
for (int i = 0; i < x; i++) {
if (dp[i])
for (int j = 0; j < n; j++)
if (i + menu[j] < x)
dp[i + menu[j]] = true;
}
for (int i = x; i > 0; i--)
if (prime[i] && dp[i]) {
ans = i;
break;
}
if (ans != -1)
cout << ans << endl;
else
cout << "NA" << endl;
}
}
|
#include <cstring>
#include <iostream>
using namespace std;
bool prime[10000001];
bool dp[10000001];
int menu[30];
int n, x;
void make_prime() {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; i < 10000001; i++) {
if (prime[i]) {
for (int j = i + i; j < 10000001; j += i)
prime[j] = false;
}
}
}
int main() {
make_prime();
for (; cin >> n >> x, n;) {
memset(dp, false, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> menu[i];
dp[menu[i]] = true;
}
int ans = -1;
for (int i = 0; i <= x; i++) {
if (dp[i])
for (int j = 0; j < n; j++)
if (i + menu[j] <= x)
dp[i + menu[j]] = true;
}
for (int i = x; i > 0; i--)
if (prime[i] && dp[i]) {
ans = i;
break;
}
if (ans != -1)
cout << ans << endl;
else
cout << "NA" << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 64, 7, 8, 57, 15, 339, 51, 16, 17, 18], ["+", 64, 7, 8, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 299
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define COUNT(i, n) for (int i = 1; i <= n; i++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for (ITER(c) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
const int N = 1000001;
int main(void) {
vector<bool> isP(N);
fill(ALL(isP), true);
rep(i, 2) isP[i] = false;
for (int i = 2; i * i < N; i++)
if (isP[i])
for (int j = i * i; j < N; j += i)
isP[j] = false;
for (int n, x; cin >> n >> x, n;) {
vector<bool> dp(x + 1);
fill(ALL(dp), false);
dp[0] = true;
while (n--) {
int m;
cin >> m;
rep(i, x) if (dp[i]) dp[i + m] = true;
}
while (~x && !(dp[x] && isP[x]))
x--;
if (~x)
cout << x << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define COUNT(i, n) for (int i = 1; i <= n; i++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for (ITER(c) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
const int N = 1000001;
int main(void) {
vector<bool> isP(N);
fill(ALL(isP), true);
rep(i, 2) isP[i] = false;
for (int i = 2; i * i < N; i++)
if (isP[i])
for (int j = i * i; j < N; j += i)
isP[j] = false;
for (int n, x; cin >> n >> x, n;) {
vector<bool> dp(x + 1);
fill(ALL(dp), false);
dp[0] = true;
while (n--) {
int m;
cin >> m;
rep(i, x - m + 1) if (dp[i]) dp[i + m] = true;
}
while (~x && !(dp[x] && isP[x]))
x--;
if (~x)
cout << x << endl;
else
cout << "NA" << endl;
}
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]]
| 1
| 337
| 4
|
#include <algorithm>
#include <iostream>
#define INF 999999
typedef long long ll;
using namespace std;
int n, a, b, c, maxm, x;
int sum, miniNo, minim;
bool t[1000001];
bool isPrime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return true;
}
int main() {
while (1) {
fill(t, t + 1000001, 0);
cin >> n >> x;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a;
t[a] = true;
for (int j = 2; j + a < 1000001; j++) {
t[j + a] = (t[j] || t[j + a]);
}
}
b = 0;
for (int i = x; i > 1; i--) {
if (isPrime(i) && t[i]) {
cout << i << endl;
b = 1;
break;
}
}
if (b == 0)
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#define INF 999999
typedef long long ll;
using namespace std;
int n, a, b, c, maxm, x;
int sum, miniNo, minim;
bool t[1000001];
bool isPrime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return true;
}
int main() {
while (1) {
fill(t, t + 1000001, 0);
cin >> n >> x;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a;
t[a] = true;
for (int j = 1; j + a < 1000001; j++) {
t[j + a] = (t[j] || t[j + a]);
}
}
b = 0;
for (int i = x; i >= 1; i--) {
if (isPrime(i) && t[i]) {
cout << i << endl;
b = 1;
break;
}
}
if (b == 0)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 20]]
| 1
| 248
| 4
|
#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;
bool dp[1000001];
bool pn[1000001];
void eratos(bool f[]) {
for (int i = 0; i < 1000001; ++i) {
f[i] = true;
}
pn[0] = false;
pn[1] = false;
for (int i = 2; i * i < 1000001; ++i) {
if (f[i]) {
for (int j = 2; i * j < 1000001; ++j) {
f[i * j] = false;
}
}
}
}
int main() {
int n, x;
eratos(pn);
while (cin >> n >> x) {
if (n == 0 && x == 0)
break;
vector<int> cost(n);
for (int i = 0; i <= x; ++i) {
dp[i] = false;
}
for (int i = 0; i < n; ++i) {
cin >> cost[i];
dp[cost[i]] = true;
}
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= x; ++j) {
if (dp[j] && j + cost[i] <= x) {
dp[j + cost[i]] = true;
}
}
}
bool flag = false;
int ans;
for (int i = x; i >= 0; --i) {
if (dp[i] && pn[i]) {
flag = true;
ans = i;
break;
}
}
if (flag) {
cout << ans << "\n";
} else {
cout << "NA\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;
bool dp[1000001];
bool pn[1000001];
void eratos(bool f[]) {
for (int i = 0; i < 1000001; ++i) {
f[i] = true;
}
pn[0] = false;
pn[1] = false;
for (int i = 2; i * i < 1000001; ++i) {
if (f[i]) {
for (int j = 2; i * j < 1000001; ++j) {
f[i * j] = false;
}
}
}
}
int main() {
int n, x;
eratos(pn);
while (cin >> n >> x) {
if (n == 0 && x == 0)
break;
vector<int> cost(n);
for (int i = 0; i <= x; ++i) {
dp[i] = false;
}
for (int i = 0; i < n; ++i) {
cin >> cost[i];
dp[cost[i]] = true;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= x; ++j) {
if (dp[j] && j + cost[i] <= x) {
dp[j + cost[i]] = true;
}
}
}
bool flag = false;
int ans;
for (int i = x; i >= 0; --i) {
if (dp[i] && pn[i]) {
flag = true;
ans = i;
break;
}
}
if (flag) {
cout << ans << "\n";
} else {
cout << "NA\n";
}
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 399
| 2
|
#include <cstring>
#include <iostream>
using namespace std;
const int MAX_N = 1e6 + 1;
bool is_prime[MAX_N + 1];
void SieveOfEratosthenes(int n) {
for (int i = 0; i <= n; ++i)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; ++i)
if (is_prime[i])
for (int j = 2 * i; j <= n; j += i)
is_prime[j] = false;
}
int main() {
int n, x;
SieveOfEratosthenes(1000000);
while (cin >> n >> x, n || x) {
int item[n];
bool flag[x];
memset(flag, 0, sizeof(flag));
for (int i = 0; i < n; ++i)
cin >> item[i];
flag[0] = true;
for (int i = 0; i < n; ++i) {
for (int j = 0; j + item[i] <= x; ++j)
if (flag[j])
flag[j + item[i]] = true;
}
int money = x;
for (; money >= 0; --money)
if (is_prime[money] && flag[money])
break;
if (money > 0)
cout << money << endl;
else
cout << "NA\n";
}
return 0;
}
|
#include <cstring>
#include <iostream>
using namespace std;
const int MAX_N = 1e6 + 10;
bool is_prime[MAX_N + 1];
void SieveOfEratosthenes(int n) {
for (int i = 0; i <= n; ++i)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; ++i)
if (is_prime[i])
for (int j = 2 * i; j <= n; j += i)
is_prime[j] = false;
}
int main() {
int n, x;
SieveOfEratosthenes(1000000);
while (cin >> n >> x, n || x) {
int item[n];
bool flag[x + 1];
memset(flag, 0, sizeof(flag));
for (int i = 0; i < n; ++i)
cin >> item[i];
flag[0] = true;
for (int i = 0; i < n; ++i) {
for (int j = 0; j + item[i] <= x; ++j)
if (flag[j])
flag[j + item[i]] = true;
}
int money = x;
for (; money >= 0; --money)
if (is_prime[money] && flag[money])
break;
if (money > 0)
cout << money << endl;
else
cout << "NA\n";
}
return 0;
}
|
[["-", 0, 30, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 0, 30, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 80, 81, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 80, 81, 16, 12, 13]]
| 1
| 298
| 4
|
#include <cstring>
#include <iostream>
#define MAX 1000000
using namespace std;
int n, x, d[31];
bool p[MAX + 1], dp[MAX + 1];
void isPrime() {
memset(p, 1, sizeof(p));
p[0] = p[1] = false;
for (int i = 2; i * i <= MAX; i++) {
for (int j = i + i; j <= MAX; j += i)
p[j] = false;
}
}
int main() {
isPrime();
while (cin >> n >> x, n || x) {
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++)
cin >> d[i];
dp[0] = true;
for (int i = 0; i <= x; i++) {
if (dp[i]) {
for (int j = 0; j < n; j++) {
if (i + d[i] >= x)
continue;
dp[i + d[j]] = true;
}
}
}
bool ju = true;
for (int i = x; i > 0; i--) {
if (p[i] && dp[i]) {
cout << i << endl;
ju = false;
break;
}
}
if (ju)
cout << "NA" << endl;
}
}
|
#include <cstring>
#include <iostream>
#define MAX 1000000
using namespace std;
int n, x, d[31];
bool p[MAX + 1], dp[MAX + 1];
void isPrime() {
memset(p, 1, sizeof(p));
p[0] = p[1] = false;
for (int i = 2; i * i <= MAX; i++) {
for (int j = i + i; j <= MAX; j += i)
p[j] = false;
}
}
int main() {
isPrime();
while (cin >> n >> x, n || x) {
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++)
cin >> d[i];
dp[0] = true;
for (int i = 0; i <= x; i++) {
if (dp[i]) {
for (int j = 0; j < n; j++) {
if (i + d[j] > x)
continue;
dp[i + d[j]] = true;
}
}
}
bool ju = true;
for (int i = x; i > 0; i--) {
if (p[i] && dp[i]) {
cout << i << endl;
ju = false;
break;
}
}
if (ju)
cout << "NA" << endl;
}
}
|
[["-", 51, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 51, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 297
| 4
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
int mod = 1000000007;
void run() {
for (;;) {
int X = sc.nextInt();
int Y = sc.nextInt();
if ((X | Y) == 0) {
return;
}
int[][] field = new int[Y][X];
int[][] dp = new int[Y][X];
for (int i = 0; i < Y; i++) {
for (int j = 0; j < X; j++) {
field[i][j] = sc.nextInt();
}
}
for (int i = 0; i < X; i++) {
if (field[0][i] == 0) {
dp[0][i] = 1;
}
}
for (int i = 1; i < Y; i++) {
for (int j = 0; j < X; j++) {
int cnt = 0;
if (field[i][j] == 1) {
continue;
}
if (j - 1 >= 0 && field[i][j] != 2 && field[i - 1][j - 1] != 1 &&
field[i - 1][j - 1] != 2) {
cnt += dp[i - 1][j - 1];
}
if (field[i - 1][j] != 2) {
cnt += dp[i - 1][j];
if (i - 2 > 0 && field[i - 2][j] == 2) {
cnt += dp[i - 2][j];
}
}
if (j + 1 < X && field[i][j] != 2 && field[i - 1][j + 1] != 1 &&
field[i - 1][j + 1] != 2) {
cnt += dp[i - 1][j + 1];
}
dp[i][j] = cnt;
}
}
int ans = 0;
for (int i = 0; i < X; i++) {
ans += dp[Y - 1][i];
if (Y - 2 >= 0 && field[Y - 2][i] == 2) {
ans += dp[Y - 2][i];
}
}
System.out.println(ans);
}
}
public static void main(String[] args) { new Main().run(); }
void debug(Object... o) { System.out.println(Arrays.deepToString(o)); }
void debug2(int[][] array) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j]);
}
System.out.println();
}
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() { return Double.parseDouble(next()); }
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char)c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
}
}
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
int mod = 1000000007;
void run() {
for (;;) {
int X = sc.nextInt();
int Y = sc.nextInt();
if ((X | Y) == 0) {
return;
}
int[][] field = new int[Y][X];
int[][] dp = new int[Y][X];
for (int i = 0; i < Y; i++) {
for (int j = 0; j < X; j++) {
field[i][j] = sc.nextInt();
}
}
for (int i = 0; i < X; i++) {
if (field[0][i] == 0) {
dp[0][i] = 1;
}
}
for (int i = 1; i < Y; i++) {
for (int j = 0; j < X; j++) {
int cnt = 0;
if (field[i][j] == 1) {
continue;
}
if (j - 1 >= 0 && field[i][j] != 2 && field[i - 1][j - 1] != 1 &&
field[i - 1][j - 1] != 2) {
cnt += dp[i - 1][j - 1];
}
if (field[i - 1][j] != 2) {
cnt += dp[i - 1][j];
}
if (i - 2 > 0 && field[i - 2][j] == 2) {
cnt += dp[i - 2][j];
}
if (j + 1 < X && field[i][j] != 2 && field[i - 1][j + 1] != 1 &&
field[i - 1][j + 1] != 2) {
cnt += dp[i - 1][j + 1];
}
dp[i][j] = cnt;
}
}
// System.out.println("------");
// debug2(dp);
int ans = 0;
for (int i = 0; i < X; i++) {
ans += dp[Y - 1][i];
if (Y - 2 >= 0 && field[Y - 2][i] == 2) {
ans += dp[Y - 2][i];
}
}
System.out.println(ans);
}
}
public static void main(String[] args) { new Main().run(); }
void debug(Object... o) { System.out.println(Arrays.deepToString(o)); }
void debug2(int[][] array) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j]);
}
System.out.println();
}
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() { return Double.parseDouble(next()); }
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char)c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 878
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w, h;
int map[][];
int cnt[][];
while (true) {
w = sc.nextInt();
h = sc.nextInt();
if ((w | h) == 0) {
break;
}
map = new int[h][w];
cnt = new int[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
map[i][j] = sc.nextInt();
}
}
for (int j = 0; j < w; j++) {
if (map[h - 1][j] == 0) {
cnt[h - 1][j] = 1;
}
}
int sum;
for (int i = h - 2; 0 <= i; i--) {
for (int j = 0; j < w; j++) {
sum = 0;
if (map[i][j] == 0) {
if (j + 1 < w && map[i + 1][j + 1] == 0) {
sum += cnt[i + 1][j + 1];
}
if (0 <= j - 1 && map[i + 1][j - 1] == 0) {
sum += cnt[i + 1][j - 1];
}
if (map[i + 1][j] != 1) {
sum += cnt[i + 1][j];
}
} else if (map[i][j] == 2) {
if (i + 2 < h) {
sum += cnt[i + 2][j];
} else {
sum = 1;
}
}
cnt[i][j] = sum;
}
}
sum = 0;
for (int j = 0; j < w; j++) {
sum += cnt[0][j];
}
System.out.println(sum);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w, h;
int map[][];
int cnt[][];
while (true) {
w = sc.nextInt();
h = sc.nextInt();
if ((w | h) == 0) {
break;
}
map = new int[h][w];
cnt = new int[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
map[i][j] = sc.nextInt();
}
}
for (int j = 0; j < w; j++) {
if (map[h - 1][j] != 1) {
cnt[h - 1][j] = 1;
}
}
int sum;
for (int i = h - 2; 0 <= i; i--) {
for (int j = 0; j < w; j++) {
sum = 0;
if (map[i][j] == 0) {
if (j + 1 < w && map[i + 1][j + 1] == 0) {
sum += cnt[i + 1][j + 1];
}
if (0 <= j - 1 && map[i + 1][j - 1] == 0) {
sum += cnt[i + 1][j - 1];
}
if (map[i + 1][j] != 1) {
sum += cnt[i + 1][j];
}
} else if (map[i][j] == 2) {
if (i + 2 < h) {
sum += cnt[i + 2][j];
} else {
sum = 1;
}
}
cnt[i][j] = sum;
}
}
sum = 0;
for (int j = 0; j < w; j++) {
sum += cnt[0][j];
}
System.out.println(sum);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
| 3
| 454
| 4
|
#include <stdio.h>
unsigned int c;
int n, m;
int X[3] = {-1, 0, 1};
int main() {
int i, j, k;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
int d[15][17] = {{0}};
int p[15][17] = {{0}};
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &d[i][j]);
}
}
for (i = 0; i < n; i++)
if (d[0][i] == 0)
p[0][i] = 1;
for (i = 0; i < m - 1; i++) {
for (j = 0; j < n; j++) { // printf("%5d",p[i][j]);
if (d[i][j] == 0) {
for (k = 0; k < 3; k++) {
if (0 <= j + X[k] && j + X[k] < n) {
if (d[i + 1][j + X[k]] == 0 || (k == 1 && d[i + 1][j] == 2)) {
p[i + 1][j + X[k]] += p[i][j];
}
}
}
} else if (d[i][j] == 2) {
p[i + 2][j] += p[i][j];
}
} // printf("\n");
}
c = 0;
for (; i < m + 1; i++) {
for (j = 0; j < n; j++) {
if (d[i][j] != 1) {
c += p[i][j];
}
}
}
printf("%d\n", c);
}
return 0;
}
|
#include <stdio.h>
unsigned int c;
int n, m;
int X[3] = {-1, 0, 1};
int main() {
int i, j, k;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
int d[17][15] = {{0}};
int p[17][15] = {{0}};
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &d[i][j]);
}
}
for (i = 0; i < n; i++)
if (d[0][i] == 0)
p[0][i] = 1;
for (i = 0; i < m - 1; i++) {
for (j = 0; j < n; j++) { // printf("%5d",p[i][j]);
if (d[i][j] == 0) {
for (k = 0; k < 3; k++) {
if (0 <= j + X[k] && j + X[k] < n) {
if (d[i + 1][j + X[k]] == 0 || (k == 1 && d[i + 1][j] == 2)) {
p[i + 1][j + X[k]] += p[i][j];
}
}
}
} else if (d[i][j] == 2) {
p[i + 2][j] += p[i][j];
}
}
}
c = 0;
for (; i < m + 1; i++) {
for (j = 0; j < n; j++) { // printf("%5d",p[i][j]);
if (d[i][j] != 1) {
c += p[i][j];
}
} // printf("\n");
}
printf("%d\n", c);
}
return 0;
}
|
[["-", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["+", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13]]
| 0
| 430
| 8
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n && n != -1) {
int sum = 3130, num[3] = {125, 140, 160};
for (int i = 0; i < 3; i++) {
n -= 10;
if (n > 10)
sum -= num[i] * 10;
else if (n > 0)
sum -= num[i] * n;
}
cout << sum << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n && n != -1) {
int sum = 3130, num[3] = {125, 140, 160};
for (int i = 0; i < 3; i++) {
n -= 10;
if (n > 10 && i != 2)
sum -= num[i] * 10;
else if (n > 0)
sum -= num[i] * n;
}
cout << sum << endl;
}
}
|
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 102
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n && n != -1) {
int sum = 3130, num[3] = {125, 140, 160};
for (int i = 0, j = n - 10; i < 3; i++, j -= 10) {
if (j > 10 && i != 2)
sum -= num[i] * 10;
else if (j > 0)
sum -= num[i] * n;
}
cout << sum << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n && n != -1) {
int sum = 3130, num[3] = {125, 140, 160};
for (int i = 0, j = n - 10; i < 3; i++, j -= 10) {
if (j > 10 && i != 2)
sum -= num[i] * 10;
else if (j > 0)
sum -= num[i] * j;
}
cout << sum << endl;
}
}
|
[["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22]]
| 1
| 112
| 2
|
#include <cmath>
#include <iostream>
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0216
int calc(int w) {
int sum = 1150;
if (w < 10)
return sum;
sum += min(w - 10, 10) * 125;
if (w < 20)
return sum;
sum += min(w - 20, 10) * 140;
if (w < 30)
return sum;
sum += min(w - 30, 10) * 160;
return sum;
}
int main() {
int w;
while (cin >> w) {
if (w == -1)
break;
cout << (4280 - calc(w)) << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0216
int calc(int w) {
int sum = 1150;
if (w < 10)
return sum;
sum += min(w - 10, 10) * 125;
if (w < 20)
return sum;
sum += min(w - 20, 10) * 140;
if (w < 30)
return sum;
sum += (w - 30) * 160;
return sum;
}
int main() {
int w;
while (cin >> w) {
if (w == -1)
break;
cout << (4280 - calc(w)) << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["-", 0, 11, 12, 16, 31, 2, 3, 4, 0, 21], ["-", 0, 11, 12, 16, 31, 2, 3, 4, 0, 13]]
| 1
| 132
| 3
|
#include <stdio.h>
int main(void) {
int n, w, a;
while (1) {
scanf("%d", &n);
if (n == -1)
break;
w = 1150;
if (n > 30) {
w = w + (n - 30) * 160;
if (n >= 40)
n = 30;
else
n = (n / 10) * 10;
}
if (n > 20) {
w = w + (n - 20) * 140;
if (n == 30)
n = 20;
else
n = (n / 10) * 10;
}
if (n > 10) {
w = w + (n - 10) * 125;
}
a = 4280 - w;
printf("%d %d\n", a, w);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, w, a;
while (1) {
scanf("%d", &n);
if (n == -1)
break;
w = 1150;
if (n > 30) {
w = w + (n - 30) * 160;
if (n >= 40)
n = 30;
else
n = (n / 10) * 10;
}
if (n > 20) {
w = w + (n - 20) * 140;
if (n == 30)
n = 20;
else
n = (n / 10) * 10;
}
if (n > 10) {
w = w + (n - 10) * 125;
}
a = 4280 - w;
printf("%d\n", a);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 167
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int w;
int p = 4280;
void solve() {
int sum = 0;
sum += 1150;
sum += max(0, min(10, w - 10)) * 125;
sum += max(0, min(10, w - 20)) * 140;
sum += max(0, min(10, w - 30)) * 160;
cout << 4280 - sum << endl;
}
int main() {
while (cin >> w) {
if (w == -1)
break;
solve();
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int w;
int p = 4280;
void solve() {
int sum = 0;
sum += 1150;
sum += max(0, min(10, w - 10)) * 125;
sum += max(0, min(10, w - 20)) * 140;
sum += max(0, w - 30) * 160;
cout << 4280 - sum << endl;
}
int main() {
while (cin >> w) {
if (w == -1)
break;
solve();
}
return 0;
}
|
[["-", 12, 16, 31, 2, 3, 4, 0, 2, 63, 22], ["-", 31, 2, 3, 4, 0, 2, 3, 4, 0, 24], ["-", 31, 2, 3, 4, 0, 2, 3, 4, 0, 13], ["-", 31, 2, 3, 4, 0, 2, 3, 4, 0, 21], ["-", 31, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
| 1
| 228
| 5
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int w;
int val = 0;
cin >> w;
if (w == -1)
break;
val = 1150;
int n = 0;
int vs[] = {125, 140, 160};
while (true) {
int t = w - 10 * (n + 1);
if (t < 0)
t = 0;
if (t > 10 && n <= 2)
t = 10;
val += t * vs[n];
++n;
if (n == 3)
break;
}
cout << 4280 - val << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int w;
int val = 0;
cin >> w;
if (w == -1)
break;
val = 1150;
int n = 0;
int vs[] = {125, 140, 160};
while (true) {
int t = w - 10 * (n + 1);
if (t < 0)
t = 0;
if (t > 10 && n <= 1)
t = 10;
val += t * vs[n];
++n;
if (n == 3)
break;
}
cout << 4280 - val << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 134
| 2
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define rp(i, c) rep(i, (c).size())
#define fr(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << #x << " = " << (x) << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
int w;
int calc() {
int ret = 1150;
if (w <= 10)
return ret;
ret += min(10, w - 10) * 125;
if (w <= 20)
return ret;
ret += min(10, w - 20) * 140;
if (w <= 30)
return ret;
ret += min(10, w - 30) * 160;
return ret;
}
int main() {
while (scanf("%d", &w), w >= 0)
printf("%d\n", 4280 - calc());
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define rp(i, c) rep(i, (c).size())
#define fr(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << #x << " = " << (x) << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
int w;
int calc() {
int ret = 1150;
if (w <= 10)
return ret;
ret += min(10, w - 10) * 125;
if (w <= 20)
return ret;
ret += min(10, w - 20) * 140;
if (w <= 30)
return ret;
ret += (w - 30) * 160;
return ret;
}
int main() {
while (scanf("%d", &w), w >= 0)
printf("%d\n", 4280 - calc());
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["-", 0, 11, 12, 16, 31, 2, 3, 4, 0, 13], ["-", 0, 11, 12, 16, 31, 2, 3, 4, 0, 21]]
| 1
| 234
| 3
|
#include <iostream>
using namespace std;
int money(int m) {
int money = 1150;
// if(m==-1)return 0;
if (m <= 10)
return money;
if (m <= 20 && m > 10)
return money + 125 * (m - 10);
if (m <= 30 && m > 20)
return money + 10 * 125 + 140 * (m - 20);
if (m > 30)
return money + 10 * 125 + 10 * 140 + 160 * (m - 30);
}
int main() {
int w;
while (true) {
cin >> w;
if (w == -1)
return 0;
cout << 4280 - money(w);
}
}
|
#include <iostream>
using namespace std;
int money(int m) {
int money = 1150;
if (m <= 10)
return money;
if (m <= 20 && m > 10)
return money + 125 * (m - 10);
if (m <= 30 && m > 20)
return money + 10 * 125 + 140 * (m - 20);
if (m > 30)
return money + 10 * 125 + 10 * 140 + 160 * (m - 30);
}
int main() {
int w;
while (true) {
cin >> w;
if (w == -1)
return 0;
cout << 4280 - money(w) << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 137
| 2
|
#include <cstdio>
int Solve(int w) {
int c = 1150;
if (w > 30) {
c += (w - 30) * 160;
c += 140 * 10;
c += 125 * 10;
} else if (w > 20) {
c += 140 * (w - 20);
c += 125 * 10;
} else if (w > 10) {
c += 125 * (w - 20);
}
return c;
}
int main() {
int self;
// int bf;
while (1) {
scanf("%d", &self);
if (self == -1) {
break;
}
printf("%d\n", 4280 - Solve(self));
}
return 0;
}
|
#include <cstdio>
int Solve(int w) {
int c = 1150;
if (w > 30) {
c += (w - 30) * 160;
c += 140 * 10;
c += 125 * 10;
} else if (w > 20) {
c += 140 * (w - 20);
c += 125 * 10;
} else if (w > 10) {
c += 125 * (w - 10);
}
return c;
}
int main() {
int self;
// int bf;
while (1) {
scanf("%d", &self);
if (self == -1) {
break;
}
printf("%d\n", 4280 - Solve(self));
}
return 0;
}
|
[["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13]]
| 1
| 146
| 2
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
if (a < b)
a = b;
}
template <class T, class C> void chmin(T &a, C b) {
if (b < a)
a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }
int main() {
int w;
while (cin >> w && w + 1) {
int dw[] = {125, 140, 160};
int res = 1150;
w -= 10;
for (int i = 0; 0 < w--; i++)
res += dw[i / 10];
cout << 4280 - res << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
if (a < b)
a = b;
}
template <class T, class C> void chmin(T &a, C b) {
if (b < a)
a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }
int main() {
int w;
while (cin >> w && w + 1) {
int dw[] = {125, 140, 160};
int res = 1150;
w -= 10;
for (int i = 0; 0 < w--; i++)
res += dw[min(i / 10, 2)];
cout << 4280 - res << endl;
}
}
|
[["+", 0, 11, 12, 69, 341, 342, 0, 2, 63, 22], ["+", 12, 69, 341, 342, 0, 2, 3, 4, 0, 24], ["+", 12, 69, 341, 342, 0, 2, 3, 4, 0, 21], ["+", 12, 69, 341, 342, 0, 2, 3, 4, 0, 13], ["+", 12, 69, 341, 342, 0, 2, 3, 4, 0, 25]]
| 1
| 303
| 5
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int w;
cin >> w;
if (w == -1)
break;
int x = 0, y = 0;
if (w >= 0 && w < 10)
y = 1150;
else if (w >= 10 && w < 20) {
x = w - 10;
y = 1150 + 125 * x;
} else if (w >= 20 && w < 30) {
x = w - 20;
y = 1150 + 125 * 10 + 140 * x;
} else if (w >= 30) {
x = w - 30;
y = 1150 + 125 * 10 + 140 * x + 160 * x;
}
cout << (4280 - y) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int w;
cin >> w;
if (w == -1)
break;
int x = 0, y = 0;
if (w >= 0 && w < 10)
y = 1150;
else if (w >= 10 && w < 20) {
x = w - 10;
y = 1150 + 125 * x;
} else if (w >= 20 && w < 30) {
x = w - 20;
y = 1150 + 125 * 10 + 140 * x;
} else if (w >= 30) {
x = w - 30;
y = 1150 + 125 * 10 + 140 * 10 + 160 * x;
}
cout << (4280 - y) << endl;
}
return 0;
}
|
[["-", 0, 11, 12, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 158
| 2
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, b, n) for (int i = b; i < n; i++)
#define RFOR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
using namespace std;
typedef pair<int, int> paii;
typedef long long ll;
int main() {
int w;
while (cin >> w, w >= 0) {
int res = 1150;
if (w > 10)
res += min(1250, (w - 10) * 125);
if (w > 20)
res += min(1400, (w - 20) * 140);
if (w > 30)
res += min(1600, (w - 30) * 160);
cout << 4280 - res << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, b, n) for (int i = b; i < n; i++)
#define RFOR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
using namespace std;
typedef pair<int, int> paii;
typedef long long ll;
int main() {
int w;
while (cin >> w, w >= 0) {
int res = 1150;
if (w > 10)
res += min(1250, (w - 10) * 125);
if (w > 20)
res += min(1400, (w - 20) * 140);
if (w > 30)
res += (w - 30) * 160;
cout << 4280 - res << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 1, 0, 11, 12, 2, 63, 22], ["-", 64, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["-", 64, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["-", 12, 2, 3, 4, 0, 16, 31, 23, 0, 24], ["-", 64, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
| 1
| 186
| 5
|
#include <iostream>
using namespace std;
int main() {
int w;
while (cin >> w, w != -1) {
int fee = 1150;
for (int i = 11; i <= 20 && i <= w; i++)
fee += 125;
for (int i = 21; i <= 30 && i <= w; i++)
fee += 140;
for (int i = 31; i < w; i++)
fee += 160;
cout << 4280 - fee << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int w;
while (cin >> w, w != -1) {
int fee = 1150;
for (int i = 11; i <= 20 && i <= w; i++)
fee += 125;
for (int i = 21; i <= 30 && i <= w; i++)
fee += 140;
for (int i = 31; i <= w; i++)
fee += 160;
cout << 4280 - fee << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 102
| 2
|
import java.util.*;
public class Main {
public static void main(String[] a) {
Scanner sc = new Scanner(System.in);
for (;;) {
int n = sc.nextInt();
if (n == 0) {
break;
}
int[] p = new int[n];
int[] d = new int[n];
int max = 0;
int res = 0;
for (int i = 0; i < n; i++) {
p[i] = sc.nextInt();
d[i] = sc.nextInt() + sc.nextInt();
if (max < d[i]) {
max = d[i];
res = p[i];
}
}
System.out.println(res);
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] a) {
Scanner sc = new Scanner(System.in);
for (;;) {
int n = sc.nextInt();
if (n == 0) {
break;
}
int[] p = new int[n];
int[] d = new int[n];
int max = 0;
int res = 0;
for (int i = 0; i < n; i++) {
p[i] = sc.nextInt();
d[i] = sc.nextInt() + sc.nextInt();
if (max < d[i]) {
max = d[i];
res = p[i];
}
}
System.out.println(res + " " + max);
}
}
}
|
[["+", 0, 492, 3, 4, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 16, 31, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 16, 31, 16, 12, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 12, 22]]
| 3
| 171
| 6
|
#include <stdio.h>
int p[10000], d[10000];
int main(void) {
int n, i, j, d1, d2, T, max = 0, maxn;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d", &p[i], &d1, &d2);
d[i] = d1 + d2;
}
for (i = 0; i < n; i++) {
if (max < d[i]) {
max = d[i];
maxn = p[i];
}
}
printf("%d %d\n", maxn, max);
}
return 0;
}
|
#include <stdio.h>
int p[10000], d[10000];
int main(void) {
int n, i, j, d1, d2, T, max = 0, maxn;
while (1) {
max = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d", &p[i], &d1, &d2);
d[i] = d1 + d2;
}
for (i = 0; i < n; i++) {
if (max < d[i]) {
max = d[i];
maxn = p[i];
}
}
printf("%d %d\n", maxn, max);
}
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
| 161
| 4
|
#include <stdio.h>
int main(void) {
int n, i, p, k, j, gokei, big = 0, b;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 1; i < n + 1; i++) {
scanf("%d %d %d", &p, &k, &j);
gokei = k + j;
if (big < gokei) {
b = p;
big = gokei;
}
}
printf("%d %d\n", b, big);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, i, p, k, j, gokei, big = 0, b;
while (1) {
scanf("%d", &n);
big = 0;
if (n == 0) {
break;
}
for (i = 1; i < n + 1; i++) {
scanf("%d %d %d", &p, &k, &j);
gokei = k + j;
if (big < gokei) {
b = p;
big = gokei;
}
}
printf("%d %d\n", b, big);
}
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
| 124
| 4
|
#include <stdio.h>
int main(void) {
int n, p, am, pm, i, ban, gou, mos = 0;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d", &p, &am, &pm);
gou = am + pm;
if (mos < gou) {
mos = gou;
ban = p;
}
}
printf("%d %d\n", ban, mos);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, p, am, pm, i, ban, gou, mos = 0;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d %d %d", &p, &am, &pm);
gou = am + pm;
if (mos < gou) {
mos = gou;
ban = p;
}
}
printf("%d %d\n", ban, mos);
mos = 0;
}
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
| 120
| 4
|
m;
main(n, p, d, e, b) {
for (;;) {
scanf("%d", &n);
if (!n)
exit(0);
for (; n--;) {
scanf("%d%d%d", &p, &d, &e);
if (m < d + e)
m = d + e, b = p;
}
printf("%d %d\n", b, m);
}
}
|
m;
main(n, p, d, e, b) {
for (;;) {
m = scanf("%d", &n);
if (!n)
exit(0);
for (; n--;) {
scanf("%d%d%d", &p, &d, &e);
if (m < d + e)
m = d + e, b = p;
}
printf("%d %d\n", b, m);
}
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32]]
| 0
| 99
| 2
|
n, p, a, m, c;
main(b) {
for (; scanf("%d", &n) * n; printf("%d %d\n", m, c))
for (m = 0; n--; a + b > c ? c = a + b, m = p : 0)
scanf("%d%d%d", &p, &a, &b);
}
|
n, p, a, m, c;
main(b) {
for (; c = -scanf("%d", &n) * n; printf("%d %d\n", m, c))
for (; n--; a + b > c ? c = a + b, m = p : 0)
scanf("%d%d%d", &p, &a, &b);
}
|
[["+", 0, 14, 8, 9, 0, 7, 15, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 11, 17, 32], ["+", 0, 7, 15, 11, 12, 16, 31, 91, 17, 33], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 31, 22], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 17, 32], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 12, 13]]
| 0
| 86
| 7
|
n, p, a, m, c;
main(b) {
for (; scanf("%d", &n) * n; printf("%d %d\n", m, c))
for (m = 0; n--; a + b > c ? c = a + b, m = p : 0)
scanf("%d%d%d", &p, &a, &b);
}
|
n, p, a, m, c;
main(b) {
for (; c = scanf("%d", &n), n; printf("%d %d\n", m, c))
for (; n--; a + b > c ? c = a + b, m = p : 0)
scanf("%d%d%d", &p, &a, &b);
}
|
[["+", 8, 9, 0, 7, 15, 34, 31, 11, 31, 22], ["+", 8, 9, 0, 7, 15, 34, 31, 11, 17, 32], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 48], ["+", 0, 14, 8, 9, 0, 7, 15, 34, 0, 21], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 31, 22], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 17, 32], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 12, 13]]
| 0
| 86
| 7
|
#include <stdio.h>
int main() {
int i, a, b, c, d, max = 0, s = 0;
scanf("%d", &a);
while (a != 0) {
s = 0;
for (i = 0; i < a; i++) {
scanf("%d %d %d", &b, &c, &d);
c = c + d;
if (max < c) {
max = c;
s = b;
}
}
printf("%d %d\n", s, max);
scanf("%d", &a);
}
return 0;
}
|
#include <stdio.h>
int main() {
int i, a, b, c, d, max = 0, s = 0;
scanf("%d", &a);
while (a != 0) {
s = 0;
max = 0;
for (i = 0; i < a; i++) {
scanf("%d %d %d", &b, &c, &d);
c = c + d;
if (max < c) {
max = c;
s = b;
}
}
printf("%d %d\n", s, max);
scanf("%d", &a);
}
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
| 127
| 4
|
#include <stdio.h>
typedef struct {
int nam;
int dis;
} set;
int main() {
int n, i, way1, way2, top = 0, rancer;
while (scanf("%d", &n)) {
if (n == 0) {
break;
}
set mem[10000];
for (i = 0; i < n; i++) {
mem[i].dis = 0;
}
for (i = 0; i < n; i++) {
scanf("%d %d %d", &mem[i].nam, &way1, &way2);
mem[i].dis += way1 + way2;
}
for (i = 0; i < n; i++) {
if (mem[i].dis > top) {
top = mem[i].dis;
rancer = mem[i].nam;
}
}
printf("%d %d", rancer, top);
top = 0;
}
return 0;
}
|
#include <stdio.h>
typedef struct {
int nam;
int dis;
} set;
int main() {
int n, i, way1, way2, top = 0, rancer;
while (scanf("%d", &n)) {
if (n == 0) {
break;
}
set mem[10000];
for (i = 0; i < n; i++) {
mem[i].dis = 0;
}
for (i = 0; i < n; i++) {
scanf("%d %d %d", &mem[i].nam, &way1, &way2);
mem[i].dis += way1 + way2;
}
for (i = 0; i < n; i++) {
if (mem[i].dis > top) {
top = mem[i].dis;
rancer = mem[i].nam;
}
}
printf("%d %d\n", rancer, top);
top = 0;
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 200
| 1
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef struct {
int num;
int first;
int second;
} Walk;
int main() {
int n, max = -1, add;
Walk people[10005];
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &people[i].num, &people[i].first, &people[i].second);
if (max < people[i].first + people[i].second) {
max = people[i].first + people[i].second;
add = i;
}
}
printf("%d %d\n", people[add].num, max);
add = 0;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef struct {
int num;
int first;
int second;
} Walk;
int main() {
int n, max = -1, add;
Walk people[10005];
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &people[i].num, &people[i].first, &people[i].second);
if (max < people[i].first + people[i].second) {
max = people[i].first + people[i].second;
add = i;
}
}
printf("%d %d\n", people[add].num, max);
add = 0;
max = -1;
}
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]]
| 1
| 191
| 4
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
typedef unsigned long long UInt64;
typedef long long Int64;
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
void solve(int n) {
vector<P> vec;
rep(i, n) {
int p, d1, d2;
cin >> p >> d1 >> d2;
vec.pb(P(d1 + d2, p));
}
sort(all(vec), greater<P>());
vector<P>::iterator it = vec.begin();
cout << it->fr << " " << it->sc << endl;
}
int main() {
int n;
while (cin >> n) {
if (n == 0)
return 0;
solve(n);
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
typedef unsigned long long UInt64;
typedef long long Int64;
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
void solve(int n) {
vector<P> vec;
rep(i, n) {
int p, d1, d2;
cin >> p >> d1 >> d2;
vec.pb(P(d1 + d2, p));
}
sort(all(vec), greater<P>());
vector<P>::iterator it = vec.begin();
cout << it->sc << " " << it->fr << endl;
}
int main() {
int n;
while (cin >> n) {
if (n == 0)
return 0;
solve(n);
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 118, 119, 120], ["+", 31, 16, 31, 16, 31, 16, 12, 118, 119, 120], ["-", 0, 1, 0, 16, 31, 16, 12, 118, 119, 120], ["+", 0, 1, 0, 16, 31, 16, 12, 118, 119, 120]]
| 1
| 262
| 4
|
#include <iostream>
using namespace std;
int main(void) {
int n, p, d1, d2;
int ans1, ans2;
while (1) {
cin >> n;
if (n == 0) {
break;
}
ans1 = -1, ans2 = -1;
for (int i = 0; i < n; i++) {
cin >> p >> d1 >> d2;
if (ans2 < d1 + d2) {
ans1 = p;
ans2 = d1 + d2;
}
}
cout << ans1 << ans2 << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
int n, p, d1, d2;
int ans1, ans2;
while (1) {
cin >> n;
if (n == 0) {
break;
}
ans1 = -1, ans2 = -1;
for (int i = 0; i < n; i++) {
cin >> p >> d1 >> d2;
if (ans2 < d1 + d2) {
ans1 = p;
ans2 = d1 + d2;
}
}
cout << ans1 << " " << ans2 << endl;
}
return 0;
}
|
[["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
| 1
| 110
| 4
|
#include <stdio.h>
int main(void) {
int i, n, p, d1, d2, ps, d, max;
max = -1;
scanf("%d", &n);
while (!(n == 0)) {
p = 0;
d1 = 0;
d2 = 0;
for (i = 1; i <= n; i++) {
scanf("%d %d %d", &p, &d1, &d2);
d = d1 + d2;
if (max < d) {
max = d;
ps = p;
}
}
printf("%d %d\n", ps, max);
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, n, p, d1, d2, ps, d, max;
max = -1;
scanf("%d", &n);
while (!(n == 0)) {
p = 0;
d1 = 0;
d2 = 0;
max = -1;
for (i = 1; i <= n; i++) {
scanf("%d %d %d", &p, &d1, &d2);
d = d1 + d2;
if (max < d) {
max = d;
ps = p;
}
}
printf("%d %d\n", ps, max);
scanf("%d", &n);
}
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]]
| 1
| 141
| 4
|
M[15][15], C[15][15], X, Y;
int D(x, y) {
if (y >= Y - 1)
return 1;
if (M[x][y])
return M[x][y];
if (C[x][y] == 2)
return M[x][y] = y + 2 >= Y || C[x][y + 2] != -1 ? D(x, y + 2) : 0;
int s = 0;
if (0 < x && C[x - 1][y + 1] == 0)
s += D(x - 1, y + 1);
if (C[x][y + 1] != 1)
s += D(x, y + 1);
if (x < X - 1 && C[x + 1][y + 1] == 0)
s += D(x + 1, y + 1);
return M[x][y] = s;
}
main(i, j, s) {
for (; scanf("%d%d", &X, &Y), X; printf("%d\n", j)) {
memset(M, 0, sizeof(M));
for (j = 0; j < Y; j++)
for (i = 0; i < X; i++)
scanf("%d", C[i] + j);
for (j = i = 0; i < X; i++)
if (C[i][0] != 1)
j += D(i, 0);
}
exit(0);
}
|
M[15][15], C[15][15], X, Y;
int D(x, y) {
if (y >= Y - 1)
return 1;
if (M[x][y])
return M[x][y];
if (C[x][y] == 2)
return M[x][y] = y + 2 >= Y || C[x][y + 2] != 1 ? D(x, y + 2) : 0;
int s = 0;
if (0 < x && C[x - 1][y + 1] == 0)
s += D(x - 1, y + 1);
if (C[x][y + 1] != 1)
s += D(x, y + 1);
if (x < X - 1 && C[x + 1][y + 1] == 0)
s += D(x + 1, y + 1);
return M[x][y] = s;
}
main(i, j, s) {
for (; scanf("%d%d", &X, &Y), X; printf("%d\n", j)) {
memset(M, 0, sizeof(M));
for (j = 0; j < Y; j++)
for (i = 0; i < X; i++)
scanf("%d", C[i] + j);
for (j = i = 0; i < X; i++)
if (C[i][0] != 1)
j += D(i, 0);
}
exit(0);
}
|
[["-", 0, 11, 12, 41, 15, 16, 12, 16, 12, 13], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 12, 13]]
| 0
| 352
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int W, H, mas[16][16];
while (cin >> W >> H, W) {
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> mas[i][j];
}
}
vector<vector<int>> dp(H + 1, vector<int>(W, 0));
for (int i = 0; i < W; i++) {
if (mas[0][i] != 1)
dp[0][i] = 1;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (dp[i][j] == 0)
continue;
if (mas[i][j] == 0) {
for (int k = -1; k <= 1; k++) {
if (j + k < 0 || j + k >= W)
continue;
if ((i == H - 1 && k == 0) ||
(i != H - 1 && k == 0 && mas[i + 1][j + k] == 2) ||
(i != H - 1 && mas[i + 1][j + k] == 0)) {
dp[i + 1][j + k] += dp[i][j];
}
}
} else if (mas[i][j] == 2) {
if (i >= H - 2 || mas[i + 2][j] != 1) {
dp[max(H, i + 2)][j] += dp[i][j];
}
}
}
}
int ret = 0;
for (int i = 0; i < W; i++) {
ret += dp[H][i];
}
cout << ret << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int W, H, mas[16][16];
while (cin >> W >> H, W) {
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> mas[i][j];
}
}
vector<vector<int>> dp(H + 1, vector<int>(W, 0));
for (int i = 0; i < W; i++) {
if (mas[0][i] != 1)
dp[0][i] = 1;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (dp[i][j] == 0)
continue;
if (mas[i][j] == 0) {
for (int k = -1; k <= 1; k++) {
if (j + k < 0 || j + k >= W)
continue;
if ((i == H - 1 && k == 0) ||
(i != H - 1 && k == 0 && mas[i + 1][j + k] == 2) ||
(i != H - 1 && mas[i + 1][j + k] == 0)) {
dp[i + 1][j + k] += dp[i][j];
}
}
} else if (mas[i][j] == 2) {
if (i >= H - 2 || mas[i + 2][j] != 1) {
dp[min(H, i + 2)][j] += dp[i][j];
}
}
}
}
int ret = 0;
for (int i = 0; i < W; i++) {
ret += dp[H][i];
}
cout << ret << endl;
}
}
|
[["-", 31, 69, 28, 69, 341, 342, 0, 2, 63, 22], ["+", 31, 69, 28, 69, 341, 342, 0, 2, 63, 22]]
| 1
| 414
| 2
|
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int W, H;
while (cin >> W >> H, W) {
int b[15][20] = {0};
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> b[i][j];
}
}
int dp[15][20] = {0};
for (int i = 0; i < W; i++) {
if (b[0][i] != 1)
dp[0][i] = 1;
}
for (int i = 0; i < H - 1; i++) {
for (int j = 0; j < W; j++) {
if (b[i][j] == 0) {
for (int d = -1; d <= 1; d++) {
if (j + d < 0 || W <= j + d)
continue;
if (b[i + 1][j + d] == 0 || b[i + 1][j + d] == 2 && d == 0)
dp[i + 1][j + d] += dp[i][j];
}
} else if (b[i][j] == 2) {
dp[i + 2][j] += dp[i][j];
}
}
}
int ans = 0;
for (int i = H - 1; i <= H; i++) {
for (int j = 0; j < W; j++) {
if (b[i][j] != 1)
ans += dp[i][j];
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int W, H;
while (cin >> W >> H, W) {
int b[20][15] = {0};
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> b[i][j];
}
}
int dp[20][15] = {0};
for (int i = 0; i < W; i++) {
if (b[0][i] != 1)
dp[0][i] = 1;
}
for (int i = 0; i < H - 1; i++) {
for (int j = 0; j < W; j++) {
if (b[i][j] == 0) {
for (int d = -1; d <= 1; d++) {
if (j + d < 0 || W <= j + d)
continue;
if (b[i + 1][j + d] == 0 || b[i + 1][j + d] == 2 && d == 0)
dp[i + 1][j + d] += dp[i][j];
}
} else if (b[i][j] == 2) {
dp[i + 2][j] += dp[i][j];
}
}
}
int ans = 0;
for (int i = H - 1; i <= H; i++) {
for (int j = 0; j < W; j++) {
if (b[i][j] != 1)
ans += dp[i][j];
}
}
cout << ans << endl;
}
}
|
[["-", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["+", 0, 43, 49, 50, 49, 80, 49, 80, 81, 13], ["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13]]
| 1
| 393
| 8
|
#include <iostream>
using namespace std;
int main() {
int x, y;
while (cin >> x >> y, x * y) { //
int skimap[15][15] = {}; // x = j y = i
int dp[15][15] = {}; // x = j y = i
int flyover = 0; //??´????£??????????????????????
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) {
cin >> skimap[i][j];
}
}
for (int i = 0; i < x; i++) {
if (skimap[0][i] == 0)
dp[0][i] = 1;
}
for (int i = 0; i < y - 1; i++) {
for (int j = 0; j < x; j++) {
if (skimap[i][j] == 0) {
if (j - 1 >= 0) {
if (skimap[i + 1][j - 1] == 0) {
dp[i + 1][j - 1] += dp[i][j];
}
}
if (skimap[i + 1][j] != 1)
dp[i + 1][j] += dp[i][j];
if (j + 1 < x) {
if (skimap[i + 1][j + 1] == 0) {
dp[i + 1][j + 1] += dp[i][j];
}
}
} else if (skimap[i][j] == 1) {
continue;
} else {
if (i + 2 < y && skimap[i + 2][j] != 1) {
dp[i + 2][j] = dp[i][j];
} else {
flyover += dp[i][j];
}
}
}
}
int sum = flyover;
for (int i = 0; i < x; i++) {
sum += dp[y - 1][i];
}
cout << sum << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int x, y;
while (cin >> x >> y, x * y) { //
int skimap[15][15] = {}; // x = j y = i
int dp[15][15] = {}; // x = j y = i
int flyover = 0; //??´????£??????????????????????
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) {
cin >> skimap[i][j];
}
}
for (int i = 0; i < x; i++) {
if (skimap[0][i] == 0)
dp[0][i] = 1;
}
for (int i = 0; i < y - 1; i++) {
for (int j = 0; j < x; j++) {
if (skimap[i][j] == 0) {
if (j - 1 >= 0) {
if (skimap[i + 1][j - 1] == 0) {
dp[i + 1][j - 1] += dp[i][j];
}
}
if (skimap[i + 1][j] != 1)
dp[i + 1][j] += dp[i][j];
if (j + 1 < x) {
if (skimap[i + 1][j + 1] == 0) {
dp[i + 1][j + 1] += dp[i][j];
}
}
} else if (skimap[i][j] == 1) {
continue;
} else {
if (i + 2 < y) {
if (skimap[i + 2][j] != 1)
dp[i + 2][j] = dp[i][j];
} else {
flyover += dp[i][j];
}
}
}
}
int sum = flyover;
for (int i = 0; i < x; i++) {
sum += dp[y - 1][i];
}
cout << sum << endl;
}
return 0;
}
|
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 75, 76, 0, 9, 0, 57, 15, 339, 0, 25], ["+", 75, 76, 0, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["-", 75, 76, 0, 9, 0, 57, 64, 9, 0, 45]]
| 1
| 435
| 6
|
/* {{{ Shinobu kawaii */
/*
______ __ _ __
.' ____ \ [ | (_) [ |
| (___ \_| | |--. __ _ .--. .--. | |.--. __ _
_.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | |
| \____) | | | | | | | | | | || \__. || \__/ | | \_/ |,
\______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/
*/
// clang-format off
/* }}} */
#include <bits/stdc++.h>
using namespace std;
// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
/* cpp template {{{ */
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()
/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* func */
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; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */
int w, h;
int field[20][20];
int memo[20][20];
ll dfs(int y, int x, int yy = -1, int xx = -1) {
if (!inside(y, x, INF, w))
return 0;
if (field[y][x] == 1)
return 0;
if (y >= h - 1)
return 1;
if (y == h - 1 && field[y][x] == 0)
return 1;
if (field[y][x] == 2 && x != xx)
return 0;
if (memo[y][x] != -1)
return memo[y][x];
ll res;
if (field[y][x] == 2) {
res = dfs(y + 2, x, y, x);
} else {
res =
dfs(y + 1, x, y, x) + dfs(y + 1, x + 1, y, x) + dfs(y + 1, x - 1, y, x);
}
return memo[y][x] = res;
}
signed main() {
while (cin >> w >> h, w || h) {
memset(field, -1, sizeof(field));
memset(memo, -1, sizeof(memo));
REP(i, h) REP(j, w) field[i][j] = in();
ll ans = 0;
REP(i, w) { ans += dfs(0, i); }
print(ans);
}
return 0;
}
|
/* {{{ Shinobu kawaii */
/*
______ __ _ __
.' ____ \ [ | (_) [ |
| (___ \_| | |--. __ _ .--. .--. | |.--. __ _
_.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | |
| \____) | | | | | | | | | | || \__. || \__/ | | \_/ |,
\______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/
*/
// clang-format off
/* }}} */
#include <bits/stdc++.h>
using namespace std;
// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
/* cpp template {{{ */
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()
/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* func */
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; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */
int w, h;
int field[20][20];
int memo[20][20];
ll dfs(int y, int x, int yy = -1, int xx = -1) {
if (!inside(y, x, INF, w))
return 0;
if (field[y][x] == 1)
return 0;
if (y > h - 1)
return 1;
if (y == h - 1 && field[y][x] == 0)
return 1;
if (field[y][x] == 2 && x != xx)
return 0;
if (memo[y][x] != -1)
return memo[y][x];
ll res;
if (field[y][x] == 2) {
res = dfs(y + 2, x, y, x);
} else {
res =
dfs(y + 1, x, y, x) + dfs(y + 1, x + 1, y, x) + dfs(y + 1, x - 1, y, x);
}
return memo[y][x] = res;
}
signed main() {
while (cin >> w >> h, w || h) {
memset(field, -1, sizeof(field));
memset(memo, -1, sizeof(memo));
REP(i, h) REP(j, w) field[i][j] = in();
ll ans = 0;
REP(i, w) { ans += dfs(0, i); }
print(ans);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 958
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int H, W;
int maps[15][15];
ll dp[15][15];
int dx[3] = {1, 0, -1}, dy[3] = {1, 1, 1};
int main() {
while (cin >> W >> H, H || W) {
REP(i, H) REP(j, W) scanf("%d", &maps[i][j]);
memset(dp, 0, sizeof(dp));
REP(j, W) dp[0][j] = maps[0][j] != 1;
REP(i, H) REP(j, W) if (dp[i][j]) {
if (maps[i][j] == 2) { // jump
if (i + 2 < H && maps[i + 2][j] == 1)
continue;
dp[min(i + 2, H - 1)][j] += dp[i][j];
} else { // normal
REP(k, 3) {
int yy = i + dy[k], xx = j + dx[k];
if (!(yy >= 0 && yy < H && xx >= 0 && xx < W))
continue;
if (maps[yy][xx] == 1 || (k != 1 && maps[yy][xx] == 2))
continue;
dp[yy][xx] += dp[i][j];
}
}
}
ll ans = 0;
REP(j, W) ans += dp[H - 1][j];
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int H, W;
int maps[15][15];
ll dp[15][15];
int dx[3] = {1, 0, -1}, dy[3] = {1, 1, 1};
int main() {
while (cin >> W >> H, H || W) {
REP(i, H) REP(j, W) scanf("%d", &maps[i][j]);
memset(dp, 0, sizeof(dp));
REP(j, W) dp[0][j] = maps[0][j] != 1;
REP(i, H - 1) REP(j, W) if (dp[i][j]) {
if (maps[i][j] == 2) { // jump
if (i + 2 < H && maps[i + 2][j] == 1)
continue;
dp[min(i + 2, H - 1)][j] += dp[i][j];
} else { // normal
REP(k, 3) {
int yy = i + dy[k], xx = j + dx[k];
if (!(yy >= 0 && yy < H && xx >= 0 && xx < W))
continue;
if (maps[yy][xx] == 1 || (k != 1 && maps[yy][xx] == 2))
continue;
dp[yy][xx] += dp[i][j];
}
}
}
ll ans = 0;
REP(j, W) ans += dp[H - 1][j];
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 520
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.