buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
#include <stdio.h>
int main(void) {
int n, m, max;
int a[1001];
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = -1;
for (int i = 0; i < n - 1; i++) {
for (int j = i; j < n; j++) {
if (max < a[i] + a[j] && a[i] + a[j] <= m) {
max = a[i] + a[j];
}
}
}
if (max == -1)
printf("NONE\n");
else
printf("%d\n", max);
} // endwhile
}
|
#include <stdio.h>
int main(void) {
int n, m, max;
int a[1001];
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = -1;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (max < a[i] + a[j] && a[i] + a[j] <= m) {
max = a[i] + a[j];
}
}
}
if (max == -1)
printf("NONE\n");
else
printf("%d\n", max);
} // endwhile
}
|
[["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
| 0
| 186
|
#include <stdio.h>
int main() {
int n, m, a[1000];
int i, j, sum, max;
while (scanf("%d %d", &n, &m)) {
if (n == 0 && m == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
sum = a[i] + a[j];
if (sum <= m)
max = sum;
}
}
if (max == 0)
printf("NONE\n");
else
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, m, a[1000];
int i, j, sum, max;
while (scanf("%d %d", &n, &m)) {
if (n == 0 && m == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
sum = a[i] + a[j];
if (max < sum && sum <= m)
max = sum;
}
}
if (max == 0)
printf("NONE\n");
else
printf("%d\n", max);
}
return 0;
}
|
[["+", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98]]
| 0
| 170
|
#include <stdio.h>
int main(void) {
int m, n, a[1001], i, j, sum, max;
while (scanf("%d %d", &n, &m)) {
if (m == 0 && n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
sum = a[i] + a[j];
if (sum <= m)
max = sum;
}
}
if (max == 0)
printf("NONE\n");
else
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int m, n, a[1001], i, j, sum, max;
while (scanf("%d %d", &n, &m)) {
if (m == 0 && n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
sum = a[i] + a[j];
if (sum > max && sum <= m)
max = sum;
}
}
if (max == 0)
printf("NONE\n");
else
printf("%d\n", max);
}
return 0;
}
|
[["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22]]
| 0
| 170
|
#include <stdio.h>
int main(void) {
int a[1000000];
int n, m;
int i, j, k;
int max = 0;
int sum = 0;
scanf("%d %d", &n, &m);
while (n != 0) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i <= n; i++) {
for (j = i + 1; j <= n; j++) {
sum = a[i] + a[j];
if (sum > max && sum <= m) {
max = sum;
}
}
}
if (max == 0) {
printf("NONE\n");
} else {
printf("%d\n", max);
}
max = 0;
scanf("%d %d", &n, &m);
}
}
|
#include <stdio.h>
int main(void) {
int a[1000000];
int n, m;
int i, j, k;
int max = 0;
int sum = 0;
scanf("%d %d", &n, &m);
while (n != 0) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
sum = a[i] + a[j];
if (sum > max && sum <= m) {
max = sum;
}
}
}
if (max == 0) {
printf("NONE\n");
} else {
printf("%d\n", max);
}
max = 0;
scanf("%d %d", &n, &m);
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18]]
| 0
| 192
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int N, M;
while (cin >> N >> M, N) {
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
int ans = -1;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (i == j)
continue;
if (a[i] + a[j] <= M)
ans = max(ans, a[i] + a[j]);
}
}
if (ans == -1)
puts("NONE");
else
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int N, M;
while (cin >> N >> M, N) {
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
int ans = -1;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (i == j)
continue;
if (a[i] + a[j] <= M)
ans = max(ans, a[i] + a[j]);
}
}
if (ans == -1)
cout << "NONE" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["-", 0, 57, 64, 1, 0, 2, 3, 4, 0, 24], ["+", 0, 57, 64, 1, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 16, 31, 16, 17, 151], ["-", 0, 57, 64, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 188
|
// warm heart, wagging tail,and a smile just for you!
// ███████████
// ███╬╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬████╬╬╬╬╬╬███
// ███████████
// ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
// █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
// ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
// ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
// ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
// █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ██████████████
// ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
// ███████ █████
// ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
while (cin >> n >> m, n) {
vector<int> a(n);
REP(i, n) cin >> a[i];
int ans = -1;
REP(i, n) REP(j, n) {
if (i != j && a[i] + a[j] <= m)
ans = max(ans, a[i] + a[j]);
}
if (ans != -1)
cout << ans << endl;
else
cout << "None" << endl;
}
return 0;
}
|
// warm heart, wagging tail,and a smile just for you!
// ███████████
// ███╬╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬████╬╬╬╬╬╬███
// ███████████
// ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
// █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
// ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
// ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
// ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
// █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ██████████████
// ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
// ███████ █████
// ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
while (cin >> n >> m, n) {
vector<int> a(n);
REP(i, n) cin >> a[i];
int ans = -1;
REP(i, n) REP(j, n) {
if (i != j && a[i] + a[j] <= m)
ans = max(ans, a[i] + a[j]);
}
if (ans != -1)
cout << ans << endl;
else
cout << "NONE" << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 304
|
#include <iostream>
using namespace std;
int main(void) {
while (1) {
int n, m;
cin >> n;
cin >> m;
if (n == 0 && m == 0) {
return 0;
}
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
sum[i][j] = a[i] + a[j];
} else {
sum[i][j] = -1000;
}
}
}
int max = -1000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (sum[i][j] > max && sum[i][j] < m) {
max = sum[i][j];
}
}
}
if (max == -1000) {
cout << "NONE" << endl;
} else {
cout << max << endl;
}
}
}
|
#include <iostream>
using namespace std;
int main(void) {
while (1) {
int n, m;
cin >> n;
cin >> m;
if (n == 0 && m == 0) {
return 0;
}
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
sum[i][j] = a[i] + a[j];
} else {
sum[i][j] = -1000;
}
}
}
int max = -1000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (sum[i][j] > max && sum[i][j] <= m) {
max = sum[i][j];
}
}
}
if (max == -1000) {
cout << "NONE" << endl;
} else {
cout << max << endl;
}
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 252
|
#include <stdio.h>
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
while (1 == 1) {
int n, m, i, j, k, tmp;
int result = 0;
scanf("%d%d\n", &n, &m);
if (n == 0 && m == 0)
break;
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
tmp = a[i] + a[j];
if (tmp <= m) {
result = max(result, tmp);
}
}
}
if (result != 0) {
printf("%d\n", result);
} else {
printf("NONE");
}
}
return 0;
}
|
#include <stdio.h>
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
while (1 == 1) {
int n, m, i, j, k, tmp;
int result = 0;
scanf("%d%d", &n, &m);
if (n == 0 && m == 0)
break;
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
tmp = a[i] + a[j];
if (tmp <= m) {
result = max(result, tmp);
}
}
}
if (result != 0) {
printf("%d\n", result);
} else {
printf("NONE\n");
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 211
|
#include <stdio.h>
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
while (1 == 1) {
int n, m, i, j, k, tmp;
int result = 0;
scanf("%d%d\n", &n, &m);
if (n == 0 && m == 0)
break;
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
tmp = a[i] + a[j];
if (tmp <= m) {
result = max(result, tmp);
}
}
}
if (result != 0) {
printf("%d\n", result);
} else {
printf("NONE");
}
}
return 0;
}
|
#include <stdio.h>
int max(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
int main() {
while (1 == 1) {
int n, m, i, j, k, tmp;
int result = 0;
scanf("%d%d", &n, &m);
if (n == 0 && m == 0)
break;
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
tmp = a[i] + a[j];
if (tmp <= m) {
result = max(result, tmp);
}
}
}
if (result != 0) {
printf("%d\n", result);
} else {
printf("NONE\n");
}
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 211
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, m;
while (1) {
int a[1000] = {}, ans = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] + a[j] <= m)
ans = a[i] + a[j];
}
}
if (ans)
cout << ans << "\n";
else
cout << "NONE\n";
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, m;
while (1) {
int a[1000] = {}, ans = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] + a[j] <= m)
ans = max(ans, a[i] + a[j]);
}
}
if (ans)
cout << ans << "\n";
else
cout << "NONE\n";
}
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
| 162
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
while (1) {
long long n, m, a[1000], ans, num;
cin >> n >> m;
num = 0;
ans = 0;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = n; j > i; j--) {
num = a[i] + a[j];
if (num <= m)
ans = max(ans, num);
}
}
if (ans == 0)
cout << "NONE" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
while (1) {
long long n, m, a[1000], ans, num;
cin >> n >> m;
num = 0;
ans = 0;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
num = a[i] + a[j];
if (num <= m)
ans = max(ans, num);
}
}
if (ans == 0)
cout << "NONE" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 165
|
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
while (true) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
if (a[n - 1] + a[n - 2] < m) {
cout << a[n - 1] + a[n - 2] << endl;
continue;
}
int ans = 0;
for (int i = 0; i < n; i++) {
int p = lower_bound(a, a + n, m - a[i]) - a;
while (p >= 0 && a[i] + a[p] > m || i == p)
p--;
if (p > 0 && a[i] + a[p] > ans)
ans = a[i] + a[p];
}
if (ans)
cout << ans << endl;
else
cout << "NONE" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
while (true) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
if (a[n - 1] + a[n - 2] < m) {
cout << a[n - 1] + a[n - 2] << endl;
continue;
}
int ans = 0;
for (int i = 0; i < n; i++) {
int p = lower_bound(a, a + n, m - a[i]) - a;
while (p >= 0 && (a[i] + a[p] > m || i == p))
p--;
if (p >= 0 && a[i] + a[p] > ans)
ans = a[i] + a[p];
}
if (ans)
cout << ans << endl;
else
cout << "NONE" << endl;
}
}
|
[["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 25], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20]]
| 1
| 233
|
#include <iostream>
using namespace std;
int main() {
int a[1001];
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] + a[j] <= m && a[i] + a[j] > ans) {
ans = a[i] + a[j];
}
}
}
if (ans == -1) {
cout << "NONE" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a[1001];
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j && a[i] + a[j] <= m && a[i] + a[j] > ans) {
ans = a[i] + a[j];
}
}
}
if (ans == -1) {
cout << "NONE" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
|
[["+", 15, 339, 51, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 79], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 98]]
| 1
| 175
|
#include <iostream>
#include <sstream>
using namespace std;
int main() {
int n, m, max;
int a[1000];
while (cin >> n >> m) {
max = 0;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] + a[j] <= m) {
if (a[i] + a[j] >= max) {
max = a[i] + a[j];
}
}
}
}
if (max == 0) {
cout << "NONE";
} else {
cout << max << "\n";
}
}
}
|
#include <iostream>
#include <sstream>
using namespace std;
int main() {
int n, m, max;
int a[1000];
while (cin >> n >> m) {
max = 0;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] + a[j] <= m) {
if (a[i] + a[j] >= max) {
max = a[i] + a[j];
}
}
}
}
if (max == 0) {
cout << "NONE\n";
} else {
cout << max << "\n";
}
}
}
|
[["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
| 1
| 181
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int i, n, m, j;
vector<int> ans;
while (1) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<int> item(n);
for (i = 0; i < n; i++) {
cin >> item[i];
}
int max = 0;
int sum;
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
sum = 0;
sum = item[i] + item[j];
if (sum > max && sum <= m) {
max = sum;
}
}
}
if (max == 0) {
ans.push_back(-1);
} else {
ans.push_back(max);
}
}
for (i = 0; i < ans.size(); i++) {
if (ans[i] == -1) {
cout << "NONE";
} else {
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int i, n, m, j;
vector<int> ans;
while (1) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<int> item(n);
for (i = 0; i < n; i++) {
cin >> item[i];
}
int max = 0;
int sum;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
sum = 0;
sum = item[i] + item[j];
if (sum > max && sum < m + 1) {
max = sum;
}
}
}
if (max == 0) {
ans.push_back(-1);
} else {
ans.push_back(max);
}
}
for (i = 0; i < ans.size(); i++) {
if (ans[i] == -1) {
cout << "NONE";
} else {
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 7, 10, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 15, 339, 51, 16, 12, 16, 12, 16, 17, 72], ["+", 15, 339, 51, 16, 12, 16, 12, 16, 12, 13]]
| 1
| 232
|
#include <iostream>
using namespace std;
bool q1() {
int n, maxValue;
cin >> n >> maxValue;
if (n == 0 && maxValue == 0)
return false;
int value[n];
int tempValue = 0;
int tempMax = 0;
for (int i = 0; i < n; i++) {
cin >> value[i];
}
for (int top = 0; top < n - 1; top++) {
for (int i = 1; i < n - top; i++) {
tempValue = value[top] + value[top + i];
if (tempMax < tempValue && tempValue <= maxValue)
tempMax = tempValue;
}
}
if (tempMax == 0) {
cout << "NONE";
return true;
}
cout << tempMax << "\n";
return true;
}
int main() {
while (q1())
;
}
|
#include <iostream>
using namespace std;
bool q1() {
int n, maxValue;
cin >> n >> maxValue;
if (n == 0 && maxValue == 0)
return false;
int value[n];
int tempValue = 0;
int tempMax = 0;
for (int i = 0; i < n; i++) {
cin >> value[i];
}
for (int top = 0; top < n - 1; top++) {
for (int i = 1; i < n - top; i++) {
tempValue = value[top] + value[top + i];
if (tempMax < tempValue && tempValue <= maxValue)
tempMax = tempValue;
}
}
if (tempMax == 0) {
cout << "NONE"
<< "\n";
return true;
}
cout << tempMax << "\n";
return true;
}
int main() {
while (q1())
;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
| 1
| 180
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define int long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
signed main() {
while (true) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
vector<int> a(n);
rep(i, n) cin >> a[i];
int ans = INF;
rep(i, n) {
rep(j, n) {
if (i == j) {
continue;
}
int tmp = a[i] + a[j];
if (tmp > ans && tmp <= m) {
ans = tmp;
}
}
}
if (ans == INF) {
cout << "NONE" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define int long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
signed main() {
while (true) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
vector<int> a(n);
rep(i, n) cin >> a[i];
int ans = -1;
rep(i, n) {
rep(j, n) {
if (i == j) {
continue;
}
int tmp = a[i] + a[j];
if (tmp > ans && tmp <= m) {
ans = tmp;
}
}
}
if (ans == -1) {
cout << "NONE" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 204
|
#include <iostream>
#define MAX 1000
using namespace std;
int a[MAX];
int main() {
while (true) {
int n, m, maxsum = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if ((a[i] + a[j] <= m))
maxsum = max(maxsum, a[i] + a[j]);
}
}
if (maxsum > m || maxsum == 0)
cout << "NONE" << endl;
else
cout << maxsum << endl;
}
return 0;
}
|
#include <iostream>
#define MAX 1001
using namespace std;
int a[MAX];
int main() {
while (true) {
int n, m, maxsum = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if ((a[i] + a[j] <= m))
maxsum = max(maxsum, a[i] + a[j]);
}
}
if (maxsum == 0)
cout << "NONE" << endl;
else
cout << maxsum << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 47], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 172
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (!n)
break;
int a[n];
rep(i, n) { cin >> a[i]; }
int ans = 0;
rep(i, n - 1) {
REP(j, i + 1, n) {
if (a[i] + a[j] <= m && ans < a[i] + a[j])
ans = a[i] + a[j];
}
}
if (ans)
cout << ans << endl;
else
puts("NONE");
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (!n)
break;
int a[n];
rep(i, n) { cin >> a[i]; }
int ans = 0;
rep(i, n - 1) {
REP(j, i + 1, n - 1) {
if (a[i] + a[j] <= m && ans < a[i] + a[j])
ans = a[i] + a[j];
}
}
if (ans)
cout << ans << endl;
else
puts("NONE");
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 163
|
/*#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<deque>
#include<fstream>
#include<iomanip>
#include<map>
#include<queue>
#include <random>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.setf(ios::fixed);
cout.precision(20);
vs v;
string s1, s2;
vs cs1, cs2;
while (true) {
cin >> s1;
if (s1 == ".") break;
cin >> s2;
ll sum = 0;
if (s1 == s2) v.pb("IDENTICAL");
else {
rep(i, s1.size()) {
rep(j, s1.size()) {
if (i != j && s1[i] == '"' && s1[j] ==
'"') { cs1.pb(s1.substr(i + 1, j - 1)); s1[i] = '0'; s1[j] = '0';
}
}
}
rep(i, s2.size()) {
rep(j, s2.size()) {
if (i != j && s2[i] == '"' && s2[j] ==
'"') { cs2.pb(s2.substr(i + 1, j - 1)); s2[i] = '0'; s2[j] = '0';
}
}
}
rep(i, cs1.size()) {
cout << cs1[i] << " " << cs2[i] << endl;
if (cs1[i] != cs2[i]) sum++;
if (sum == 2) break;
}
if (sum == 1) v.pb("CLOSE");
else v.pb("DIFFERENT");
}
}
rep(i, v.size()) cout << v[i] << endl;
return 0;
}*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); (i)--)
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
ll n, m;
vll w;
while (true) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
vll v(n);
ll ans = -1;
rep(i, n) cin >> v[i];
rep(i, n) {
REP(j, i + 1, n) {
if (v[i] + v[j] <= m) {
ans = max(ans, v[i] + v[j]);
}
}
}
if (ans == -1)
puts("NONE");
else
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); (i)--)
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
ll n, m;
vll w;
while (true) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
vll v(n);
ll ans = -1;
rep(i, n) cin >> v[i];
rep(i, n) {
REP(j, i + 1, n) {
if (v[i] + v[j] <= m) {
ans = max(ans, v[i] + v[j]);
}
}
}
if (ans == -1)
cout << "NONE" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["-", 0, 57, 64, 1, 0, 2, 3, 4, 0, 24], ["+", 0, 57, 64, 1, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 16, 31, 16, 17, 151], ["-", 0, 57, 64, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 313
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 736891;
int main() {
int n, m;
bool f[MAX + 1];
while (1) {
cin >> m >> n;
if (m + n == 0)
break;
REP(i, MAX + 1) f[i] = false;
for (int i = m;; i++) {
if (!f[i]) {
if (n == 0) {
cout << i << endl;
break;
} else {
n--;
for (int j = i; j <= MAX; j += i) {
f[j] = true;
}
}
}
}
}
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 7368791;
int main() {
int n, m;
bool f[MAX + 1];
while (1) {
cin >> m >> n;
if (m + n == 0)
break;
REP(i, MAX + 1) f[i] = false;
for (int i = m;; i++) {
if (!f[i]) {
if (n == 0) {
cout << i << endl;
break;
} else {
n--;
for (int j = i; j <= MAX; j += i) {
f[j] = true;
}
}
}
}
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
| 1
| 144
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef pair<int, P> PP;
bool memo[8000000];
int m, n;
void furui(int n, int count) {
fill(memo, memo + 8000000, true);
int cnt = 0;
for (int i = m; i <= m + n; i++) {
if (memo[i - m]) {
memo[i - m] = false;
for (int j = 2 * i; j <= n; j += i) {
memo[j - m] = false;
}
cnt++;
break;
if (cnt == count)
return;
}
}
return;
}
int main() {
while (cin >> m >> n) {
if (m == 0 && n == 0)
return 0;
fill(memo, memo + 8000000, true);
int l = m;
for (int k = 0; k < n; k++) {
for (int i = l; i <= 8000000; i++) {
if (memo[i - m]) {
l = i;
memo[i - m] = false;
for (int j = ((m - i + 1) / i) * i; j <= 8000000; j += i) {
memo[j - m] = false;
}
break;
}
}
/*
for(int i=m;i<=13;i++){
cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
}
cout<<endl;
*/
}
for (int i = 0; i <= 8000000; i++) {
if (memo[i]) {
cout << i + m << endl;
break;
}
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef pair<int, P> PP;
bool memo[8000000];
int m, n;
void furui(int n, int count) {
fill(memo, memo + 8000000, true);
int cnt = 0;
for (int i = m; i <= m + n; i++) {
if (memo[i - m]) {
memo[i - m] = false;
for (int j = 2 * i; j <= n; j += i) {
memo[j - m] = false;
}
cnt++;
break;
if (cnt == count)
return;
}
}
return;
}
int main() {
while (cin >> m >> n) {
if (m == 0 && n == 0)
return 0;
fill(memo, memo + 8000000, true);
int l = m;
for (int k = 0; k < n; k++) {
for (int i = l; i <= 8000000; i++) {
if (memo[i - m]) {
l = i;
memo[i - m] = false;
for (int j = ((m + i - 1) / i) * i; j <= 8000000; j += i) {
memo[j - m] = false;
}
break;
}
}
/*
for(int i=m;i<=13;i++){
cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
}
cout<<endl;
*/
}
for (int i = 0; i <= 8000000; i++) {
if (memo[i]) {
cout << i + m << endl;
break;
}
}
}
return 0;
}
|
[["-", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 33]]
| 1
| 342
|
#ifdef _MSVC_LANG
#define _SCL_SECURE_NO_WARNINGS
#pragma warning(disable : 0325) // inline namespace Error
#endif
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <random>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
// C++ 11 前提
using Ull = unsigned long long;
using Ll = long long;
template <typename T> using Vec = std::vector<T>;
template <typename T, size_t L> using Ary = std::array<T, L>;
namespace {
namespace meta {
namespace coming {
// c++ 17;
template <class... _Types> using void_t = void;
template <class _Ty,
_Ty _Val>
struct integral_constant { // convenient template for integral constant types
static constexpr _Ty value = _Val;
using value_type = _Ty;
using type = integral_constant;
constexpr operator value_type() const noexcept { // return stored value
return (value);
}
constexpr value_type operator()() const noexcept { // return stored value
return (value);
}
};
// c++ 17;
template <bool _Val> using bool_constant = integral_constant<bool, _Val>;
// c++ 14
template <bool _Test, class _Ty = void>
using enable_if_t = typename std::enable_if<_Test, _Ty>::type;
} // namespace coming
namespace core {
template <class, class = void> struct enable_std_begin_end : std::false_type {};
template <typename T>
struct enable_std_begin_end<
T, coming::void_t<decltype(std::begin(std::declval<const T &>()),
std::end(std::declval<const T &>()))>>
: std::true_type {}; // c++ 17
template <class, class = void> struct enable_adl_begin_end : std::false_type {};
template <typename T>
struct enable_adl_begin_end<
T, coming::void_t<decltype(begin(std::declval<const T &>()),
end(std::declval<const T &>()))>>
: std::true_type {};
} // namespace core
template <typename T>
struct is_range : coming::bool_constant<core::enable_std_begin_end<T>::value ||
core::enable_adl_begin_end<T>::value> {
};
/// <summary>
/// ある値が0以上か
/// </summary>
template <class T, T num, class = std::nullptr_t>
struct is_positive : coming::bool_constant<(num >= 0)> {};
} // namespace meta
inline namespace extension {
inline namespace container_io {
inline namespace in {
/// <summary>
/// for cin with STL container
/// </summary>
template <template <class...> class Container, class... Args,
typename = meta::coming::enable_if_t<
!std::is_same<Container<Args...>, std::string>::value>>
std::istream &operator>>(std::istream &is, Container<Args...> &container) {
for (auto &elem : container)
is >> elem;
return is;
}
/// <summary>
/// for cin with std::arary
/// </summary>
template <class T, size_t L>
std::istream &operator>>(std::istream &is, std::array<T, L> &container) {
for (auto &elem : container)
is >> elem;
return is;
}
/// <summary>
/// for cin with raw array
/// </summary>
template <class T, size_t L>
std::istream &operator>>(std::istream &is, T (&ary)[L]) {
for (int i{}; i < L; ++i)
is >> ary[i];
return is;
}
} // namespace in
inline namespace out {
namespace settings {
/// <summary>
/// 要素間の区切り文字
/// </summary>
const auto sepOfContainerElements{"\n"};
/// <summary>
/// コンテナ間の区切り文字
/// </summary>
const auto sepOfContainer{"\n"};
} // namespace settings
/// <summary>
/// for cout Container with STL container
/// </summary>
template <template <class...> class Container, class... Args,
typename = meta::coming::enable_if_t<
!std::is_same<Container<Args...>, std::string>::value>>
std::ostream &operator<<(std::ostream &os,
const Container<Args...> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainerElements;
return os;
}
/// <summary>
/// for cout Container with std::array
/// </summary>
template <class T, size_t L>
std::ostream &operator<<(std::ostream &os, const std::array<T, L> container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainerElements;
return os;
}
/// <summary>
/// for cout Container with raw array
/// </summary>
template <class T, size_t L,
typename = meta::coming::enable_if_t<!std::is_same<T, char>::value>>
std::ostream &operator<<(std::ostream &os, const T (&ary)[L]) {
for (const auto &elem : ary)
os << elem << settings::sepOfContainerElements;
return os;
}
/// <summary>
/// for cout Container in Container with STL container
/// </summary>
template <template <class...> class Container1, class... Cont1Args,
template <class...> class Container2, class... Cont2Args>
std::ostream &operator<<(
std::ostream &os,
const Container1<Container2<Cont2Args...>, Cont1Args...> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout Container in Container with std::array
/// </summary>
template <template <class...> class Container, class... Args, size_t L>
std::ostream &operator<<(std::ostream &os,
const std::array<Container<Args...>, L> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout Container in Container with std::array
/// </summary>
template <template <class...> class Container, class... Args, size_t L, class T>
std::ostream &
operator<<(std::ostream &os,
const Container<std::array<T, L>, Args...> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout Container in Container with std::array
/// </summary>
template <class T, size_t L1, size_t L2>
std::ostream &operator<<(std::ostream &os,
const std::array<std::array<T, L2>, L1> container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout raw ary in raw ary
/// </summary>
template <class T, size_t L1, size_t L2>
std::ostream &operator<<(std::ostream &os, const T (&ary)[L1][L2]) {
for (size_t i{}; i < L1; ++i)
os << ary[i] << settings::sepOfContainer;
return os;
}
} // namespace out
} // namespace container_io
template <typename T, size_t L, typename Function>
void for_each(T (&ary)[L], Function lambda) {
for (size_t i{}; i < L; ++i)
lambda(static_cast<T &>(ary[i]));
}
} // namespace extension
inline namespace util {
template <typename T>
void SetAll(T &container,
typename T::value_type value = typename T::value_type{}) {
for (typename T::reference content : container)
content = value;
}
template <typename T, size_t L> void SetAll(T (&ary)[L], T value) {
for (size_t i{}; i < L; ++i)
ary[i] = value;
}
template <typename T, typename U, size_t L1, size_t L2>
void SetAll(T (&ary)[L1][L2], U value) {
for (size_t i{}; i < L1; ++i)
SetAll(ary[i], value);
}
} // namespace util
inline namespace alg {
bool IsPrime(const Ull n) {
switch (n) {
case 0:
case 1:
return false;
case 2:
return true;
default:
if (n % 2 == 0)
return false;
for (Ull i{3}; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
}
return true;
}
// 最大公約数
Ull EuclideanAlg(Ull n1, Ull n2) {
// if (n1 < 0 || n2 < 0) return 0;
if (n2 > n1)
std::swap(n1, n2);
Ull r;
while ((r = n1 % n2) != 0) {
n1 = n2;
n2 = r;
}
return n2;
}
// 最小公倍数
Ull LCM(const std::vector<Ull> &values) {
if (values.size() == 0)
return 0;
if (values.size() == 1)
return values[0];
if (values.size() == 2)
return values[0] * values[1] / EuclideanAlg(values[0], values[1]);
auto mid = values.cbegin() + values.size() / 2;
return LCM(std::vector<Ull>{LCM(std::vector<Ull>(values.begin(), mid)),
LCM(std::vector<Ull>(mid, values.end()))});
}
} // namespace alg
void Solve();
} // namespace
#if true
int main() {
Solve();
return 0;
}
#endif
template <typename T> void print(T &data, std::string sep = " ") {
for (auto &val : data) {
std::cout << (int)val << sep;
}
std::cout << std::endl;
}
namespace {
constexpr size_t maxYear{7368791};
constexpr size_t arySize{maxYear + 1};
char ary[arySize] = {0};
void Solve() {
while (true) {
int m, n;
std::cin >> m >> n;
if (m == 0 && n == 0)
break;
for (int i{m}, nn{}; nn < n; ++i) {
if (ary[i] == 1)
continue;
for (int j{i}; j < arySize; j += i)
ary[j] = 1;
++nn;
}
// print(ary);
bool hasAns = false;
for (int i{m}; i < arySize; ++i) {
if (ary[i] == 0 && !hasAns) {
std::cout << i;
hasAns = true;
}
ary[i] = 0;
}
}
}
} // namespace
|
#ifdef _MSVC_LANG
#define _SCL_SECURE_NO_WARNINGS
#pragma warning(disable : 0325) // inline namespace Error
#endif
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <random>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
// C++ 11 前提
using Ull = unsigned long long;
using Ll = long long;
template <typename T> using Vec = std::vector<T>;
template <typename T, size_t L> using Ary = std::array<T, L>;
namespace {
namespace meta {
namespace coming {
// c++ 17;
template <class... _Types> using void_t = void;
template <class _Ty,
_Ty _Val>
struct integral_constant { // convenient template for integral constant types
static constexpr _Ty value = _Val;
using value_type = _Ty;
using type = integral_constant;
constexpr operator value_type() const noexcept { // return stored value
return (value);
}
constexpr value_type operator()() const noexcept { // return stored value
return (value);
}
};
// c++ 17;
template <bool _Val> using bool_constant = integral_constant<bool, _Val>;
// c++ 14
template <bool _Test, class _Ty = void>
using enable_if_t = typename std::enable_if<_Test, _Ty>::type;
} // namespace coming
namespace core {
template <class, class = void> struct enable_std_begin_end : std::false_type {};
template <typename T>
struct enable_std_begin_end<
T, coming::void_t<decltype(std::begin(std::declval<const T &>()),
std::end(std::declval<const T &>()))>>
: std::true_type {}; // c++ 17
template <class, class = void> struct enable_adl_begin_end : std::false_type {};
template <typename T>
struct enable_adl_begin_end<
T, coming::void_t<decltype(begin(std::declval<const T &>()),
end(std::declval<const T &>()))>>
: std::true_type {};
} // namespace core
template <typename T>
struct is_range : coming::bool_constant<core::enable_std_begin_end<T>::value ||
core::enable_adl_begin_end<T>::value> {
};
/// <summary>
/// ある値が0以上か
/// </summary>
template <class T, T num, class = std::nullptr_t>
struct is_positive : coming::bool_constant<(num >= 0)> {};
} // namespace meta
inline namespace extension {
inline namespace container_io {
inline namespace in {
/// <summary>
/// for cin with STL container
/// </summary>
template <template <class...> class Container, class... Args,
typename = meta::coming::enable_if_t<
!std::is_same<Container<Args...>, std::string>::value>>
std::istream &operator>>(std::istream &is, Container<Args...> &container) {
for (auto &elem : container)
is >> elem;
return is;
}
/// <summary>
/// for cin with std::arary
/// </summary>
template <class T, size_t L>
std::istream &operator>>(std::istream &is, std::array<T, L> &container) {
for (auto &elem : container)
is >> elem;
return is;
}
/// <summary>
/// for cin with raw array
/// </summary>
template <class T, size_t L>
std::istream &operator>>(std::istream &is, T (&ary)[L]) {
for (int i{}; i < L; ++i)
is >> ary[i];
return is;
}
} // namespace in
inline namespace out {
namespace settings {
/// <summary>
/// 要素間の区切り文字
/// </summary>
const auto sepOfContainerElements{"\n"};
/// <summary>
/// コンテナ間の区切り文字
/// </summary>
const auto sepOfContainer{"\n"};
} // namespace settings
/// <summary>
/// for cout Container with STL container
/// </summary>
template <template <class...> class Container, class... Args,
typename = meta::coming::enable_if_t<
!std::is_same<Container<Args...>, std::string>::value>>
std::ostream &operator<<(std::ostream &os,
const Container<Args...> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainerElements;
return os;
}
/// <summary>
/// for cout Container with std::array
/// </summary>
template <class T, size_t L>
std::ostream &operator<<(std::ostream &os, const std::array<T, L> container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainerElements;
return os;
}
/// <summary>
/// for cout Container with raw array
/// </summary>
template <class T, size_t L,
typename = meta::coming::enable_if_t<!std::is_same<T, char>::value>>
std::ostream &operator<<(std::ostream &os, const T (&ary)[L]) {
for (const auto &elem : ary)
os << elem << settings::sepOfContainerElements;
return os;
}
/// <summary>
/// for cout Container in Container with STL container
/// </summary>
template <template <class...> class Container1, class... Cont1Args,
template <class...> class Container2, class... Cont2Args>
std::ostream &operator<<(
std::ostream &os,
const Container1<Container2<Cont2Args...>, Cont1Args...> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout Container in Container with std::array
/// </summary>
template <template <class...> class Container, class... Args, size_t L>
std::ostream &operator<<(std::ostream &os,
const std::array<Container<Args...>, L> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout Container in Container with std::array
/// </summary>
template <template <class...> class Container, class... Args, size_t L, class T>
std::ostream &
operator<<(std::ostream &os,
const Container<std::array<T, L>, Args...> &container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout Container in Container with std::array
/// </summary>
template <class T, size_t L1, size_t L2>
std::ostream &operator<<(std::ostream &os,
const std::array<std::array<T, L2>, L1> container) {
for (const auto &elem : container)
os << elem << settings::sepOfContainer;
return os;
}
/// <summary>
/// for cout raw ary in raw ary
/// </summary>
template <class T, size_t L1, size_t L2>
std::ostream &operator<<(std::ostream &os, const T (&ary)[L1][L2]) {
for (size_t i{}; i < L1; ++i)
os << ary[i] << settings::sepOfContainer;
return os;
}
} // namespace out
} // namespace container_io
template <typename T, size_t L, typename Function>
void for_each(T (&ary)[L], Function lambda) {
for (size_t i{}; i < L; ++i)
lambda(static_cast<T &>(ary[i]));
}
} // namespace extension
inline namespace util {
template <typename T>
void SetAll(T &container,
typename T::value_type value = typename T::value_type{}) {
for (typename T::reference content : container)
content = value;
}
template <typename T, size_t L> void SetAll(T (&ary)[L], T value) {
for (size_t i{}; i < L; ++i)
ary[i] = value;
}
template <typename T, typename U, size_t L1, size_t L2>
void SetAll(T (&ary)[L1][L2], U value) {
for (size_t i{}; i < L1; ++i)
SetAll(ary[i], value);
}
} // namespace util
inline namespace alg {
bool IsPrime(const Ull n) {
switch (n) {
case 0:
case 1:
return false;
case 2:
return true;
default:
if (n % 2 == 0)
return false;
for (Ull i{3}; i * i <= n; i += 2) {
if (n % i == 0)
return false;
}
}
return true;
}
// 最大公約数
Ull EuclideanAlg(Ull n1, Ull n2) {
// if (n1 < 0 || n2 < 0) return 0;
if (n2 > n1)
std::swap(n1, n2);
Ull r;
while ((r = n1 % n2) != 0) {
n1 = n2;
n2 = r;
}
return n2;
}
// 最小公倍数
Ull LCM(const std::vector<Ull> &values) {
if (values.size() == 0)
return 0;
if (values.size() == 1)
return values[0];
if (values.size() == 2)
return values[0] * values[1] / EuclideanAlg(values[0], values[1]);
auto mid = values.cbegin() + values.size() / 2;
return LCM(std::vector<Ull>{LCM(std::vector<Ull>(values.begin(), mid)),
LCM(std::vector<Ull>(mid, values.end()))});
}
} // namespace alg
void Solve();
} // namespace
#if true
int main() {
Solve();
return 0;
}
#endif
template <typename T> void print(T &data, std::string sep = " ") {
for (auto &val : data) {
std::cout << (int)val << sep;
}
std::cout << std::endl;
}
namespace {
constexpr size_t maxYear{7368791};
constexpr size_t arySize{maxYear + 1};
char ary[arySize] = {0};
void Solve() {
while (true) {
int m, n;
std::cin >> m >> n;
if (m == 0 && n == 0)
break;
for (int i{m}, nn{}; nn < n; ++i) {
if (ary[i] == 1)
continue;
for (int j{i}; j < arySize; j += i)
ary[j] = 1;
++nn;
}
// print(ary);
bool hasAns = false;
for (int i{m}; i < arySize; ++i) {
if (ary[i] == 0 && !hasAns) {
std::cout << i << std::endl;
hasAns = true;
}
ary[i] = 0;
}
}
}
} // namespace
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 64, 9, 0, 1, 0, 16, 12, 343, 345, 348], ["+", 64, 9, 0, 1, 0, 16, 12, 343, 0, 349], ["+", 64, 9, 0, 1, 0, 16, 12, 343, 141, 22]]
| 1
| 2,011
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
const int MAX_P = 7368791; // max
bool prime[MAX_P + 1];
void Eratosthenes(int m) {
for (int i = m; i <= MAX_P; i++)
prime[i] = true;
for (int i = m; i * i <= MAX_P; i++)
if (prime[i])
for (int j = 2; i * j <= MAX_P; j++)
prime[i * j] = false;
}
bool solve() {
int m, n;
cin >> m >> n;
if (m == 0)
return 0;
Eratosthenes(m);
int counter = n;
for (int i = m;; i++) {
counter -= prime[i];
// if(prime[i]) debug(i);
if (counter < 0) {
printf("%d\n", i);
return 1;
}
}
return 1;
}
int main() {
while (solve())
;
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
const int MAX_P = 7368791; // max
bool prime[MAX_P + 1];
void Eratosthenes(int m) {
for (int i = m; i <= MAX_P; i++)
prime[i] = true;
for (int i = m; i <= MAX_P; i++)
if (prime[i])
for (int j = 2; i * j <= MAX_P; j++)
prime[i * j] = false;
}
bool solve() {
int m, n;
cin >> m >> n;
if (m == 0)
return 0;
Eratosthenes(m);
int counter = n;
for (int i = m;; i++) {
counter -= prime[i];
// if(prime[i]) debug(i);
if (counter < 0) {
printf("%d\n", i);
return 1;
}
}
return 1;
}
int main() {
while (solve())
;
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 31, 16, 17, 48], ["-", 8, 9, 0, 7, 15, 16, 31, 16, 12, 22]]
| 1
| 250
|
#include <cstdio>
using namespace std;
int n, m;
bool used[7400000];
int main() {
while (1) {
scanf("%d%d", &m, &n);
if (n == 0)
break;
int ans = m, counter = n;
for (int i = 0; i < 7400000; i++)
used[i] = false;
while (1) {
if (used[ans]) {
ans++;
continue;
}
for (int i = ans; i < 7400000; i += ans)
used[i] = true;
counter--;
if (counter == 0)
break;
ans++;
}
printf("%d\n", ans);
}
}
|
#include <cstdio>
using namespace std;
int n, m;
bool used[7400000];
int main() {
while (1) {
scanf("%d%d", &m, &n);
if (n == 0)
break;
int ans = m, counter = n;
for (int i = 0; i < 7400000; i++)
used[i] = false;
while (1) {
if (used[ans]) {
ans++;
continue;
}
for (int i = ans; i < 7400000; i += ans)
used[i] = true;
counter--;
if (counter < 0)
break;
ans++;
}
printf("%d\n", ans);
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 146
|
#include "bits/stdc++.h"
using namespace std;
int dp[300][300]; // dp[l][r] [l,r]でだるまを落としたときの落とした個数
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int da[300];
for (int i = 0; i < n; i++)
cin >> da[i];
fill(dp[0], dp[300], 0);
for (int i = 1; i < n; i++) {
int dif = da[i] - da[i - 1];
if (dif < 2 && dif > -2)
dp[i - 1][i] = 2;
else
dp[i - 1][i] = 0;
}
//ここからdp
for (int k = 2; k < n; k++) {
for (int i = 0; i < n - k; i++) {
//分割して調べる
for (int j = i; j < i + k - 1; j++)
dp[i][i + k] = max(dp[i][i + k], dp[i][j] + dp[j + 1][i + k]);
//真ん中が全部消える場合も調べる
int dif = da[i] - da[i + k];
if (dp[i + 1][i + k - 1] == k - 1 && dif < 2 && dif > -2)
dp[i][i + k] = k + 1;
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
int dp[300][300]; // dp[l][r] [l,r]でだるまを落としたときの落とした個数
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int da[300];
for (int i = 0; i < n; i++)
cin >> da[i];
fill(dp[0], dp[300], 0);
for (int i = 1; i < n; i++) {
int dif = da[i] - da[i - 1];
if (dif < 2 && dif > -2)
dp[i - 1][i] = 2;
else
dp[i - 1][i] = 0;
}
//ここからdp
for (int k = 2; k < n; k++) {
for (int i = 0; i < n - k; i++) {
//分割して調べる
for (int j = i; j < i + k; j++) {
// cerr<<dp[i][j]+dp[j+1][i+k]<<endl;
dp[i][i + k] = max(dp[i][i + k], dp[i][j] + dp[j + 1][i + k]);
}
//真ん中が全部消える場合も調べる
int dif = da[i] - da[i + k];
if (dp[i + 1][i + k - 1] == k - 1 && dif < 2 && dif > -2)
dp[i][i + k] = k + 1;
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46]]
| 1
| 327
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int n, a[1000], dp[1000][1000];
int main() {
while (true) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++)
dp[i][j] = 0;
}
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
if (abs(a[i] - a[i + 1]) <= 1) {
dp[i][i + 1] = 2;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
int a1 = j, a3 = i + j;
if (a3 >= n)
continue;
for (int k = a1 + 1; k <= a3; k++) {
int a2 = k;
dp[a1][a3] = max(dp[a1][a3], dp[a1][a2 - 1] + dp[a2][a3]);
}
if (dp[a1][a3] >= 1 && a1 > 0 && a3 < n - 1 &&
abs(a[a1 - 1] - a[a3 + 1]) <= 1) {
dp[a1 - 1][a3 + 1] = dp[a1][a3] + 2;
}
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int n, a[1000], dp[1000][1000];
int main() {
while (true) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++)
dp[i][j] = 0;
}
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
if (abs(a[i] - a[i + 1]) <= 1) {
dp[i][i + 1] = 2;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
int a1 = j, a3 = i + j;
if (a3 >= n)
continue;
for (int k = a1 + 1; k <= a3; k++) {
int a2 = k;
dp[a1][a3] = max(dp[a1][a3], dp[a1][a2 - 1] + dp[a2][a3]);
}
if (dp[a1][a3] == i + 1 && a1 > 0 && a3 < n - 1 &&
abs(a[a1 - 1] - a[a3 + 1]) <= 1) {
dp[a1 - 1][a3 + 1] = dp[a1][a3] + 2;
}
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 17, 72]]
| 1
| 357
|
#include <bits/stdc++.h>
#define N 305
using namespace std;
int n, w[N], dp[N][N];
int main() {
while (1) {
cin >> n;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> w[i];
memset(dp, 0, sizeof(dp));
int ans = 0;
for (int i = 1; i <= n; i += 2) {
for (int j = 0; j <= n - i; j++) {
dp[j][j + i] = dp[j + 1][j + i - 1];
for (int k = j + 1; k <= j + i; k += 2)
dp[j][j + i] = max(dp[j][j + i], dp[j][k] + dp[k + 1][j + i]);
if (dp[j + 1][j + i - 1] == i - 1 && abs(w[j] - w[j + i]) <= 1)
dp[j][j + i] = max(dp[j][j + i], dp[j + 1][j + i - 1] + 2);
ans = max(ans, dp[j][j + i]);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define N 305
using namespace std;
int n, w[N], dp[N][N];
int main() {
while (1) {
cin >> n;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> w[i];
memset(dp, 0, sizeof(dp));
int ans = 0;
for (int i = 1; i <= n; i += 2) {
for (int j = 0; j < n - i; j++) {
dp[j][j + i] = dp[j + 1][j + i - 1];
for (int k = j + 1; k <= j + i; k += 2)
dp[j][j + i] = max(dp[j][j + i], dp[j][k] + dp[k + 1][j + i]);
if (dp[j + 1][j + i - 1] == i - 1 && abs(w[j] - w[j + i]) <= 1)
dp[j][j + i] = max(dp[j][j + i], dp[j + 1][j + i - 1] + 2);
ans = max(ans, dp[j][j + i]);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 309
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++)
v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
int main() {
int n;
while (cin >> n, n) {
vi num(n);
REP(i, n)
cin >> num[i];
vector<vector<bool>> able(n, vb(n, false));
for (int i = 2; i < n + 1; i += 2) {
for (int j = 0; j + i - 1 < n; j++) {
if (i == 2) {
if (abs(num[j] - num[j + i - 1]) <= 1)
able[j][j + i - 1] = true;
} else {
if (abs(num[j] - num[j + i - 1]) <= 1 && able[j + 1][j + i - 2])
able[j][j + i - 1] = true;
REP(k, i / 2 - 1)
if (able[j][j + k * 2 + 1] && able[j + k * 2 + 2][j + i - 1])
able[j][j + i - 1] = true;
}
}
}
vvi DP(n, vi(n, 0));
REP(i, n)
REP(j, n)
if (able[i][j])
DP[i][j] = j - i + 1;
for (int i = 3; i < n + 1; i++) {
for (int j = 0; j + i - 1 < n; j++)
REP(k, i)
DP[j][j + i - 1] =
max(DP[j][j + i - 1], DP[j][j + k] + DP[j + k + 1][j + i - 1]);
}
cout << DP[0][n - 1] << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++)
v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
int main() {
int n;
while (cin >> n, n) {
vi num(n);
REP(i, n)
cin >> num[i];
vector<vector<bool>> able(n, vb(n, false));
for (int i = 2; i < n + 1; i += 2) {
for (int j = 0; j + i - 1 < n; j++) {
if (i == 2) {
if (abs(num[j] - num[j + i - 1]) <= 1)
able[j][j + i - 1] = true;
} else {
if (abs(num[j] - num[j + i - 1]) <= 1 && able[j + 1][j + i - 2])
able[j][j + i - 1] = true;
REP(k, i / 2 - 1)
if (able[j][j + k * 2 + 1] && able[j + k * 2 + 2][j + i - 1])
able[j][j + i - 1] = true;
}
}
}
vvi DP(n, vi(n, 0));
REP(i, n)
REP(j, n)
if (able[i][j])
DP[i][j] = j - i + 1;
for (int i = 3; i < n + 1; i++) {
for (int j = 0; j + i - 1 < n; j++)
REP(k, i - 1)
DP[j][j + i - 1] =
max(DP[j][j + i - 1], DP[j][j + k] + DP[j + k + 1][j + i - 1]);
}
cout << DP[0][n - 1] << endl;
}
}
|
[["+", 28, 69, 28, 2, 3, 4, 0, 16, 17, 33], ["+", 28, 69, 28, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 716
|
#include "bits/stdc++.h"
#define REP(i, n, N) for (int i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= n; i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 1e9;
int dp[310][310];
int n;
int w[310];
int main() {
while (cin >> n, n) {
REP(i, 0, n) REP(j, 0, n) dp[i][j] = 0;
REP(i, 0, n) cin >> w[i];
for (int k = 1; k < n; k++) {
REP(L, 0, n - k) {
int R = L + k;
if (dp[L + 1][R - 1] == k - 1)
dp[L][R] =
max(dp[L][R], dp[L + 1][R - 1] + (abs(w[L] - w[R]) <= 1) * 2);
REP(i, L + 1, R - 1) dp[L][R] = max(dp[L][R], dp[L][i] + dp[i + 1][R]);
}
}
p(dp[0][n - 1]);
}
return 0;
}
|
#include "bits/stdc++.h"
#define REP(i, n, N) for (int i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= n; i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 1e9;
int dp[310][310];
int n;
int w[310];
int main() {
while (cin >> n, n) {
REP(i, 0, n) REP(j, 0, n) dp[i][j] = 0;
REP(i, 0, n) cin >> w[i];
for (int k = 1; k < n; k++) {
REP(L, 0, n - k) {
int R = L + k;
if (dp[L + 1][R - 1] == k - 1)
dp[L][R] =
max(dp[L][R], dp[L + 1][R - 1] + (abs(w[L] - w[R]) <= 1) * 2);
REP(i, L, R) dp[L][R] = max(dp[L][R], dp[L][i] + dp[i + 1][R]);
}
}
p(dp[0][n - 1]);
}
return 0;
}
|
[["-", 28, 69, 28, 2, 3, 4, 0, 16, 17, 72], ["-", 28, 69, 28, 2, 3, 4, 0, 16, 12, 13], ["-", 28, 69, 28, 2, 3, 4, 0, 16, 17, 33]]
| 1
| 329
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
// typedef tuple<int, int, int> T;
#define FOR(i, s, x) for (int i = s; i < (int)(x); i++)
#define REP(i, x) FOR(i, 0, x)
#define ALL(c) c.begin(), c.end()
#define DUMP(x) cerr << #x << " = " << (x) << endl
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
int dp[300][300];
int main() {
// use scanf in CodeForces!
cin.tie(0);
ios_base::sync_with_stdio(false);
while (true) {
int N;
cin >> N;
if (not N)
break;
vector<int> W(N);
REP(i, N) cin >> W[i];
memset(dp, 0, sizeof(dp));
FOR(w, 2, N + 1) REP(left, N - w + 1) {
// [left, right]
int right = left + w - 1;
if (dp[left + 1][right - 1] == w - 2 and abs(W[left] - W[right]) <= 1) {
dp[left][right] = w;
} else {
FOR(mid, left + 1, right) {
dp[left][right] =
max(dp[left][right], dp[left][mid] + dp[mid + 1][right]);
}
}
}
cout << dp[0][N - 1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
// typedef tuple<int, int, int> T;
#define FOR(i, s, x) for (int i = s; i < (int)(x); i++)
#define REP(i, x) FOR(i, 0, x)
#define ALL(c) c.begin(), c.end()
#define DUMP(x) cerr << #x << " = " << (x) << endl
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
int dp[300][300];
int main() {
// use scanf in CodeForces!
cin.tie(0);
ios_base::sync_with_stdio(false);
while (true) {
int N;
cin >> N;
if (not N)
break;
vector<int> W(N);
REP(i, N) cin >> W[i];
memset(dp, 0, sizeof(dp));
FOR(w, 2, N + 1) REP(left, N - w + 1) {
// [left, right]
int right = left + w - 1;
if (dp[left + 1][right - 1] == w - 2 and abs(W[left] - W[right]) <= 1) {
dp[left][right] = w;
} else {
FOR(mid, left, right) {
dp[left][right] =
max(dp[left][right], dp[left][mid] + dp[mid + 1][right]);
}
}
}
cout << dp[0][N - 1] << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
| 1
| 336
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n != 0) {
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<vector<int>> dp(n, vector<int>(n, 0));
int ans = 0;
int mx = 0;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (i == 2) {
if (v[j] <= v[j + 1] + 1 && v[j] >= v[j + 1] - 1) {
dp[j][j + 1] = 2;
}
} else {
if (dp[j + 1][j + i - 2] == i - 2 && v[j] <= v[j + i - 1] + 1 &&
v[j] >= v[j + i - 1] - 1) {
dp[j][j + i - 1] = i;
}
mx = dp[j][j + i - 1];
for (int k = 1; k <= i - 2; k++) {
mx = max(mx, dp[j][j + k] + dp[j + k + 1][j + i - 1]);
dp[j][j + i - 1] = mx;
}
}
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n != 0) {
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<vector<int>> dp(n, vector<int>(n, 0));
int ans = 0;
int mx = 0;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (i == 2) {
if (v[j] <= v[j + 1] + 1 && v[j] >= v[j + 1] - 1) {
dp[j][j + 1] = 2;
}
} else {
if (dp[j + 1][j + i - 2] == i - 2 && v[j] <= v[j + i - 1] + 1 &&
v[j] >= v[j + i - 1] - 1) {
dp[j][j + i - 1] = i;
}
mx = dp[j][j + i - 1];
for (int k = 0; k <= i - 2; k++) {
mx = max(mx, dp[j][j + k] + dp[j + k + 1][j + i - 1]);
dp[j][j + i - 1] = mx;
}
}
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
[["-", 0, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 354
|
// written by @kakira9618
// problem:
// http://icpc.iisf.or.jp/past-icpc/domestic2016/problems/all_ja.html#section_D
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
int n;
vector<int> W;
int dp[301][301];
int dfs(int l, int r) {
if (r - l <= 1)
return dp[l][r] = 0;
if (dp[l][r] != -1)
return dp[l][r];
int ans = 0;
for (int i = l + 1; i < r - 1; i++) {
ans = max(ans, dfs(l, i) + dfs(i, r));
}
if (abs(W[r - 1] - W[l]) <= 1) {
if (dfs(l + 1, r - 1) == r - l - 2) {
ans = max(ans, dfs(l + 1, r - 1) + 2);
}
}
return dp[l][r] = ans;
}
int main() {
while (cin >> n, n) {
memset(dp, -1, sizeof(int) * 301 * 301);
W.clear();
W.resize(n);
for (int i = 0; i < n; i++) {
cin >> W[i];
}
cout << dfs(0, n) << endl;
}
return 0;
}
|
// written by @kakira9618
// problem:
// http://icpc.iisf.or.jp/past-icpc/domestic2016/problems/all_ja.html#section_D
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
int n;
vector<int> W;
int dp[301][301];
// O(n^3)
int dfs(int l, int r) {
if (r - l <= 1)
return dp[l][r] = 0;
if (dp[l][r] != -1)
return dp[l][r]; // ?????¢???
int ans = 0;
// i????????§??????????????????????¨?????????????????§£??????
for (int i = l + 1; i < r; i++) {
ans = max(ans, dfs(l, i) + dfs(i, r));
}
// ?????£???2??????????????¶?????????1??\???????????????????????¨????¶??????????????????°?????£????????????????¶???????
if (abs(W[r - 1] - W[l]) <= 1) {
if (dfs(l + 1, r - 1) == r - l - 2) {
ans = max(ans, dfs(l + 1, r - 1) + 2);
}
}
return dp[l][r] = ans;
}
int main() {
while (cin >> n, n) {
memset(dp, -1, sizeof(int) * 301 * 301);
W.clear();
W.resize(n);
for (int i = 0; i < n; i++) {
cin >> W[i];
}
cout << dfs(0, n) << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 285
|
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
typedef long long LL;
int N;
bool ok[1001][1001];
int dp[1001][1001];
int ans[1001];
int main() {
while (cin >> N, N) {
vector<int> v(N);
REP(i, N) cin >> v[i];
REP(i, 1001) REP(j, 1001) {
ok[i][j] = false;
dp[i][j] = 0;
}
// ok????????????
/*REP(i,N){
for(int j=i+1;j<N;j++){
if(j-i==1&&abs(v[i]-v[j])<=1){ok[i][j]=true;dp[i][j]=2;continue;}
if(j-i==2){ok[i][j]=false;dp[i][j]=0;continue;}
for(int k=i+1;k+1<j;k++){
if(abs(v[i]-v[j])>1)continue;
if(ok[i][k]==false)continue;
if(ok[k+1][j]==false)continue;
ok[i][j]=true;
dp[i][j]=j-i+1;
}
}
}*/
for (int k = 1; k <= N - 1; k++) {
REP(i, N) {
if (i + k >= N)
continue;
if (k == 1 && abs(v[i] - v[i + 1]) <= 1) {
ok[i][i + 1] = true;
dp[i][i + 1] = 2;
continue;
}
if (k == 1)
continue;
if (k == 2) {
ok[i][i + 2] = false;
dp[i][i + 2] = 0;
continue;
}
if (abs(v[i] - v[i + k]) <= 1 && ok[i + 1][i + k - 1] == true) {
ok[i][i + k] = true;
dp[i][i + k] = k + 1;
}
for (int j = 1; j <= k; j++) {
if (ok[i][i + j] && ok[i + j + 1][i + k]) {
ok[i][i + k] = true;
dp[i][i + k] = k + 1;
}
/*if(abs(v[i]-v[i+j]>1))continue;
if(ok[i][i+j-1]==false)continue;
if(ok[i+j+1][i+k]==false)continue;
ok[i][i+k]=true;
dp[i][i+k]=k+1;*/
}
}
}
REP(i, 1001) { ans[i] = 0; }
for (int i = 1; i < N; i++) {
ans[i] = max(ans[i], ans[i - 1]);
ans[i] = max(ans[i], dp[0][i]);
for (int j = 1; j < i; j++) {
ans[i] = max(ans[i], ans[j] + dp[j + 1][i]);
}
}
// REP(i,N){REP(j,N)cout<<dp[i][j]<<" ";cout<<endl;}
// REP(i,N)cout<<ans[i]<<endl;
cout << ans[N - 1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
typedef long long LL;
int N;
bool ok[1001][1001];
int dp[1001][1001];
int ans[1001];
int main() {
while (cin >> N, N) {
vector<int> v(N);
REP(i, N) cin >> v[i];
REP(i, 1001) REP(j, 1001) {
ok[i][j] = false;
dp[i][j] = 0;
}
// ok????????????
/*REP(i,N){
for(int j=i+1;j<N;j++){
if(j-i==1&&abs(v[i]-v[j])<=1){ok[i][j]=true;dp[i][j]=2;continue;}
if(j-i==2){ok[i][j]=false;dp[i][j]=0;continue;}
for(int k=i+1;k+1<j;k++){
if(abs(v[i]-v[j])>1)continue;
if(ok[i][k]==false)continue;
if(ok[k+1][j]==false)continue;
ok[i][j]=true;
dp[i][j]=j-i+1;
}
}
}*/
for (int k = 1; k <= N - 1; k++) {
REP(i, N) {
if (i + k >= N)
continue;
if (k == 1 && abs(v[i] - v[i + 1]) <= 1) {
ok[i][i + 1] = true;
dp[i][i + 1] = 2;
continue;
}
if (k == 1)
continue;
if (k == 2) {
ok[i][i + 2] = false;
dp[i][i + 2] = 0;
continue;
}
if (abs(v[i] - v[i + k]) <= 1 && ok[i + 1][i + k - 1] == true) {
ok[i][i + k] = true;
dp[i][i + k] = k + 1;
}
for (int j = 1; j <= k; j++) {
if (ok[i][i + j] && ok[i + j + 1][i + k]) {
ok[i][i + k] = true;
dp[i][i + k] = k + 1;
}
/*if(abs(v[i]-v[i+j]>1))continue;
if(ok[i][i+j-1]==false)continue;
if(ok[i+j+1][i+k]==false)continue;
ok[i][i+k]=true;
dp[i][i+k]=k+1;*/
}
}
}
REP(i, 1001) { ans[i] = 0; }
for (int i = 1; i < N; i++) {
ans[i] = max(ans[i], ans[i - 1]);
ans[i] = max(ans[i], dp[0][i]);
for (int j = 0; j < i; j++) {
ans[i] = max(ans[i], ans[j] + dp[j + 1][i]);
}
}
// REP(i,N){REP(j,N)cout<<dp[i][j]<<" ";cout<<endl;}
// REP(i,N)cout<<ans[i]<<endl;
cout << ans[N - 1] << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 522
|
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define OK(x, y) abs(w[x] - w[y]) <= 1
int n, w[311];
int dp[311][311];
int main() {
while (cin >> n && n) {
REP(i, n) cin >> w[i];
memset(dp, 0, sizeof dp);
for (int j = 1; j < n; j++) {
for (int i = 0; i + j < n; i++) {
if (OK(i, i + j) && dp[i + 1][i + j - 1] == j - 1) {
dp[i][i + j] = j + 1;
}
for (int k = i + 1; k <= i + j - 1; k++) {
dp[i][i + j] = max(dp[i][i + j], dp[i][k] + dp[k + 1][i + j]);
}
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define OK(x, y) abs(w[x] - w[y]) <= 1
int n, w[311];
int dp[311][311];
int main() {
while (cin >> n && n) {
REP(i, n) cin >> w[i];
memset(dp, 0, sizeof dp);
for (int j = 1; j < n; j++) {
for (int i = 0; i + j < n; i++) {
if (OK(i, i + j) && dp[i + 1][i + j - 1] == j - 1) {
dp[i][i + j] = j + 1;
}
for (int k = i; k <= i + j; k++) {
dp[i][i + j] = max(dp[i][i + j], dp[i][k] + dp[k + 1][i + j]);
}
}
}
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
[["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 245
|
#include <cmath>
#include <iostream>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;
int N, W[300];
int dp[301][3001];
bool ok(int i, int j) { return abs(W[i] - W[j]) <= 1; }
int dfs(int l, int r) {
if (r - l <= 1)
return 0;
if (r - l == 2)
return ok(l, l + 1) ? 2 : 0;
if (dp[l][r] >= 0)
return dp[l][r];
int ret = 0;
REP(i, l + 1, r - 1) ret = max(ret, dfs(l, i) + dfs(i, r));
if (ok(l, r - 1) && dfs(l + 1, r - 1) == r - l - 2)
ret = max(ret, r - l);
return dp[l][r] = ret;
}
int main(void) {
while (cin >> N, N) {
REP(i, 0, N) cin >> W[i];
REP(i, 0, 301) REP(j, 0, 301) dp[i][j] = -1;
cout << dfs(0, N) << endl;
}
}
|
#include <cmath>
#include <iostream>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;
int N, W[300];
int dp[301][3001];
bool ok(int i, int j) { return abs(W[i] - W[j]) <= 1; }
int dfs(int l, int r) {
if (r - l <= 1)
return 0;
if (r - l == 2)
return ok(l, l + 1) ? 2 : 0;
if (dp[l][r] >= 0)
return dp[l][r];
int ret = 0;
REP(i, l + 1, r) ret = max(ret, dfs(l, i) + dfs(i, r));
if (ok(l, r - 1) && dfs(l + 1, r - 1) == r - l - 2)
ret = max(ret, r - l);
return dp[l][r] = ret;
}
int main(void) {
while (cin >> N, N) {
REP(i, 0, N) cin >> W[i];
REP(i, 0, 301) REP(j, 0, 301) dp[i][j] = -1;
cout << dfs(0, N) << endl;
}
}
|
[["-", 0, 11, 31, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 11, 31, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 286
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int w[n];
for (int i = 0; i < n; ++i)
cin >> w[i];
int dp[n][n];
for (int i = 0; i < n; ++i) {
fill(dp[i], dp[i] + n, 0);
}
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n; ++j) {
if (j + i + 1 > n - 1)
break;
if (dp[j + 1][j + i] == i && abs(w[j] - w[j + i + 1]) < 2) {
dp[j][j + i + 1] = dp[j + 1][j + i] + 2;
} else {
for (int k = 0; k < i; ++k) {
dp[j][j + i + 1] =
max(dp[j][j + i + 1], dp[j][j + k] + dp[j + k + 1][j + i + 1]);
}
}
}
}
/*
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
cout << dp[i][j] << " ";
}
cout << endl;
}
*/
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int w[n];
for (int i = 0; i < n; ++i)
cin >> w[i];
int dp[n][n];
for (int i = 0; i < n; ++i) {
fill(dp[i], dp[i] + n, 0);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j + i + 1 > n - 1)
break;
if (dp[j + 1][j + i] == i && abs(w[j] - w[j + i + 1]) < 2) {
dp[j][j + i + 1] = dp[j + 1][j + i] + 2;
} else {
for (int k = 0; k <= i; ++k) {
dp[j][j + i + 1] =
max(dp[j][j + i + 1], dp[j][j + k] + dp[j + k + 1][j + i + 1]);
}
}
}
}
// Debug
/*
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
cout << dp[i][j] << " ";
}
cout << endl;
}
*/
cout << dp[0][n - 1] << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 75, 76, 0, 9, 0, 7, 15, 16, 17, 18], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 297
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
int main() {
int n;
while (cin >> n, n) {
vector<int> w(n, 0);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
for (int W = 2; W <= n; W++) {
// left
for (int l = 0; l < n; l++) {
int r = l + W - 1;
if (r > n)
continue;
if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r - 1]) <= 1)
dp[l][r] = W;
for (int mid = l; mid <= r; mid++) {
dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
}
}
}
cout << dp[0][n] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
int main() {
int n;
while (cin >> n, n) {
vector<int> w(n, 0);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
for (int W = 2; W <= n; W++) {
// left
for (int l = 0; l < n; l++) {
int r = l + W;
if (r > n)
continue;
if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r - 1]) <= 1)
dp[l][r] = W;
for (int mid = l; mid <= r; mid++) {
dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
}
}
}
cout << dp[0][n] << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 291
|
#include <bits/stdc++.h>
// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
// Loop
#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (auto i = (a); i >= (b); --i)
#define REP(i, a) for (long i = 0; i < (a); ++i)
#define RREP(i, a) for (long i = (a); i >= 0; --i)
#define EACH(i, a) for (auto(i) = (a).begin(), _END = (a).end(); i != _END; ++i)
#define REACH(i, a) \
for (auto(i) = (a).rbegin(), _END = (a).rend(); i != _END; ++i)
// Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a, x) ((a).find(x) != (a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) \
std::sort((a).begin(), a.end()), \
a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);
// Setting
#define OPT \
std::cin.tie(0); \
std::ios::sync_with_stdio(false);
// debug message
bool debug = true;
#define MSG(s) \
if (debug) { \
std::cout << s << std::endl; \
}
#define DEBUG(x) \
if (debug) { \
std::cout << "debug(" << #x << "): " << x << std::endl; \
}
// alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<VC> VC2;
typedef std::vector<VI> VI2;
typedef std::vector<VL> VL2;
typedef std::vector<VLL> VLL2;
typedef std::pair<int, int> PII;
int n;
VI w(301);
VI2 memo(301, VI(301));
int dp(int l, int r) {
if (l == r)
return 0;
if (r - l == 1)
return (std::abs(w[l] - w[r]) <= 1) ? 2 : 0;
if (memo[l][r] != -1)
return memo[l][r];
int ans = 0;
if (std::abs(w[l] - w[r]) <= 1) {
int res = dp(l + 1, r + 1);
if (res == r - l - 1) {
ans = 2 + res;
}
}
for (int i = l; i < r; ++i) {
ans = std::max(ans, dp(l, i) + dp(i + 1, r));
}
return memo[l][r] = ans;
}
int main() {
while (std::cin >> n, n != 0) {
REP(i, n) { std::cin >> w[i]; }
memo.assign(301, VI(301, -1));
std::cout << dp(0, n - 1) << std::endl;
}
}
|
#include <bits/stdc++.h>
// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
// Loop
#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (auto i = (a); i >= (b); --i)
#define REP(i, a) for (long i = 0; i < (a); ++i)
#define RREP(i, a) for (long i = (a); i >= 0; --i)
#define EACH(i, a) for (auto(i) = (a).begin(), _END = (a).end(); i != _END; ++i)
#define REACH(i, a) \
for (auto(i) = (a).rbegin(), _END = (a).rend(); i != _END; ++i)
// Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a, x) ((a).find(x) != (a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) \
std::sort((a).begin(), a.end()), \
a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);
// Setting
#define OPT \
std::cin.tie(0); \
std::ios::sync_with_stdio(false);
// debug message
bool debug = true;
#define MSG(s) \
if (debug) { \
std::cout << s << std::endl; \
}
#define DEBUG(x) \
if (debug) { \
std::cout << "debug(" << #x << "): " << x << std::endl; \
}
// alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<VC> VC2;
typedef std::vector<VI> VI2;
typedef std::vector<VL> VL2;
typedef std::vector<VLL> VLL2;
typedef std::pair<int, int> PII;
int n;
VI w(301);
VI2 memo(301, VI(301));
int dp(int l, int r) {
if (l == r)
return 0;
if (r - l == 1)
return (std::abs(w[l] - w[r]) <= 1) ? 2 : 0;
if (memo[l][r] != -1)
return memo[l][r];
int ans = 0;
if (std::abs(w[l] - w[r]) <= 1) {
int res = dp(l + 1, r - 1);
if (res == r - l - 1) {
ans = 2 + res;
}
}
for (int i = l; i < r; ++i) {
ans = std::max(ans, dp(l, i) + dp(i + 1, r));
}
return memo[l][r] = ans;
}
int main() {
while (std::cin >> n, n != 0) {
REP(i, n) { std::cin >> w[i]; }
memo.assign(301, VI(301, -1));
std::cout << dp(0, n - 1) << std::endl;
}
}
|
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 17, 72], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 33]]
| 1
| 495
|
while true
x, y = gets.split(' ').map(&:to_i)
break if x == 0 && y == 0
results = []
prices = gets.split(' ').map(&:to_i)
(0..n-1).each do |i|
(0..i-1).each do |j|
sum = prices[i] + prices[j]
results.push(sum) if sum <= y
end
end
puts results.empty? ? 'NONE' : results.max
end
|
while true
x, y = gets.split(' ').map(&:to_i)
break if x == 0 && y == 0
results = []
prices = gets.split(' ').map(&:to_i)
(0..x-1).each do |i|
(0..i-1).each do |j|
sum = prices[i] + prices[j]
results.push(sum) if sum <= y
end
end
puts results.empty? ? 'NONE' : results.max
end
|
[["-", 0, 652, 486, 739, 0, 475, 444, 738, 31, 22], ["+", 0, 652, 486, 739, 0, 475, 444, 738, 31, 22]]
| 4
| 111
|
#!/usr/bin/env python3
n_list = []
m_list = []
a_list = []
while True:
n, m = list(map(int, input().split(' ')))
if n == 0 and m == 0:
break
a = list(map(int, input().split(' ')))
n_list.append(n)
m_list.append(m)
a_list.append(a)
for n, m, a in zip(n_list, m_list, a_list):
m_sum = 0
for i in range(0, n):
for j in range(i + 1, n):
tmp = a[i] + a[j]
if m_sum < tmp and tmp <= m:
m_sum = tmp
if m_sum > 0:
print(m_sum)
else:
print('None')
|
#!/usr/bin/env python3
n_list = []
m_list = []
a_list = []
while True:
n, m = list(map(int, input().split(' ')))
if n == 0 and m == 0:
break
a = list(map(int, input().split(' ')))
n_list.append(n)
m_list.append(m)
a_list.append(a)
for n, m, a in zip(n_list, m_list, a_list):
m_sum = 0
for i in range(0, n):
for j in range(i + 1, n):
tmp = a[i] + a[j]
if m_sum < tmp and tmp <= m:
m_sum = tmp
if m_sum > 0:
print(m_sum)
else:
print('NONE')
|
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 167
|
ans = []
cou = 0
while(1):
n,m = map(int,input().split())
if(n == 0): break
ar = list(map(int,input().split()))
max_ans = 0
for i in range(n-1):
for j in range(i,n):
if(max_ans < ar[i]+ar[j] and ar[i]+ar[j] <= m):
max_ans = ar[i] + ar[j]
ans.append(max_ans)
cou += 1
for i in range(cou):
if(ans[i] == 0): print("NONE")
else: print(ans[i])
|
ans = []
cou = 0
while(1):
n,m = map(int,input().split())
if(n == 0): break
ar = list(map(int,input().split()))
max_ans = 0
for i in range(n-1):
for j in range(i+1,n):
if(max_ans < ar[i]+ar[j] and ar[i]+ar[j] <= m):
max_ans = ar[i] + ar[j]
ans.append(max_ans)
cou += 1
for i in range(cou):
if(ans[i] == 0): print("NONE")
else: print(ans[i])
|
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 156
|
maxs=[]
while(True):
max=-1
b=list(map(int,input().split()))
n=b[0]
m=b[1]
if(n == 0 and m == 0):
break
a=list(map(int,input().split()))
for i in range(n):
for j in range(i+1,n):
sum=a[i]+a[j]
if(sum>max and sum<m):
max=sum
maxs.append(max)
for i in maxs:
if i==-1:
print("NONE")
else:
print(i)
|
maxs=[]
while(True):
max=-1
b=list(map(int,input().split()))
n=b[0]
m=b[1]
if(n == 0 and m == 0):
break
a=list(map(int,input().split()))
for i in range(n):
for j in range(i+1,n):
sum=a[i]+a[j]
if(sum>max and sum<=m):
max=sum
maxs.append(max)
for i in maxs:
if i==-1:
print("NONE")
else:
print(i)
|
[["-", 0, 57, 15, 23, 0, 679, 12, 666, 667, 18], ["+", 0, 57, 15, 23, 0, 679, 12, 666, 667, 19]]
| 5
| 145
|
while 1:
str=input().split()
n=int(str[0])
m=int(str[1])
if n==0 and m==0: break
str=input().split()
a=[0]*n
for i in range(n):
a[i]=int(str[i])
a.sort()
a.reverse()
print(a)
flag=0
max=0
for i in range(n):
if flag!=0: break
for j in range(i+1,n):
v=a[i]+a[j]
if m>=v:
if max<v: max=v
if max==0: print("NONE")
else: print(max)
|
while 1:
str=input().split()
n=int(str[0])
m=int(str[1])
if n==0 and m==0: break
str=input().split()
a=[0]*n
for i in range(n):
a[i]=int(str[i])
a.sort()
a.reverse()
flag=0
max=0
for i in range(n):
if flag!=0: break
for j in range(i+1,n):
v=a[i]+a[j]
if m>=v:
if max<v: max=v
if max==0: print("NONE")
else: print(max)
|
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 163
|
import sys
while(True):
items=[]
max=0
n, m = map(int, input().split())
if (n == 0 & m == 0):exit()
items = list(map(int, input().split()))
for i in range(n):
for j in range(n):
sum = items[i] + items[j]
if (i != j and sum < m and sum > max):
max = sum
if (max == 0):
print("NONE")
else:
print(max)
|
import sys
while(True):
items=[]
max=0
n, m = map(int, input().split())
if (n == 0 & m == 0):exit()
items = list(map(int, input().split()))
for i in range(n):
for j in range(n):
sum = items[i] + items[j]
if (i != j and sum <= m and sum > max):
max = sum
if (max == 0):
print("NONE")
else:
print(max)
|
[["-", 15, 23, 0, 679, 31, 679, 12, 666, 667, 18], ["+", 15, 23, 0, 679, 31, 679, 12, 666, 667, 19]]
| 5
| 125
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s, t;
while (cin >> s && s != ".") {
cin >> t;
vector<string> v1, u1, v2, u2;
bool flag = 0;
string tmp;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '"' && !flag) {
v1.push_back(tmp);
flag = 1;
tmp.clear();
} else if (s[i] == '"' && flag) {
u1.push_back(tmp);
flag = 0;
tmp.clear();
} else {
tmp.push_back(s[i]);
}
}
v1.push_back(tmp);
string tmp2;
flag = 0;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '"' && !flag) {
v2.push_back(tmp2);
flag = 1;
tmp2.clear();
} else if (t[i] == '"' && flag) {
u2.push_back(tmp2);
flag = 0;
tmp2.clear();
} else {
tmp2.push_back(t[i]);
}
}
v2.push_back(tmp2);
if (v1.size() != v2.size() || u1.size() != u2.size()) {
cout << "DIFFERENT" << endl;
continue;
}
flag = 0;
for (int i = 0; i < v1.size(); i++) {
if (v1[i] != v2[i]) {
cout << "DIFFERENT" << endl;
flag = 1;
}
}
if (flag)
continue;
int cnt = 0;
for (int i = 0; i < u1.size(); i++) {
if (u1[i] != u2[i]) {
cnt++;
}
}
if (cnt == 0) {
cout << "IDENTICAL" << endl;
} else if (cnt == 1) {
cout << "CLOSE" << endl;
} else {
cout << "DIFFERENT" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s, t;
while (cin >> s && s != ".") {
cin >> t;
vector<string> v1, u1, v2, u2;
bool flag = 0;
string tmp;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '"' && !flag) {
v1.push_back(tmp);
flag = 1;
tmp.clear();
} else if (s[i] == '"' && flag) {
u1.push_back(tmp);
flag = 0;
tmp.clear();
} else {
tmp.push_back(s[i]);
}
}
v1.push_back(tmp);
string tmp2;
flag = 0;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '"' && !flag) {
v2.push_back(tmp2);
flag = 1;
tmp2.clear();
} else if (t[i] == '"' && flag) {
u2.push_back(tmp2);
flag = 0;
tmp2.clear();
} else {
tmp2.push_back(t[i]);
}
}
v2.push_back(tmp2);
if (v1.size() != v2.size() || u1.size() != u2.size()) {
cout << "DIFFERENT" << endl;
continue;
}
flag = 0;
for (int i = 0; i < v1.size(); i++) {
if (v1[i] != v2[i]) {
cout << "DIFFERENT" << endl;
flag = 1;
break;
}
}
if (flag)
continue;
int cnt = 0;
for (int i = 0; i < u1.size(); i++) {
if (u1[i] != u2[i]) {
cnt++;
}
}
if (cnt == 0) {
cout << "IDENTICAL" << endl;
} else if (cnt == 1) {
cout << "CLOSE" << endl;
} else {
cout << "DIFFERENT" << endl;
}
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 461
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
void split(string s, vector<string> &v) {
v.clear();
s += '"';
string str = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == '"') {
v.push_back(str);
str = "";
} else {
str += s[i];
}
}
}
int main() {
while (1) {
string s1, s2;
cin >> s1;
if (s1 == ".")
break;
cin >> s2;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
} else {
vector<string> v1, v2;
split(s1, v1);
split(s2, v2);
if (v1.size() != v2.size()) {
cout << "DIFFERENT" << endl;
} else {
bool a = false;
int cnt = 0;
for (int i = 0; i < v1.size(); i++) {
if (i % 2 == 0) {
if (v1[i] != v2[i]) {
a = true;
}
} else {
if (v1[i] != v2[i])
cnt++;
}
}
if (a) {
cout << "DIFFERENT" << endl;
}
if (cnt > 1) {
cout << "DIFFERENT" << endl;
} else {
cout << "CLOSE" << endl;
}
}
}
}
}
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
void split(string s, vector<string> &v) {
v.clear();
s += '"';
string str = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == '"') {
v.push_back(str);
str = "";
} else {
str += s[i];
}
}
}
int main() {
while (1) {
string s1, s2;
cin >> s1;
if (s1 == ".")
break;
cin >> s2;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
} else {
vector<string> v1, v2;
split(s1, v1);
split(s2, v2);
if (v1.size() != v2.size()) {
cout << "DIFFERENT" << endl;
} else {
bool a = false;
int cnt = 0;
for (int i = 0; i < v1.size(); i++) {
if (i % 2 == 0) {
if (v1[i] != v2[i])
a = true;
} else {
if (v1[i] != v2[i])
cnt++;
}
}
if (a) {
cout << "DIFFERENT" << endl;
} else if (cnt > 1) {
cout << "DIFFERENT" << endl;
} else {
cout << "CLOSE" << endl;
}
}
}
}
}
|
[["-", 0, 57, 64, 9, 0, 57, 64, 9, 0, 45], ["-", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 75, 76, 0, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 322
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void split(string s, vector<string> &v) {
s += '"';
string buf = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == '"') {
v.push_back(buf);
buf = "";
} else
buf += s[i];
}
}
int main() {
while (1) {
string S1, S2;
cin >> S1;
if (S1 == ".")
break;
cin >> S2;
//すでに完全に一致ならば
if (S1 == S2) {
cout << "IDENTICAL" << endl;
continue;
}
vector<string> v1, v2;
split(S1, v1), split(S2, v2);
if (v1.size() != v2.size()) {
cout << "DIFFERENT" << endl;
continue;
}
int cnt = 0;
for (int i = 0; i < v1.size(); i++) {
if (i % 2 == 0) {
if (v1[i] != v2[i]) {
cout << "DIFFERENT" << endl;
continue;
}
} else {
if (v1[i] != v2[i]) {
cnt++;
}
}
}
if (cnt > 1) {
cout << "DIFFERENT" << endl;
} else {
cout << "CLOSE" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void split(string s, vector<string> &v) {
s += '"';
string buf = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == '"') {
v.push_back(buf);
buf = "";
} else
buf += s[i];
}
}
int main() {
while (1) {
string S1, S2;
cin >> S1;
if (S1 == ".")
break;
cin >> S2;
//すでに完全に一致ならば
if (S1 == S2) {
cout << "IDENTICAL" << endl;
continue;
}
vector<string> v1, v2;
split(S1, v1), split(S2, v2);
if (v1.size() != v2.size()) {
cout << "DIFFERENT" << endl;
continue;
}
int cnt = 0;
for (int i = 0; i < v1.size(); i++) {
if (i % 2 == 0) {
if (v1[i] != v2[i]) {
cout << "DIFFERENT" << endl;
goto next;
}
} else {
if (v1[i] != v2[i]) {
cnt++;
}
}
}
if (cnt > 1) {
cout << "DIFFERENT" << endl;
} else {
cout << "CLOSE" << endl;
}
next:;
}
return 0;
}
|
[["-", 64, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["+", 64, 9, 0, 57, 64, 9, 0, 126, 0, 127], ["+", 64, 9, 0, 57, 64, 9, 0, 126, 128, 129], ["+", 8, 9, 0, 52, 8, 9, 0, 97, 128, 129], ["+", 8, 9, 0, 52, 8, 9, 0, 97, 0, 102], ["+", 0, 52, 8, 9, 0, 97, 0, 1, 0, 35]]
| 1
| 301
|
#include <bits/stdc++.h>
using namespace std;
#define r(i, n) for (int i = 0; i < n; i++)
string a[2], b;
string s[2][1001];
int p[2];
void dfs(int x) {
r(i, a[x].size()) {
if (a[x][i] == '"') {
i++;
s[x][p[x]] += '"';
while (i < a[x].size() && a[x][i] != '"')
s[x][p[x]] += a[x][i++];
p[x]++;
} else {
while (i < a[x].size() && a[x][i] != '"')
s[x][p[x]] += a[x][i++];
p[x]++;
i--;
}
}
}
main() {
while (cin >> a[0], a[0] != ".") {
cin >> a[1];
p[0] = p[1] = 0;
r(i, 2) r(j, 1001) s[i][j] = "";
r(i, 2) dfs(i);
if (p[0] != p[1])
cout << "DIFFERENT" << endl;
else {
int f1 = 0, f2 = 0;
r(i, p[0]) if (s[0][i] != s[1][i]) {
if (s[0][i][0] == '"' && s[1][i][0] == '"')
f1++;
else
f2++;
}
if (f2 || f1 > 1)
cout << "DiFERENT" << endl;
else if (f1)
cout << "CLOSE" << endl;
else
cout << "IDENTICAL" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define r(i, n) for (int i = 0; i < n; i++)
string a[2], b;
string s[2][1001];
int p[2];
void dfs(int x) {
r(i, a[x].size()) {
if (a[x][i] == '"') {
i++;
s[x][p[x]] += '"';
while (i < a[x].size() && a[x][i] != '"')
s[x][p[x]] += a[x][i++];
p[x]++;
} else {
while (i < a[x].size() && a[x][i] != '"')
s[x][p[x]] += a[x][i++];
p[x]++;
i--;
}
}
}
main() {
while (cin >> a[0], a[0] != ".") {
cin >> a[1];
p[0] = p[1] = 0;
r(i, 2) r(j, 1001) s[i][j] = "";
r(i, 2) dfs(i);
if (p[0] != p[1])
cout << "DIFFERENT" << endl;
else {
int f1 = 0, f2 = 0;
r(i, p[0]) if (s[0][i] != s[1][i]) {
if (s[0][i][0] == '"' && s[1][i][0] == '"')
f1++;
else
f2++;
}
if (f2 || f1 > 1)
cout << "DIFFERENT" << endl;
else if (f1)
cout << "CLOSE" << endl;
else
cout << "IDENTICAL" << endl;
}
}
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 422
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
string s1, s2;
cin >> s1;
if (s1[0] == '.' && s1.size() == 1) {
break;
}
cin >> s2;
string::iterator itr1 = s1.begin(), itr2 = s2.begin();
bool firstdiff = false;
bool is_into_quotation = false;
string ans = "INCOLLECT";
while (1) {
if (*itr1 == '"' && *itr2 == '"') {
if (is_into_quotation) {
is_into_quotation = false;
} else {
is_into_quotation = true;
}
}
if (*itr1 != *itr2) {
if (is_into_quotation && !firstdiff) {
while (*itr1 != '"') {
itr1++;
}
while (*itr2 != '"') {
itr2++;
}
is_into_quotation = false;
firstdiff = true;
} else {
ans = "DIFFERENT";
break;
}
}
itr1++;
itr2++;
if (itr1 == s1.end() && itr2 == s2.end()) {
if (firstdiff) {
ans = "CLOSE";
} else {
ans = "IDENICAL";
}
break;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
string s1, s2;
cin >> s1;
if (s1[0] == '.' && s1.size() == 1) {
break;
}
cin >> s2;
string::iterator itr1 = s1.begin(), itr2 = s2.begin();
bool firstdiff = false;
bool is_into_quotation = false;
string ans = "INCOLLECT";
while (1) {
if (*itr1 == '"' && *itr2 == '"') {
if (is_into_quotation) {
is_into_quotation = false;
} else {
is_into_quotation = true;
}
}
if (*itr1 != *itr2) {
if (is_into_quotation && !firstdiff) {
while (*itr1 != '"') {
itr1++;
}
while (*itr2 != '"') {
itr2++;
}
is_into_quotation = false;
firstdiff = true;
} else {
ans = "DIFFERENT";
break;
}
}
itr1++;
itr2++;
if (itr1 == s1.end() && itr2 == s2.end()) {
if (firstdiff) {
ans = "CLOSE";
} else {
ans = "IDENTICAL";
}
break;
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 0, 9, 0, 1, 0, 11, 12, 5, 0, 6]]
| 1
| 255
|
#include <iostream>
#include <sstream>
using namespace std;
int main() {
while (1) {
string s1, s2;
cin >> s1;
if (s1 == ".")
return 0;
cin >> s2;
string s11[201], s22[201];
for (int i = 0; i < 201; i++) {
s11[i] = ".";
s22[i] = ".";
}
int now1 = 0, now2 = 0;
for (int i = 0; i < (int)s1.length(); i++) {
if (s1[i] == '"') {
now1++;
s11[now1] = "";
} else
s11[now1] += s1[i];
}
for (int i = 0; i < (int)s2.length(); i++) {
if (s2[i] == '"') {
now2++;
s22[now2] = "";
} else
s22[now2] += s2[i];
}
int d = 0;
int maxnow;
if (now1 < now2)
maxnow = now2;
else
maxnow = now1;
for (int i = 0; i < maxnow; i++) {
if (s11[i] != s22[i]) {
if (i & 1) {
d++;
} else
d += 2;
}
}
if (d == 0)
cout << "IDENTICAL";
else if (d == 1)
cout << "CLOSE";
else
cout << "DIFFERENT";
cout << "\n";
}
}
|
#include <iostream>
#include <sstream>
using namespace std;
int main() {
while (1) {
string s1, s2;
cin >> s1;
if (s1 == ".")
return 0;
cin >> s2;
string s11[201], s22[201];
for (int i = 0; i < 201; i++) {
s11[i] = ".";
s22[i] = ".";
}
int now1 = 0, now2 = 0;
for (int i = 0; i < (int)s1.length(); i++) {
if (s1[i] == '"') {
now1++;
s11[now1] = "";
} else
s11[now1] += s1[i];
}
for (int i = 0; i < (int)s2.length(); i++) {
if (s2[i] == '"') {
now2++;
s22[now2] = "";
} else
s22[now2] += s2[i];
}
int d = 0;
int maxnow;
if (now1 < now2)
maxnow = now2;
else
maxnow = now1;
for (int i = 0; i < maxnow + 1; i++) {
if (s11[i] != s22[i]) {
if (i & 1) {
d++;
} else
d += 2;
}
}
if (d == 0)
cout << "IDENTICAL";
else if (d == 1)
cout << "CLOSE";
else
cout << "DIFFERENT";
cout << "\n";
}
}
|
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 321
|
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
#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 mp make_pair
#define fi first
#define sc second
int main() {
string s1, s2;
while (true) {
cin >> s1;
if (s1 == ".")
break;
cin >> s2;
if (s1 == s2) {
cout << "IDENICAL" << endl;
continue;
}
string t1, t2;
t1 = t2 = "";
ll cou1 = 0, cou2 = 0;
vector<string> u1, u2;
REP(i, s1.size()) {
if (s1[i] == '\"') {
i++;
string u = "";
while (s1[i] != '\"') {
u.push_back(s1[i]);
i++;
}
u1.pb(u);
cou1++;
}
if (i < s1.size())
t1.push_back(s1[i]);
}
REP(i, s2.size()) {
if (s2[i] == '\"') {
i++;
string u = "";
while (s2[i] != '\"') {
u.push_back(s2[i]);
i++;
}
u2.pb(u);
cou2++;
}
if (i < s2.size())
t2.push_back(s2[i]);
}
if (t1 != t2 || cou1 != cou2) {
cout << "DIFFERENT" << endl;
continue;
}
ll cou = 0;
REP(i, u1.size()) {
if (u1[i] != u2[i])
cou++;
}
if (cou > 1) {
cout << "DIFFERENT" << endl;
} else {
cout << "CLOSE" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
#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 mp make_pair
#define fi first
#define sc second
int main() {
string s1, s2;
while (true) {
cin >> s1;
if (s1 == ".")
break;
cin >> s2;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
continue;
}
string t1, t2;
t1 = t2 = "";
ll cou1 = 0, cou2 = 0;
vector<string> u1, u2;
REP(i, s1.size()) {
if (s1[i] == '\"') {
i++;
string u = "";
while (s1[i] != '\"') {
u.push_back(s1[i]);
i++;
}
u1.pb(u);
cou1++;
}
if (i < s1.size())
t1.push_back(s1[i]);
}
REP(i, s2.size()) {
if (s2[i] == '\"') {
i++;
string u = "";
while (s2[i] != '\"') {
u.push_back(s2[i]);
i++;
}
u2.pb(u);
cou2++;
}
if (i < s2.size())
t2.push_back(s2[i]);
}
if (t1 != t2 || cou1 != cou2) {
cout << "DIFFERENT" << endl;
continue;
}
ll cou = 0;
REP(i, u1.size()) {
if (u1[i] != u2[i])
cou++;
}
if (cou > 1) {
cout << "DIFFERENT" << endl;
} else {
cout << "CLOSE" << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 460
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int cnt;
string s1, s2, tmp;
vector<string> sv1, sv2;
while (cin >> s1) {
if (s1 == ".") {
break;
}
cin >> s2;
sv1.clear();
sv2.clear();
tmp = "";
cnt = 0;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
} else {
for (int i = 0; i < s1.size() + 1; i++) {
if (s1[i] != '"' && i != s1.size()) {
tmp += s1[i];
} else {
sv1.push_back(tmp);
tmp = "";
}
}
for (int i = 0; i < s2.size() + 1; i++) {
if (s2[i] != '"' && i != s2.size()) {
tmp += s2[i];
} else {
sv2.push_back(tmp);
tmp = "";
}
}
if (sv1.size() != sv2.size()) {
cnt += 2;
} else {
for (int i = 0; i < sv1.size(); i++) {
if (sv1[i] != sv2[i] && i % 2 == 1) {
cnt++;
} else if (sv1[i] != sv2[i]) {
cnt += 2;
break;
}
}
}
cout << ((cnt == 1) ? "CLOSE" : "DEFFERENT") << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int cnt;
string s1, s2, tmp;
vector<string> sv1, sv2;
while (cin >> s1) {
if (s1 == ".") {
break;
}
cin >> s2;
sv1.clear();
sv2.clear();
tmp = "";
cnt = 0;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
} else {
for (int i = 0; i < s1.size() + 1; i++) {
if (s1[i] != '"' && i != s1.size()) {
tmp += s1[i];
} else {
sv1.push_back(tmp);
tmp = "";
}
}
for (int i = 0; i < s2.size() + 1; i++) {
if (s2[i] != '"' && i != s2.size()) {
tmp += s2[i];
} else {
sv2.push_back(tmp);
tmp = "";
}
}
if (sv1.size() != sv2.size()) {
cnt += 2;
} else {
for (int i = 0; i < sv1.size(); i++) {
if (sv1[i] != sv2[i] && i % 2 == 1) {
cnt++;
} else if (sv1[i] != sv2[i]) {
cnt += 2;
break;
}
}
}
cout << ((cnt == 1) ? "CLOSE" : "DIFFERENT") << endl;
}
}
return 0;
}
|
[["-", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6], ["+", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6]]
| 1
| 338
|
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 50;
ll s;
struct Cube {
ll x;
ll y;
ll z;
};
inline ll connected(const Cube &c1, const Cube &c2) {
const ll dx = abs(c1.x - c2.x);
const ll dy = abs(c1.y - c2.y);
const ll dz = abs(c1.z - c2.z);
if (dx < s and dy < s and dz < s) {
return ((s - dx) * (s - dy) + (s - dy) * (s - dz) + (s - dz) * (s - dx)) *
2;
}
return 0;
}
struct Edge {
int from;
int to;
ll cost;
};
struct Graph {
Graph(const int n) { edge.resize(n); }
void addEdge(const int from, const int to, const ll cost) {
edge[from].push_back(Edge{from, to, cost});
edge[to].push_back(Edge{to, from, cost});
}
vector<vector<Edge>> edge;
};
int getEdge(const Graph &g, const int s, vector<bool> &visited) {
visited[s] = true;
int child = 0;
for (const auto &e : g.edge[s]) {
if (not visited[e.to]) {
return getEdge(g, e.to, visited);
}
}
if (child == 0) {
return s;
}
}
struct Chain {
bool ring = false;
vector<ll> edges;
};
ostream &operator<<(ostream &os, const Chain &ch) {
os << "Ring: " << boolalpha << ch.ring << "\nEdge: {";
for (int i = 0; i < ch.edges.size(); i++) {
if (i != 0) {
os << ",";
}
os << ch.edges[i];
}
os << "}" << endl;
return os;
}
void dfs(const Graph &g, const int s, const int dep, vector<bool> &visited,
Chain &chain) {
visited[s] = true;
for (const auto &e : g.edge[s]) {
if (not visited[e.to]) {
chain.edges.push_back(e.cost);
dfs(g, e.to, dep, visited, chain);
}
}
}
int main() {
while (true) {
int n, k;
cin >> n >> k >> s;
if (n == 0 and k == 0 and s == 0) {
break;
}
const ll whole = 6 * s * s * k;
vector<Cube> cube(n);
for (int i = 0; i < n; i++) {
cin >> cube[i].x >> cube[i].y >> cube[i].z;
}
if (k == 1) {
cout << whole << endl;
continue;
}
Graph g(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
const ll cost = connected(cube[i], cube[j]);
if (cost > 0) {
g.addEdge(i, j, cost);
}
}
}
vector<bool> visited(n, false);
vector<Chain> chains;
for (int i = 0; i < n; i++) {
if (not visited[i]) {
vector<bool> visited2(n, false);
const int dep = getEdge(g, i, visited2);
Chain chain;
chain.ring = g.edge[dep].size() == 2;
if (chain.ring) {
chain.edges.push_back(g.edge[dep][1].cost);
}
dfs(g, dep, dep, visited, chain);
chains.push_back(chain);
}
}
ll mini = INF;
for (const auto chain : chains) {
const bool ring = chain.ring;
const vector<ll> &costs = chain.edges;
if (costs.size() < k) {
continue;
}
if (ring) {
ll sum = 0;
for (int i = 0; i < k - 1; i++) {
sum += costs[i];
}
if (costs.size() == k) {
sum += costs[k - 1];
mini = min(mini, whole - sum);
} else {
mini = min(mini, whole - sum);
int head = 0;
int tail = k - 1;
for (int j = 0; j < costs.size();
j++, head++, tail++, tail = tail % costs.size()) {
sum += (costs[tail] - costs[head]);
mini = min(mini, whole - sum);
}
}
} else {
ll sum = 0;
for (int i = 0; i < k - 1; i++) {
sum += costs[i];
}
mini = min(mini, whole - sum);
int head = 0;
int tail = k - 1;
for (; tail < costs.size(); head++, tail++) {
sum += (costs[tail] - costs[head]);
mini = min(mini, whole - sum);
}
}
}
cout << ((mini == INF) ? -1 : mini) << endl;
}
return 0;
}
|
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 50;
ll s;
struct Cube {
ll x;
ll y;
ll z;
};
inline ll connected(const Cube &c1, const Cube &c2) {
const ll dx = abs(c1.x - c2.x);
const ll dy = abs(c1.y - c2.y);
const ll dz = abs(c1.z - c2.z);
if (dx < s and dy < s and dz < s) {
return ((s - dx) * (s - dy) + (s - dy) * (s - dz) + (s - dz) * (s - dx)) *
2;
}
return 0;
}
struct Edge {
int from;
int to;
ll cost;
};
struct Graph {
Graph(const int n) { edge.resize(n); }
void addEdge(const int from, const int to, const ll cost) {
edge[from].push_back(Edge{from, to, cost});
edge[to].push_back(Edge{to, from, cost});
}
vector<vector<Edge>> edge;
};
int getEdge(const Graph &g, const int s, vector<bool> &visited) {
visited[s] = true;
int child = 0;
for (const auto &e : g.edge[s]) {
if (not visited[e.to]) {
return getEdge(g, e.to, visited);
}
}
if (child == 0) {
return s;
}
}
struct Chain {
bool ring = false;
vector<ll> edges;
};
ostream &operator<<(ostream &os, const Chain &ch) {
os << "Ring: " << boolalpha << ch.ring << "\nEdge: {";
for (int i = 0; i < ch.edges.size(); i++) {
if (i != 0) {
os << ",";
}
os << ch.edges[i];
}
os << "}" << endl;
return os;
}
void dfs(const Graph &g, const int s, const int dep, vector<bool> &visited,
Chain &chain) {
visited[s] = true;
for (const auto &e : g.edge[s]) {
if (not visited[e.to]) {
chain.edges.push_back(e.cost);
dfs(g, e.to, dep, visited, chain);
}
}
}
int main() {
while (true) {
int n, k;
cin >> n >> k >> s;
if (n == 0 and k == 0 and s == 0) {
break;
}
const ll whole = 6 * s * s * k;
vector<Cube> cube(n);
for (int i = 0; i < n; i++) {
cin >> cube[i].x >> cube[i].y >> cube[i].z;
}
if (k == 1) {
cout << whole << endl;
continue;
}
Graph g(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
const ll cost = connected(cube[i], cube[j]);
if (cost > 0) {
g.addEdge(i, j, cost);
}
}
}
vector<bool> visited(n, false);
vector<Chain> chains;
for (int i = 0; i < n; i++) {
if (not visited[i]) {
vector<bool> visited2(n, false);
const int dep = getEdge(g, i, visited2);
Chain chain;
chain.ring = g.edge[dep].size() == 2;
if (chain.ring) {
chain.edges.push_back(g.edge[dep][1].cost);
}
dfs(g, dep, dep, visited, chain);
chains.push_back(chain);
}
}
ll mini = INF;
for (const auto chain : chains) {
const bool ring = chain.ring;
const vector<ll> &costs = chain.edges;
if (costs.size() < k - 1) {
continue;
}
if (ring) {
ll sum = 0;
for (int i = 0; i < k - 1; i++) {
sum += costs[i];
}
if (costs.size() == k) {
sum += costs[k - 1];
mini = min(mini, whole - sum);
} else {
mini = min(mini, whole - sum);
int head = 0;
int tail = k - 1;
for (int j = 0; j < costs.size();
j++, head++, tail++, tail = tail % costs.size()) {
sum += (costs[tail] - costs[head]);
mini = min(mini, whole - sum);
}
}
} else {
ll sum = 0;
for (int i = 0; i < k - 1; i++) {
sum += costs[i];
}
mini = min(mini, whole - sum);
int head = 0;
int tail = k - 1;
for (; tail < costs.size(); head++, tail++) {
sum += (costs[tail] - costs[head]);
mini = min(mini, whole - sum);
}
}
}
cout << ((mini == INF) ? -1 : mini) << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 1,187
|
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
int subcube(int len, int x0, int y0, int z0, int x1, int y1, int z1) {
int dx = x0 - x1, dy = y0 - y1, dz = z0 - z1;
int sx = max(min(len + dx, len - dx), 0);
int sy = max(min(len + dy, len - dy), 0);
int sz = max(min(len + dz, len - dz), 0);
return (sx * sy * sz == 0) ? 0 : 2 * (sx * sy + sy * sz + sz * sx);
}
int main() {
int n, k, s;
while (cin >> n >> k >> s, n != 0) {
vector<int> xs(n), ys(n), zs(n);
REP(i, n) { cin >> xs[i] >> ys[i] >> zs[i]; }
if (k == 1)
cout << s * s * 6 * k << endl;
vector<vector<int>> subc(n, vector<int>(n));
REP(a, n) {
REP(b, n) {
if (a == b) { /*cout << "--\t";*/
continue;
}
subc[a][b] = subcube(s, xs[a], ys[a], zs[a], xs[b], ys[b], zs[b]);
// cout << subc[a][b] << "\t";
}
// cout << endl;
}
vector<vector<int>> segs;
vector<int> used(n, false);
/// 4 8 12 16 20
REP(a, n) {
if (used[a])
continue;
vector<int> seg;
int p = a;
bool ok = true;
seg.push_back(p);
used[a] = true;
while (ok) {
ok = false;
REP(b, n) {
if (subc[p][b] > 0) {
if (used[b])
continue;
p = b;
seg.push_back(p);
used[b] = true;
ok = true;
break;
}
}
}
reverse(ALL(seg));
p = a;
ok = true;
while (ok) {
ok = false;
REP(b, n) {
// cout << "?" << a << "->" << b << endl;
if (subc[p][b] > 0) {
if (used[b])
continue;
p = b;
seg.push_back(p);
used[b] = true;
ok = true;
break;
}
}
}
segs.push_back(seg);
}
int res = -1;
REP(i, segs.size()) {
const vector<int> seg(segs[i]);
/*cout << "# "; REP(a, seg.size()) {
cout << seg[a] << " ";
} cout << endl;*/
const int l = seg.size();
if (l < k) {
continue;
}
if (l == k) {
int sum = 0;
if (l == 2) {
res = max(res, subc[seg[0]][seg[1]]);
continue;
}
REP(a, l) {
// cout << "+=" << seg[a] << " " << seg[(a+1)%l] << endl;
// cout << " : " << subc[seg[a]][seg[(a+1)%l]] << endl;
sum += subc[seg[a]][seg[(a + 1) % l]];
}
res = max(res, sum);
continue;
}
int sum = 0;
REP(a, k - 1) { sum += subc[seg[a]][seg[a + 1]]; }
REP(a, l) {
res = max(res, sum);
int ad = subc[seg[(a + k - 1) % l]][seg[(a + k) % l]];
if (ad == 0)
break;
sum += ad;
sum -= subc[seg[(a % l)]][seg[(a + 1) % l]];
}
}
// cout << "$" << subc[0][1] << endl;
// cout << res << endl;
if (res < 0)
cout << res << endl;
else
cout << s * s * 6 * k - res << endl;
}
}
|
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
int subcube(int len, int x0, int y0, int z0, int x1, int y1, int z1) {
int dx = x0 - x1, dy = y0 - y1, dz = z0 - z1;
int sx = max(min(len + dx, len - dx), 0);
int sy = max(min(len + dy, len - dy), 0);
int sz = max(min(len + dz, len - dz), 0);
return (sx * sy * sz == 0) ? 0 : 2 * (sx * sy + sy * sz + sz * sx);
}
int main() {
int n, k, s;
while (cin >> n >> k >> s, n != 0) {
vector<int> xs(n), ys(n), zs(n);
REP(i, n) { cin >> xs[i] >> ys[i] >> zs[i]; }
if (k == 1) {
cout << s * s * 6 * k << endl;
continue;
}
vector<vector<int>> subc(n, vector<int>(n));
REP(a, n) {
REP(b, n) {
if (a == b) { /*cout << "--\t";*/
continue;
}
subc[a][b] = subcube(s, xs[a], ys[a], zs[a], xs[b], ys[b], zs[b]);
// cout << subc[a][b] << "\t";
}
// cout << endl;
}
vector<vector<int>> segs;
vector<int> used(n, false);
/// 4 8 12 16 20
REP(a, n) {
if (used[a])
continue;
vector<int> seg;
int p = a;
bool ok = true;
seg.push_back(p);
used[a] = true;
while (ok) {
ok = false;
REP(b, n) {
if (subc[p][b] > 0) {
if (used[b])
continue;
p = b;
seg.push_back(p);
used[b] = true;
ok = true;
break;
}
}
}
reverse(ALL(seg));
p = a;
ok = true;
while (ok) {
ok = false;
REP(b, n) {
// cout << "?" << a << "->" << b << endl;
if (subc[p][b] > 0) {
if (used[b])
continue;
p = b;
seg.push_back(p);
used[b] = true;
ok = true;
break;
}
}
}
segs.push_back(seg);
}
int res = -1;
REP(i, segs.size()) {
const vector<int> seg(segs[i]);
/*cout << "# "; REP(a, seg.size()) {
cout << seg[a] << " ";
} cout << endl;*/
const int l = seg.size();
if (l < k) {
continue;
}
if (l == k) {
int sum = 0;
if (l == 2) {
res = max(res, subc[seg[0]][seg[1]]);
continue;
}
REP(a, l) {
// cout << "+=" << seg[a] << " " << seg[(a+1)%l] << endl;
// cout << " : " << subc[seg[a]][seg[(a+1)%l]] << endl;
sum += subc[seg[a]][seg[(a + 1) % l]];
}
res = max(res, sum);
continue;
}
int sum = 0;
REP(a, k - 1) { sum += subc[seg[a]][seg[a + 1]]; }
REP(a, l) {
res = max(res, sum);
int ad = subc[seg[(a + k - 1) % l]][seg[(a + k) % l]];
if (ad == 0)
break;
sum += ad;
sum -= subc[seg[(a % l)]][seg[(a + 1) % l]];
}
}
// cout << "$" << subc[0][1] << endl;
// cout << res << endl;
if (res < 0)
cout << res << endl;
else
cout << s * s * 6 * k - res << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 880
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
while (true) {
int n = scan.nextInt();
int m = scan.nextInt();
int t = scan.nextInt();
int p = scan.nextInt();
if (n == 0 && m == 0) {
break;
}
ArrayList<ArrayList<Integer>> paper = new ArrayList<ArrayList<Integer>>();
int hole = 0;
for (int i = 0; i < m; i++) {
ArrayList<Integer> array = new ArrayList<Integer>();
for (int j = 0; j < n; j++) {
array.add(1);
}
paper.add(array);
}
/*
* for (int pap = paper.size() - 1; pap >= 0; pap--) {
* System.out.println(paper.get(pap)); } System.out.println("");
*/
for (int i = 0; i < t; i++) {
int d = scan.nextInt();
int c = scan.nextInt();
switch (d) {
case 1:
for (int j = 0; j < paper.size(); j++) {
for (int k = 0; k < c; k++) {
if (c >= paper.get(j).size()) {
paper.get(j).add(paper.get(j).get(c - k - 1));
} else {
paper.get(j).set(c, paper.get(j).get(c) +
paper.get(j).get(c - k - 1));
}
paper.get(j).remove(c - k - 1);
}
}
break;
case 2:
for (int j = 0; j < c; j++) {
if (c + j >= paper.size()) {
paper.add(paper.get(c - j - 1));
} else {
for (int k = 0; k < paper.get(j).size(); k++) {
paper.get(c).set(k, paper.get(c).get(k) +
paper.get(c - j - 1).get(k));
}
}
paper.remove(c - j - 1);
}
break;
}
/*
* for (int pap = paper.size() - 1; pap >= 0; pap--) {
* System.out.println(paper.get(pap)); } System.out.println("");
*/
}
for (int i = 0; i < p; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
hole = paper.get(y).get(x);
System.out.println(hole);
}
// System.out.println("next");
}
scan.close();
}
}
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
while (true) {
int n = scan.nextInt();
int m = scan.nextInt();
int t = scan.nextInt();
int p = scan.nextInt();
if (n == 0 && m == 0) {
break;
}
ArrayList<ArrayList<Integer>> paper = new ArrayList<ArrayList<Integer>>();
int hole = 0;
for (int i = 0; i < m; i++) {
ArrayList<Integer> array = new ArrayList<Integer>();
for (int j = 0; j < n; j++) {
array.add(1);
}
paper.add(array);
}
// for (int pap = paper.size() - 1; pap >= 0; pap--) {
// System.out.println(paper.get(pap));
//}
// System.out.println("");
for (int i = 0; i < t; i++) {
int d = scan.nextInt();
int c = scan.nextInt();
switch (d) {
case 1:
for (int j = 0; j < paper.size(); j++) {
for (int k = 0; k < c; k++) {
if (c >= paper.get(j).size()) {
paper.get(j).add(paper.get(j).get(c - k - 1));
} else {
paper.get(j).set(c, paper.get(j).get(c) +
paper.get(j).get(c - k - 1));
}
paper.get(j).remove(c - k - 1);
}
}
break;
case 2:
for (int j = 0; j < c; j++) {
if (c >= paper.size()) {
paper.add(paper.get(c - j - 1));
} else {
for (int k = 0; k < paper.get(j).size(); k++) {
paper.get(c).set(k, paper.get(c).get(k) +
paper.get(c - j - 1).get(k));
}
}
paper.remove(c - j - 1);
}
break;
}
// for (int pap = paper.size() - 1; pap >= 0; pap--) {
// System.out.println(paper.get(pap));
//}
// System.out.println("");
}
for (int i = 0; i < p; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
hole = paper.get(y).get(x);
System.out.println(hole);
}
// System.out.println("next");
}
scan.close();
}
}
|
[["-", 0, 57, 15, 15, 0, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 15, 0, 16, 31, 16, 12, 22]]
| 3
| 562
|
#include <bits/stdc++.h>
using namespace std;
int A[200][200];
int main() {
int n, m, t, p;
while (1) {
cin >> n >> m >> t >> p;
if (n == 0 && m == 0 && t == 0 && p == 0)
break;
for (int i = 0; i < 200; i++)
for (int j = 0; j < 200; j++)
A[i][j] = 0;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
A[i][j] = 1;
for (int u = 0; u < t; u++) {
int d, c;
cin >> d >> c;
if (d == 1) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < c; j++) {
int dist = c - j;
A[i][c + dist - 1] += A[i][j];
A[i][j] = 0;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
A[i][j] = A[i][j + c];
}
}
} else {
for (int i = 0; i < c; i++) {
for (int j = 0; j < n; j++) {
int dist = c - i;
A[c + dist - 1][j] += A[i][j];
A[i][j] = 0;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
A[i][j] = A[i + c][j];
}
}
}
}
for (int i = 0; i < p; i++) {
int x, y;
cin >> x >> y;
cout << A[y][x] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int A[200][200];
int main() {
int n, m, t, p;
while (1) {
cin >> n >> m >> t >> p;
if (n == 0 && m == 0 && t == 0 && p == 0)
break;
for (int i = 0; i < 200; i++)
for (int j = 0; j < 200; j++)
A[i][j] = 0;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
A[i][j] = 1;
for (int u = 0; u < t; u++) {
int d, c;
cin >> d >> c;
if (d == 1) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < c; j++) {
int dist = c - j;
A[i][c + dist - 1] += A[i][j];
A[i][j] = 0;
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
A[i][j] = A[i][j + c];
}
}
} else {
for (int i = 0; i < c; i++) {
for (int j = 0; j < n; j++) {
int dist = c - i;
A[c + dist - 1][j] += A[i][j];
A[i][j] = 0;
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
A[i][j] = A[i + c][j];
}
}
}
}
for (int i = 0; i < p; i++) {
int x, y;
cin >> x >> y;
cout << A[y][x] << endl;
}
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 75, 76, 0, 9, 0, 7, 15, 16, 12, 22], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 460
|
s=[]
while 1:
l1=input()
if l1==".":
break
l2=input()
sp1=l1.split('"')
sp2=l2.split('"')
t=0
if len(sp1)==len(sp2):
for i in range(len(sp1)):
if i%2==1 and sp1[i]!=sp2[i]:
t+=1
elif i%2!=1 and sp1[i]!=sp2[i]:
t+=2
if sp1==sp2:
s+=["IDENTCAL"]
elif t==1:
s+=["CLOSE"]
else:
s+=["DIFFERENT"]
for x in s:
print(x)
|
s=[]
while 1:
l1=input()
if l1==".":
break
l2=input()
sp1=l1.split('"')
sp2=l2.split('"')
t=0
if len(sp1)==len(sp2):
for i in range(len(sp1)):
if i%2==1 and sp1[i]!=sp2[i]:
t+=1
elif i%2!=1 and sp1[i]!=sp2[i]:
t+=2
if sp1==sp2:
s+=["IDENTICAL"]
elif t==1:
s+=["CLOSE"]
else:
s+=["DIFFERENT"]
for x in s:
print(x)
|
[["-", 0, 1, 0, 677, 12, 634, 0, 557, 0, 6], ["+", 0, 1, 0, 677, 12, 634, 0, 557, 0, 6]]
| 5
| 152
|
while 1:
s1=input().split('"')
if s1[0]==".":
break
s2=input().split('"')
cnt1=0
cnt2=0
flag=0
if len(s1)!=len(s2):
print("DIFFERENT")
else:
i=0
while i<len(s1):
if s1[i]==s2[i]:
cnt1+=1
elif i%2==0:
print("DIFFERENT")
flag=1
break
else:
cnt2+=1
if cnt2>1:
print("DIFFERENT")
break
i+=1
if flag==1:
break
elif cnt2==1:
print("CLOSE")
elif cnt1==len(s1):
print("IDENTICAL")
|
while 1:
s1=input().split('"')
if s1[0]==".":
break
s2=input().split('"')
cnt1=0
cnt2=0
flag=0
if len(s1)!=len(s2):
print("DIFFERENT")
else:
i=0
while i<len(s1):
if s1[i]==s2[i]:
cnt1+=1
elif i%2==0:
print("DIFFERENT")
flag=1
break
else:
cnt2+=1
if cnt2>1:
print("DIFFERENT")
break
i+=1
if flag==0 and cnt2==1:
print("CLOSE")
if cnt1==len(s1):
print("IDENTICAL")
|
[["-", 75, 76, 8, 196, 0, 57, 15, 666, 0, 612], ["-", 0, 57, 75, 76, 8, 196, 0, 57, 0, 102], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 75, 76, 8, 196, 0, 57, 75, 665, 0, 683], ["+", 8, 196, 0, 57, 15, 679, 31, 666, 0, 612], ["+", 75, 76, 8, 196, 0, 57, 15, 679, 17, 355], ["+", 0, 57, 75, 76, 8, 196, 0, 57, 0, 121]]
| 5
| 159
|
#include <bits/stdc++.h>
using namespace std;
int dx[9] = {0, 0, 1, 1, 1, 0, -1, -1, -1},
dy[9] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int main() {
int d, w;
while (cin >> d >> w, d) {
int e[d][w];
for (int i = 0; i < d; i++) {
for (int j = 0; j < w; j++) {
cin >> e[i][j];
}
}
int ans = 0;
for (int a = 1; a <= 9; a++) {
for (int i = 1; i < d - 1; i++) {
for (int j = 1; j < w - 1; j++) {
if (e[i][j] >= a)
continue;
int y = i, x = j;
while (y + 1 < d - 1 && e[y + 1][j] < a)
y++;
while (x + 1 < w - 1 && e[i][x + 1] < a)
x++;
bool flag = true;
int sum = 0;
// if ( a == 2 ) cout << i << j << y << x << endl;
for (int r = i; r <= y; r++) {
for (int c = j; c <= x; c++) {
sum += a - e[r][c];
for (int k = 0; k < 8; k++) {
int ny = r + dy[k], nx = c + dx[k];
if (k == 0 && e[ny][nx] >= a) {
flag = false;
r = y;
c = x;
break;
}
if ((ny < i || y < ny || nx < j || x < nx) && e[ny][nx] < a) {
flag = false;
r = y;
c = x;
break;
}
}
}
}
if (flag) {
ans = max(ans, sum);
// if ( sum == 22 ) cout << i << " " << j << " " << a << endl;
}
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dx[9] = {0, 0, 1, 1, 1, 0, -1, -1, -1},
dy[9] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int main() {
int d, w;
while (cin >> d >> w, d) {
int e[d][w];
for (int i = 0; i < d; i++) {
for (int j = 0; j < w; j++) {
cin >> e[i][j];
}
}
int ans = 0;
for (int a = 1; a <= 9; a++) {
for (int i = 1; i < d - 1; i++) {
for (int j = 1; j < w - 1; j++) {
if (e[i][j] >= a)
continue;
int y = i, x = j;
while (y + 1 < d - 1 && e[y + 1][j] < a)
y++;
while (x + 1 < w - 1 && e[i][x + 1] < a)
x++;
bool flag = true;
int sum = 0;
// if ( a == 2 ) cout << i << j << y << x << endl;
for (int r = i; r <= y; r++) {
for (int c = j; c <= x; c++) {
sum += a - e[r][c];
for (int k = 0; k < 9; k++) {
int ny = r + dy[k], nx = c + dx[k];
if (k == 0 && e[ny][nx] >= a) {
flag = false;
r = y;
c = x;
break;
}
if ((ny < i || y < ny || nx < j || x < nx) && e[ny][nx] < a) {
flag = false;
r = y;
c = x;
break;
}
}
}
}
if (flag) {
ans = max(ans, sum);
// if ( sum == 22 ) cout << i << " " << j << " " << a << endl;
}
}
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 454
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
int main(void) {
int64 h, w;
while (cin >> h >> w && h + w) {
auto f = make_v<int64>(h, w);
REP(i, h) REP(j, w) cin >> f[i][j];
int64 res = 0;
REP(lu_y, h) {
REP(lu_x, w) {
FOR(rd_y, lu_y + 2, h) {
FOR(rd_x, lu_x + 2, w) {
int64 mini = INF, maxi = 0, sum = 0;
FOR(y, lu_y, rd_y + 1) {
FOR(x, lu_x, rd_x + 1) {
if (y == lu_y || y == rd_y || x == lu_x || x == rd_x)
mini = min(mini, f[y][x]);
else {
maxi = max(maxi, f[y][x]);
sum += f[y][x];
}
}
}
if (maxi < mini)
res = max(res, (rd_x - lu_x - 1) * (rd_y - lu_y - 1) - sum);
}
}
}
}
cout << res << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
int main(void) {
int64 h, w;
while (cin >> h >> w && h + w) {
auto f = make_v<int64>(h, w);
REP(i, h) REP(j, w) cin >> f[i][j];
int64 res = 0;
REP(lu_y, h) {
REP(lu_x, w) {
FOR(rd_y, lu_y + 2, h) {
FOR(rd_x, lu_x + 2, w) {
int64 mini = INF, maxi = 0, sum = 0;
FOR(y, lu_y, rd_y + 1) {
FOR(x, lu_x, rd_x + 1) {
if (y == lu_y || y == rd_y || x == lu_x || x == rd_x)
mini = min(mini, f[y][x]);
else {
maxi = max(maxi, f[y][x]);
sum += f[y][x];
}
}
}
if (maxi < mini)
res =
max(res, (rd_x - lu_x - 1) * (rd_y - lu_y - 1) * mini - sum);
}
}
}
}
cout << res << endl;
}
}
|
[["+", 12, 2, 3, 4, 0, 16, 31, 16, 17, 48], ["+", 12, 2, 3, 4, 0, 16, 31, 16, 12, 22]]
| 1
| 580
|
#include <iostream>
using namespace std;
int d, w;
int cap = 0;
int e[10][10];
int hight_of_ike(int sx, int sy, int col, int row) {
int suii = e[sy][sx];
for (int y = sy; y <= sy + col; ++y) {
for (int x = sx; x <= sx + row; ++x) {
suii = max(suii, e[y][x]);
}
}
return suii;
}
int hight_of_sto(int sx, int sy, int col, int row) {
int hight = e[sx][sy];
for (int y = sy; y <= sy + col; ++y) {
for (int x = sx; x <= sx + row; ++x) {
if (y > sy && y < sy + col && x > sx && x < sx + row)
continue;
hight = min(hight, e[y][x]);
}
}
return hight;
}
int get_cap(int sto, int sx, int sy, int col, int row) {
int tmp = 0;
for (int y = sy; y <= sy + col; ++y) {
for (int x = sx; x <= sx + row; ++x) {
tmp += sto - e[y][x];
}
}
return tmp;
}
int main() {
while (cin >> d >> w, d || w) {
cap = 0;
for (int y = 0; y < d; ++y) {
for (int x = 0; x < w; ++x) {
cin >> e[y][x];
}
}
for (int sy = 1; sy < d - 1; ++sy) {
for (int sx = 1; sx < w - 1; ++sx) {
for (int col = 0; sy + col < d - 1; ++col) {
for (int row = 0; sx + row < w - 1; ++row) {
int ike = hight_of_ike(sx, sy, col, row);
int sto = hight_of_sto(sx - 1, sy - 1, col + 2, row + 2);
if (sto - ike > 0) {
cap = max(cap, get_cap(sto, sx, sy, col, row));
}
}
}
}
}
cout << cap << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int d, w;
int cap = 0;
int e[10][10];
int hight_of_ike(int sx, int sy, int col, int row) {
int suii = e[sy][sx];
for (int y = sy; y <= sy + col; ++y) {
for (int x = sx; x <= sx + row; ++x) {
suii = max(suii, e[y][x]);
}
}
return suii;
}
int hight_of_sto(int sx, int sy, int col, int row) {
int hight = e[sy][sx];
for (int y = sy; y <= sy + col; ++y) {
for (int x = sx; x <= sx + row; ++x) {
if (y > sy && y < sy + col && x > sx && x < sx + row)
continue;
hight = min(hight, e[y][x]);
}
}
return hight;
}
int get_cap(int sto, int sx, int sy, int col, int row) {
int tmp = 0;
for (int y = sy; y <= sy + col; ++y) {
for (int x = sx; x <= sx + row; ++x) {
tmp += sto - e[y][x];
}
}
return tmp;
}
int main() {
while (cin >> d >> w, d || w) {
cap = 0;
for (int y = 0; y < d; ++y) {
for (int x = 0; x < w; ++x) {
cin >> e[y][x];
}
}
for (int sy = 1; sy < d - 1; ++sy) {
for (int sx = 1; sx < w - 1; ++sx) {
for (int col = 0; sy + col < d - 1; ++col) {
for (int row = 0; sx + row < w - 1; ++row) {
int ike = hight_of_ike(sx, sy, col, row);
int sto = hight_of_sto(sx - 1, sy - 1, col + 2, row + 2);
if (sto - ike > 0) {
cap = max(cap, get_cap(sto, sx, sy, col, row));
}
}
}
}
}
cout << cap << endl;
}
return 0;
}
|
[["-", 49, 50, 51, 69, 28, 69, 341, 342, 0, 22], ["+", 49, 50, 51, 69, 28, 69, 341, 342, 0, 22], ["-", 0, 43, 49, 50, 51, 69, 341, 342, 0, 22], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 22]]
| 1
| 506
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[510];
void dfs(int &ans, int tmp, int idx, vector<bool> is_odd) {
// cout << idx << endl;
if (idx == n) {
int ok = true;
for (int i = 0; i < m; i++) {
if (is_odd[i]) {
ok = false;
break;
}
}
if (ok)
ans = max(ans, tmp);
return;
}
//取らない
dfs(ans, tmp, idx + 1, is_odd);
//取る
for (int i = 0; i < m; i++) {
if (s[idx][i] == '1')
is_odd[i] = is_odd[i] ^ 1;
}
dfs(ans, tmp + 1, idx + 1, is_odd);
return;
}
int main() {
while (1) {
cin >> n >> m;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> s[i];
if (n < m) {
//深さ優先
int ans = 0;
vector<bool> is_odd(m, false);
dfs(ans, 0, 0, is_odd);
cout << ans << endl;
} else {
// dp
vector<int> bit(n);
for (int i = 0; i < n; i++) {
int tmp_bit = 0;
for (int j = 0; j < m; j++) {
if (s[i][j] == '1')
tmp_bit = tmp_bit | (1 << j);
}
bit[i] = tmp_bit;
}
vector<vector<int>> dp(2, vector<int>((1 << m), -1000000));
dp[0][0] = 0;
int now = 0;
int next = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++)
dp[next][j] = 0;
for (int j = 0; j < (1 << m); j++) {
//取らない
dp[next][j] = max(dp[next][j], dp[now][j]);
//取る
int next_bit = j ^ bit[i];
// cout << i << " " << j << " " << next_bit << endl;
dp[next][next_bit] = max(dp[next][next_bit], dp[now][j] + 1);
}
swap(now, next);
}
cout << dp[next][0] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s[510];
void dfs(int &ans, int tmp, int idx, vector<bool> is_odd) {
// cout << idx << endl;
if (idx == n) {
int ok = true;
for (int i = 0; i < m; i++) {
if (is_odd[i]) {
ok = false;
break;
}
}
if (ok)
ans = max(ans, tmp);
return;
}
//取らない
dfs(ans, tmp, idx + 1, is_odd);
//取る
for (int i = 0; i < m; i++) {
if (s[idx][i] == '1')
is_odd[i] = is_odd[i] ^ 1;
}
dfs(ans, tmp + 1, idx + 1, is_odd);
return;
}
int main() {
while (1) {
cin >> n >> m;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> s[i];
if (n < m) {
//深さ優先
int ans = 0;
vector<bool> is_odd(m, false);
dfs(ans, 0, 0, is_odd);
cout << ans << endl;
} else {
// dp
vector<int> bit(n);
for (int i = 0; i < n; i++) {
int tmp_bit = 0;
for (int j = 0; j < m; j++) {
if (s[i][j] == '1')
tmp_bit = tmp_bit | (1 << j);
}
bit[i] = tmp_bit;
}
vector<vector<int>> dp(2, vector<int>((1 << m), -1000000));
dp[0][0] = 0;
int now = 0;
int next = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++)
dp[next][j] = -10000;
for (int j = 0; j < (1 << m); j++) {
//取らない
dp[next][j] = max(dp[next][j], dp[now][j]);
//取る
int next_bit = j ^ bit[i];
// cout << i << " " << j << " " << next_bit << endl;
dp[next][next_bit] = max(dp[next][next_bit], dp[now][j] + 1);
}
swap(now, next);
}
cout << dp[now][0] << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 7, 8, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 1, 0, 11, 12, 13], ["-", 31, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["+", 31, 16, 12, 69, 28, 69, 341, 342, 0, 22]]
| 1
| 542
|
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int n, m;
bool b[504];
int c;
bool s[501];
int DP[2][1 << 25];
int bc(int bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
int main() {
while (cin >> n >> m, n | m) {
char a;
rep(i, n) {
rep(j, m) {
cin >> a;
b[i * m + j] = (a == '1');
}
}
if (n < 25) {
int r = 0;
rep(i, 1 << n) {
rep(j, m) s[j] = true;
c = bc(i);
if (c <= r)
continue;
rep(j, n) {
if (i & (1 << j)) {
rep(k, m) {
if (b[j * m + k])
s[k] = !s[k];
}
}
}
bool f = true;
rep(j, m) {
if (!s[j]) {
f = false;
break;
}
}
if (f)
r = i;
}
cout << r << endl;
} else {
c = 0;
rep(j, m) {
if (b[j])
c += 1 << j;
}
rep(i, 1 << m) {
DP[0][i] = -1;
DP[1][i] = -1;
}
DP[0][0] = 0;
DP[0][c] = 1;
for (int i = 1; i < n; i++) {
c = 0;
rep(j, m) {
if (b[i * m + j])
c += 1 << j;
}
rep(j, 1 << m) {
DP[i & 1][j] = DP[(i - 1) & 1][j];
if (DP[(i - 1) & 1][j ^ c] >= 0 &&
DP[(i - 1) & 1][j ^ c] >= DP[i & 1][j])
DP[i & 1][j] = DP[(i - 1) & 1][j ^ c] + 1;
}
}
cout << (DP[(n - 1) % 2][0] < 0 ? 0 : DP[(n - 1) % 2][0]) << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int n, m;
bool b[504];
int c;
bool s[501];
int DP[2][1 << 25];
int bc(int bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
int main() {
while (cin >> n >> m, n | m) {
char a;
rep(i, n) {
rep(j, m) {
cin >> a;
b[i * m + j] = (a == '1');
}
}
if (n < 25) {
int r = 0;
rep(i, 1 << n) {
rep(j, m) s[j] = true;
c = bc(i);
if (c <= r)
continue;
rep(j, n) {
if (i & (1 << j)) {
rep(k, m) {
if (b[j * m + k])
s[k] = !s[k];
}
}
}
bool f = true;
rep(j, m) {
if (!s[j]) {
f = false;
break;
}
}
if (f)
r = c;
}
cout << r << endl;
} else {
c = 0;
rep(j, m) {
if (b[j])
c += 1 << j;
}
rep(i, 1 << m) {
DP[0][i] = -1;
DP[1][i] = -1;
}
DP[0][0] = 0;
DP[0][c] = 1;
for (int i = 1; i < n; i++) {
c = 0;
rep(j, m) {
if (b[i * m + j])
c += 1 << j;
}
rep(j, 1 << m) {
DP[i & 1][j] = DP[(i - 1) & 1][j];
if (DP[(i - 1) & 1][j ^ c] >= 0 &&
DP[(i - 1) & 1][j ^ c] >= DP[i & 1][j])
DP[i & 1][j] = DP[(i - 1) & 1][j ^ c] + 1;
}
}
cout << (DP[(n - 1) % 2][0] < 0 ? 0 : DP[(n - 1) % 2][0]) << endl;
}
}
return 0;
}
|
[["-", 0, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
| 1
| 611
|
#include <assert.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
auto parse = [](const string &exp) {
int i = 0;
function<int()> pp = [&exp, &i, &pp]() {
char c = exp[i++];
switch (c) {
case '0': {
return 0x0000;
}
case '1': {
return 0xffff;
}
case 'a': {
return 0xaaaa;
} // 1010 1010 1010 1010
case 'b': {
return 0xcccc;
} // 1100 1100 1100 1100
case 'c': {
return 0xf0f0;
} // 1111 0000 1111 0000
case 'd': {
return 0xff00;
} // 1111 1111 0000 0000
case '-': {
return (~pp()) & 0xfff;
}
case '(': {
int a = pp();
c = exp[i++];
switch (c) {
case '^': {
int b = a ^ pp(); /* ')' */
i++;
return b;
}
case '*': {
int b = a & pp(); /* ')' */
i++;
return b;
}
}
assert(false);
}
}
};
return pp();
};
/* building answers from the shortest ones
1: 0,1,a,b,c,d
2: -a,-b-c-d
3: x
4: x
5: (_*_), (_^_) # 1+1+3
6: (_*__), (_^__), -(_*_), -(_^_)
7: -(_*__), -(_^__)
8: (__*__), (__^__)
9: (_*_____), (_^_____)
...
*/
vector<string> ans(1 << 16, ""); // redundant. only the length is necessary.
vector<vector<int>> sss;
sss.push_back({});
vector<int> ss1;
for (string s : {"0", "1", "a", "b", "c", "d"}) {
int t = parse(s);
ss1.push_back(t);
ans[t] = s;
}
sss.push_back(move(ss1));
const string str_neg = "-";
const string str_xor = "^";
const string str_and = "*";
for (int i = 2; i <= 16; i++) {
// cout << "building " << i << endl;
vector<int> is;
// negation
for (int s : sss[i - 1]) {
int p = (~s) & 0xffff;
if (ans[p] == "") {
string str = "-" + ans[s];
ans[p] = move(str);
is.push_back(p);
// cout << "pushed " << ans[p] << endl;
}
}
// combination
for (int j = 1; j < i - 3; j++) {
int k = i - j - 3; // i.e., i = k + j + 3
for (int s : sss[j]) {
for (int t : sss[k]) {
{
int p = s ^ t;
if (ans[p] == "") {
string str = "(" + ans[s] + "^" + ans[t] + ")";
ans[p] = move(str);
is.push_back(p);
// cout << "pushed " << ans[p] << endl;
}
}
{
int p = s & t;
if (ans[p] == "") {
string str = "(" + ans[s] + "*" + ans[t] + ")";
ans[p] = move(str);
is.push_back(p);
// cout << "pushed " << ans[p] << endl;
}
}
}
}
}
sss.push_back(is);
}
for (;;) {
string str;
cin >> str;
if (str == ".")
break;
// cout << setfill('0') << setw(4) << hex << parse(str) << endl;
cout << ans[parse(str)].length() << endl;
}
return 0;
}
|
#include <assert.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
auto parse = [](const string &exp) {
int i = 0;
function<int()> pp = [&exp, &i, &pp]() {
char c = exp[i++];
switch (c) {
case '0': {
return 0x0000;
}
case '1': {
return 0xffff;
}
case 'a': {
return 0xaaaa;
} // 1010 1010 1010 1010
case 'b': {
return 0xcccc;
} // 1100 1100 1100 1100
case 'c': {
return 0xf0f0;
} // 1111 0000 1111 0000
case 'd': {
return 0xff00;
} // 1111 1111 0000 0000
case '-': {
return (~pp()) & 0xffff;
}
case '(': {
int a = pp();
c = exp[i++];
switch (c) {
case '^': {
int b = a ^ pp(); /* ')' */
i++;
return b;
}
case '*': {
int b = a & pp(); /* ')' */
i++;
return b;
}
}
assert(false);
}
}
};
return pp();
};
/* building answers from the shortest ones
1: 0,1,a,b,c,d
2: -a,-b-c-d
3: x
4: x
5: (_*_), (_^_) # 1+1+3
6: (_*__), (_^__), -(_*_), -(_^_)
7: -(_*__), -(_^__)
8: (__*__), (__^__)
9: (_*_____), (_^_____)
...
*/
vector<string> ans(1 << 16, ""); // redundant. only the length is necessary.
vector<vector<int>> sss;
sss.push_back({});
vector<int> ss1;
for (string s : {"0", "1", "a", "b", "c", "d"}) {
int t = parse(s);
ss1.push_back(t);
ans[t] = s;
}
sss.push_back(move(ss1));
const string str_neg = "-";
const string str_xor = "^";
const string str_and = "*";
for (int i = 2; i <= 16; i++) {
// cout << "building " << i << endl;
vector<int> is;
// negation
for (int s : sss[i - 1]) {
int p = (~s) & 0xffff;
if (ans[p] == "") {
string str = "-" + ans[s];
ans[p] = move(str);
is.push_back(p);
// cout << "pushed " << ans[p] << endl;
}
}
// combination
for (int j = 1; j < i - 3; j++) {
int k = i - j - 3; // i.e., i = k + j + 3
for (int s : sss[j]) {
for (int t : sss[k]) {
{
int p = s ^ t;
if (ans[p] == "") {
string str = "(" + ans[s] + "^" + ans[t] + ")";
ans[p] = move(str);
is.push_back(p);
// cout << "pushed " << ans[p] << endl;
}
}
{
int p = s & t;
if (ans[p] == "") {
string str = "(" + ans[s] + "*" + ans[t] + ")";
ans[p] = move(str);
is.push_back(p);
// cout << "pushed " << ans[p] << endl;
}
}
}
}
}
sss.push_back(is);
}
for (;;) {
string str;
cin >> str;
if (str == ".")
break;
// cout << "read: " << setfill('0') << setw(4) << hex << parse(str) <<
// endl;
cout << ans[parse(str)].length() << endl;
}
return 0;
}
|
[["-", 0, 100, 0, 9, 0, 37, 0, 16, 12, 13], ["+", 0, 100, 0, 9, 0, 37, 0, 16, 12, 13]]
| 1
| 702
|
#include <stdio.h>
int main() {
long long n, a, b;
char s[100];
while (scanf("%lld %lld %lld", &n, &a, &b), n) {
a--;
b--;
s[n] = 0;
while (n--) {
s[n] = (a % 2 == b % 2) ? 'L' : 'R';
a = (a < (1 << n)) ? (1 << n) - a - 1 : a - (1 << n);
b /= 2;
}
printf("%s\n", s);
}
return 0;
}
|
#include <stdio.h>
int main() {
long long n, a, b;
char s[100];
while (scanf("%lld %lld %lld", &n, &a, &b), n) {
a--;
b--;
s[n] = 0;
while (n--) {
s[n] = (a % 2 == b % 2) ? 'L' : 'R';
a = (a < (1LL << n)) ? (1LL << n) - a - 1 : a - (1LL << n);
b /= 2;
}
printf("%s\n", s);
}
return 0;
}
|
[["-", 15, 23, 0, 16, 12, 23, 0, 16, 31, 13], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 31, 13], ["-", 64, 16, 31, 16, 31, 23, 0, 16, 31, 13], ["+", 64, 16, 31, 16, 31, 23, 0, 16, 31, 13], ["-", 12, 41, 75, 16, 12, 23, 0, 16, 31, 13], ["+", 12, 41, 75, 16, 12, 23, 0, 16, 31, 13]]
| 0
| 134
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
ll POW[61], height[62];
ll N, I, J;
void func() {
ll tmp_h = POW[N] - I + 1;
height[1] = 1;
for (ll i = N; i >= 1; i--) {
height[i + 1] = tmp_h;
if (tmp_h > POW[i] / 2) {
tmp_h = POW[i] - tmp_h + 1;
}
}
queue<char> Q;
ll width, mid, loc = J;
ll k, R_height, L_height, thick;
for (ll i = N; i >= 1; i--) {
k = N - i + 1;
width = POW[i];
mid = width / 2;
thick = POW[k - 1];
tmp_h = height[k];
if (loc <= mid) {
L_height = thick + (thick - tmp_h) + 1;
R_height = tmp_h;
if (L_height == height[k + 1]) {
loc = mid - (loc - 1);
Q.push('L');
} else {
Q.push('R');
}
} else {
L_height = tmp_h;
R_height = thick + (thick - tmp_h) + 1;
if (R_height == height[k + 1]) {
loc = width - loc + 1;
Q.push('R');
} else {
loc -= mid;
Q.push('L');
}
}
}
while (!Q.empty()) {
printf("%c", Q.front());
Q.pop();
}
printf("%\n");
}
int main() {
POW[0] = 1;
for (int i = 1; i < 61; i++)
POW[i] = 2 * POW[i - 1];
while (true) {
scanf("%lld %lld %lld", &N, &I, &J);
if (N == 0 && I == 0 && J == 0)
break;
func();
}
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
ll POW[61], height[62];
ll N, I, J;
void func() {
ll tmp_h = POW[N] - I + 1;
height[1] = 1;
for (ll i = N; i >= 1; i--) {
height[i + 1] = tmp_h;
if (tmp_h > POW[i] / 2) {
tmp_h = POW[i] - tmp_h + 1;
}
}
queue<char> Q;
ll width, mid, loc = J;
ll k, R_height, L_height, thick;
for (ll i = N; i >= 1; i--) {
k = N - i + 1;
width = POW[i];
mid = width / 2;
thick = POW[k - 1];
tmp_h = height[k];
if (loc <= mid) {
L_height = thick + (thick - tmp_h) + 1;
R_height = tmp_h;
if (L_height == height[k + 1]) {
loc = mid - (loc - 1);
Q.push('L');
} else {
Q.push('R');
}
} else {
L_height = tmp_h;
R_height = thick + (thick - tmp_h) + 1;
if (R_height == height[k + 1]) {
loc = width - loc + 1;
Q.push('R');
} else {
loc -= mid;
Q.push('L');
}
}
}
while (!Q.empty()) {
printf("%c", Q.front());
Q.pop();
}
printf("\n");
}
int main() {
POW[0] = 1;
for (int i = 1; i < 61; i++)
POW[i] = 2 * POW[i - 1];
while (true) {
scanf("%lld %lld %lld", &N, &I, &J);
if (N == 0 && I == 0 && J == 0)
break;
func();
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 476
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i, n, sum, avg, count;
while (true) {
sum = 0;
avg = 0;
count = 0;
n = sc.nextInt();
if (n == 0)
break;
int a[] = new int[n];
for (i = 0; i < n; i++) {
a[i] = sc.nextInt();
sum += a[i];
}
avg = sum / n;
for (i = 0; i < n; i++) {
if (a[i] < avg) {
count++;
}
}
System.out.println(count);
}
sc.close();
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i, n, sum, avg, count;
while (true) {
sum = 0;
avg = 0;
count = 0;
n = sc.nextInt();
if (n == 0)
break;
int a[] = new int[n];
for (i = 0; i < n; i++) {
a[i] = sc.nextInt();
sum += a[i];
}
avg = sum / n;
for (i = 0; i < n; i++) {
if (a[i] <= avg) {
count++;
}
}
System.out.println(count);
}
sc.close();
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 19]]
| 3
| 174
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n) \
rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int n;
int sum = 0;
int a[110000];
int main() {
while (true) {
cin >> n;
if (n == 0)
break;
rep(i, n) {
cin >> a[i];
sum += a[i];
}
sum /= n;
int asn = 0;
rep(i, n) {
if (sum >= a[i])
asn++;
}
cout << asn << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n) \
rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int n;
int sum = 0;
int a[110000];
int main() {
while (true) {
sum = 0;
cin >> n;
if (n == 0)
break;
rep(i, n) {
cin >> a[i];
sum += a[i];
}
sum /= n;
int asn = 0;
rep(i, n) {
if (sum >= a[i])
asn++;
}
cout << asn << endl;
}
}
|
[["+", 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
| 242
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t b;
while (cin >> b, b) {
for (int d = sqrt(b); d > 0; --d) {
int64_t a = (2 * b + d - d * d) / (2 * d);
if (a <= 0)
continue;
if ((a + d) * (a + d - 1) - a * (a - 1) == 2 * b) {
cout << a << " " << d << endl;
break;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t b;
while (cin >> b, b) {
for (int64_t d = sqrt(2 * b); d > 0; --d) {
int64_t a = (2 * b + d - d * d) / (2 * d);
if (a <= 0)
continue;
if ((a + d) * (a + d - 1) - a * (a - 1) == 2 * b) {
cout << a << " " << d << endl;
break;
}
}
}
}
|
[["-", 0, 52, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 0, 52, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 31, 13], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 48]]
| 1
| 117
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
void _main() {
int B;
while (cin >> B) {
if (B == 0)
return;
int ans1 = B, ans2 = 1;
rep(n, 2, 101010) {
ll sm = 1LL * n * (n + 1) / 2;
if (B < sm)
break;
int d = B - sm;
if (d % n == 0) {
ans1 = d + 1;
ans2 = n;
}
}
printf("%d %d\n", ans1, ans2);
}
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
void _main() {
int B;
while (cin >> B) {
if (B == 0)
return;
int ans1 = B, ans2 = 1;
rep(n, 2, 101010) {
ll sm = 1LL * n * (n + 1) / 2;
if (B < sm)
break;
int d = B - sm;
if (d % n == 0) {
ans1 = d / n + 1;
ans2 = n;
}
}
printf("%d %d\n", ans1, ans2);
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22]]
| 1
| 273
|
#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
int b;
while (cin >> b, b) {
for (ll l = (1 << 20); l >= 0; l--) {
ll bunshi = b - l * (l + 1) / 2;
ll bunbo = l + 1;
if (bunshi >= 0 && bunshi % bunbo == 0) {
cout << bunshi / bunbo << " " << l + 1 << endl;
break;
}
}
}
return 0;
}
|
#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
int b;
while (cin >> b, b) {
for (ll l = (1 << 20); l >= 0; l--) {
ll bunshi = b - l * (l + 1) / 2;
ll bunbo = l + 1;
if (bunshi > 0 && bunshi % bunbo == 0) {
cout << bunshi / bunbo << " " << l + 1 << endl;
break;
}
}
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 47]]
| 1
| 108
|
#include <iostream>
using namespace std;
long n;
main() {
while (cin >> n, n) {
for (long long w = 4e4; --w;) {
if (n > w * (w - 1) / 2 && (n - w * (w - 1) / 2) % w < 1) {
cout << (n - w * (w - 1) / 2) / w << " " << w << endl;
break;
}
}
}
}
|
#include <iostream>
using namespace std;
long n;
main() {
while (cin >> n, n) {
for (long w = 1e5; --w;) {
if (n > w * (w - 1) / 2 && (n - w * (w - 1) / 2) % w < 1) {
cout << (n - w * (w - 1) / 2) / w << " " << w << endl;
break;
}
}
}
}
|
[["-", 8, 9, 0, 7, 10, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 100
|
//初項をa, 項数をnとして式を立てて, aについて解くと嬉しい。nは2 *
//sqrt(b)くらいまで考えれば十分。
// l+…+rではなくて、a+…+(a+n-1)を考えたくなる理由:(1) nの範囲が小さい, (2)
// 計算しやすい(線形っぽい分解)
#include <iostream>
using namespace std;
int main() {
int b;
while (cin >> b) {
if (b == 0)
break;
int n;
for (n = 50000; n > 0; n--) {
int na = b - n * (n - 1) / 2;
if (na < n || na % n != 0)
continue;
int a = na / n;
cout << a << " " << n << endl;
break;
}
}
return 0;
}
|
//初項をa, 項数をnとして式を立てて, aについて解くと嬉しい。nは2 *
//sqrt(b)くらいまで考えれば十分。
// l+…+rではなくて、a+…+(a+n-1)を考えたくなる理由:(1) nの範囲が小さい, (2)
// 計算しやすい(線形っぽい分解)
#include <iostream>
#define int long long
using namespace std;
signed main() {
int b;
while (cin >> b) {
if (b == 0)
break;
int n;
for (n = 50000; n > 0; n--) {
int na = b - n * (n - 1) / 2;
if (na < n || na % n != 0)
continue;
int a = na / n;
cout << a << " " << n << endl;
break;
}
}
return 0;
}
|
[["+", 36, 36, 36, 36, 0, 30, 0, 58, 0, 148], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 0, 30, 0, 14, 39, 86, 0, 156]]
| 1
| 106
|
while s=gets
n=s.to_i
break if n==0
a=b=r=0
(2..1/0.0).each{|i|
x=n-i*(i-1)/2
break if x<i
if x%i==0
a=x/i
b=i
end
}
puts '%d %d'%[a,b]
end
|
while s=gets
n=s.to_i
break if n==0
a=n;b=1
r=0
(2..1/0.0).each{|i|
x=n-i*(i-1)/2
break if x<i
if x%i==0
a=x/i
b=i
end
}
puts '%d %d'%[a,b]
end
|
[["+", 0, 493, 0, 89, 8, 170, 0, 662, 12, 22], ["+", 36, 36, 0, 493, 0, 89, 8, 170, 0, 35], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 12, 612]]
| 4
| 76
|
while True:
b = int(eval(input()))
if b == 0:
break
n = 1
ans = []
while True:
# print(n)
if n % 2 == 0:
if b % n != 0:
if b // n >= n // 2:
if (b / n * 10) % 5 == 0:
ans = [b // n - n // 2 + 1, n]
else:
break
else:
if b % n == 0:
if b // n - 1 >= (n - 1) // 2:
ans = [b // n - 1 - (n - 1) // 2 + 1, n]
else:
break
n += 1
# print(ans)
print((ans[0], ans[1]))
|
while True:
b = int(input())
if b == 0:
break
n = 1
ans = []
while True:
# print(n)
if n % 2 == 0:
if b % n != 0:
if b // n >= n // 2:
if (b / n * 10) % 5 == 0:
ans = [b // n - n // 2 + 1, n]
else:
break
else:
if b % n == 0:
if b // n - 1 >= (n - 1) // 2:
ans = [b // n - 1 - (n - 1) // 2 + 1, n]
else:
break
n += 1
# print(ans)
print(ans[0], ans[1])
|
[["-", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["-", 0, 1, 0, 652, 3, 4, 0, 660, 0, 24], ["-", 0, 1, 0, 652, 3, 4, 0, 660, 0, 25]]
| 5
| 151
|
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
for (int W = 0; W < (n); W++) \
cerr << v[W] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, i, j) \
{ \
for (int aaa = 0; aaa < i; aaa++) { \
for (int bbb = 0; bbb < j; bbb++) \
cerr << v[aaa][bbb] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
int ans = 0;
int n;
int win[10];
char mp[10][10];
void dfs(int a, int b) {
if (a == n - 1 && b == n - 1) {
ans++;
return;
}
if (b == n) {
a++;
b = 0;
}
if (a == b || mp[a][b] != '-') {
dfs(a, b + 1);
} else {
if (win[a] < (n - 1) / 2) {
mp[a][b] = 'o';
mp[b][a] = 'x';
win[a]++;
dfs(a, b + 1);
win[a]--;
mp[a][b] = '-';
mp[b][a] = '-';
}
if (win[b] < (n - 1) / 2) {
mp[a][b] = 'x';
mp[b][a] = 'o';
win[b]++;
dfs(a, b + 1);
win[b]--;
mp[a][b] = '-';
mp[b][a] = '-';
}
}
}
void solve() {
ans = 0;
REP(i, 10) {
win[i] = 0;
REP(j, 10) { mp[i][j] = '-'; }
}
int m;
cin >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
mp[a][b] = 'o';
mp[b][a] = 'x';
win[a]++;
}
REP(i, n) {
if (win[i] > (n - 1) / 2) {
cout << 0 << endl;
}
}
dfs(0, 0);
cout << ans << endl;
}
int main() {
while (cin >> n, n) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
for (int W = 0; W < (n); W++) \
cerr << v[W] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, i, j) \
{ \
for (int aaa = 0; aaa < i; aaa++) { \
for (int bbb = 0; bbb < j; bbb++) \
cerr << v[aaa][bbb] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
int ans = 0;
int n;
int win[10];
char mp[10][10];
void dfs(int a, int b) {
if (a == n - 1 && b == n - 1) {
ans++;
return;
}
if (b == n) {
a++;
b = 0;
}
if (a == b || mp[a][b] != '-') {
dfs(a, b + 1);
} else {
if (win[a] < (n - 1) / 2) {
mp[a][b] = 'o';
mp[b][a] = 'x';
win[a]++;
dfs(a, b + 1);
win[a]--;
mp[a][b] = '-';
mp[b][a] = '-';
}
if (win[b] < (n - 1) / 2) {
mp[a][b] = 'x';
mp[b][a] = 'o';
win[b]++;
dfs(a, b + 1);
win[b]--;
mp[a][b] = '-';
mp[b][a] = '-';
}
}
}
void solve() {
ans = 0;
REP(i, 10) {
win[i] = 0;
REP(j, 10) { mp[i][j] = '-'; }
}
int m;
cin >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
mp[a][b] = 'o';
mp[b][a] = 'x';
win[a]++;
}
REP(i, n) {
if (win[i] > (n - 1) / 2) {
cout << 0 << endl;
return;
}
}
dfs(0, 0);
cout << ans << endl;
}
int main() {
while (cin >> n, n) {
solve();
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 35]]
| 1
| 544
|
#include <stdio.h>
typedef struct _Gem {
int x;
int y;
bool hit;
} Gem;
static void pick_gem(Gem *g, int n, int x, int y) {
for (int i = 0; i < n; i++) {
if (!g[i].hit && g[i].x == x && g[i].y == y) {
g[i].hit = true;
return;
}
}
}
static bool check_gem(Gem *g, int n) {
for (int i = 0; i < n; i++) {
if (g[i].hit == false) {
return false;
}
}
return true;
}
int main(void) {
char line[80];
int n;
int m;
Gem g[20];
char d[30];
int l[30];
while (true) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d", &n) != 1) {
return 1;
}
if (n == 0) {
break;
}
for (int i = 0; i < n; i++) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) {
return 1;
}
g[i].hit = false;
}
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d", &m) != 1) {
return 1;
}
for (int i = 0; i < m; i++) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) {
return 1;
}
}
int x = 10;
int y = 10;
for (int i = 0; i < m; i++) {
if (d[i] == 'N') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, x, ++y);
}
} else if (d[i] == 'S') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, x, --y);
}
} else if (d[i] == 'E') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, ++x, y);
}
} else {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, --x, y);
}
}
}
printf("%s\n", (check_gem(g, n) ? "YES" : "NO"));
}
return 0;
}
|
#include <stdio.h>
typedef struct _Gem {
int x;
int y;
bool hit;
} Gem;
static void pick_gem(Gem *g, int n, int x, int y) {
for (int i = 0; i < n; i++) {
if (!g[i].hit && g[i].x == x && g[i].y == y) {
g[i].hit = true;
return;
}
}
}
static bool check_gem(Gem *g, int n) {
for (int i = 0; i < n; i++) {
if (g[i].hit == false) {
return false;
}
}
return true;
}
int main(void) {
char line[80];
int n;
int m;
Gem g[20];
char d[30];
int l[30];
while (true) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d", &n) != 1) {
return 1;
}
if (n == 0) {
break;
}
for (int i = 0; i < n; i++) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) {
return 1;
}
g[i].hit = false;
}
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d", &m) != 1) {
return 1;
}
for (int i = 0; i < m; i++) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) {
return 1;
}
}
int x = 10;
int y = 10;
for (int i = 0; i < m; i++) {
if (d[i] == 'N') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, x, ++y);
}
} else if (d[i] == 'S') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, x, --y);
}
} else if (d[i] == 'E') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, ++x, y);
}
} else {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, --x, y);
}
}
}
printf("%s\n", (check_gem(g, n) ? "Yes" : "No"));
}
return 0;
}
|
[["-", 3, 4, 0, 23, 0, 41, 64, 5, 0, 6], ["+", 3, 4, 0, 23, 0, 41, 64, 5, 0, 6], ["-", 3, 4, 0, 23, 0, 41, 75, 5, 0, 6], ["+", 3, 4, 0, 23, 0, 41, 75, 5, 0, 6]]
| 1
| 648
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
string s;
int n, m, x, y;
while (cin >> n && n != 0) {
int c = 0;
int ma[22][22] = {0};
for (int aa = 0; aa < n; aa++) {
cin >> x >> y;
ma[x][y] = 1;
}
cin >> m;
int nx = 10, ny = 10, w;
for (int aa = 0; aa < m; aa++) {
cin >> s >> w;
if (s == "N") {
while (w > 0) {
ny++;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
if (s == "S") {
while (w > 0) {
ny--;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
if (s == "E") {
while (w > 0) {
nx++;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
if (s == "W") {
while (w > 0) {
nx--;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
}
if (n == c)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
string s;
int n, m, x, y;
while (cin >> n && n != 0) {
int c = 0;
int ma[22][22] = {0};
for (int aa = 0; aa < n; aa++) {
cin >> x >> y;
ma[x][y] = 1;
}
cin >> m;
int nx = 10, ny = 10, w;
for (int aa = 0; aa < m; aa++) {
cin >> s >> w;
if (s == "N") {
while (w > 0) {
ny++;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
if (s == "S") {
while (w > 0) {
ny--;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
if (s == "E") {
while (w > 0) {
nx++;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
if (s == "W") {
while (w > 0) {
nx--;
if (ma[nx][ny] == 1) {
ma[nx][ny] = 0;
c++;
}
w--;
}
}
}
if (n == c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 361
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define dbg(x) cout << #x "=" << x << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define INF 1000000000
bool field[21][21];
int main() {
while (true) {
int n, m;
cin >> n;
if (n == 0)
break;
rep(i, 21) rep(j, 21) field[i][j] = false;
rep(i, n) {
int x, y;
scanf("%d %d", &x, &y);
field[x][y] = true;
}
scanf("%d\n", &m);
int x = 10, y = 10;
rep(i, m) {
char c;
int d;
scanf("%c %d\n", &c, &d);
int dx = 0, dy = 0;
switch (c) {
case 'N':
dy = 1;
break;
case 'E':
dx = 1;
break;
case 'S':
dy = -1;
break;
case 'W':
dx = -1;
break;
}
rep(j, d) {
x += dx;
y += dy;
if (field[x][y]) {
n--;
field[x][y] = false;
}
}
}
if (n == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define dbg(x) cout << #x "=" << x << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define INF 1000000000
bool field[21][21];
int main() {
while (true) {
int n, m;
cin >> n;
if (n == 0)
break;
rep(i, 21) { rep(j, 21) field[i][j] = false; }
rep(i, n) {
int x, y;
scanf("%d %d", &x, &y);
field[x][y] = true;
}
scanf("%d\n", &m);
int x = 10, y = 10;
rep(i, m) {
char c;
int d;
scanf("%c %d\n", &c, &d);
int dx = 0, dy = 0;
switch (c) {
case 'N':
dy = 1;
break;
case 'E':
dx = 1;
break;
case 'S':
dy = -1;
break;
case 'W':
dx = -1;
break;
}
rep(j, d) {
x += dx;
y += dy;
if (field[x][y]) {
n--;
field[x][y] = false;
}
}
}
if (n == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
[["+", 8, 9, 0, 52, 8, 9, 0, 9, 0, 45], ["+", 8, 9, 0, 52, 8, 9, 0, 9, 0, 46], ["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 344
|
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 20
int main() {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int x[MAX], y[MAX];
rep(i, n) { cin >> x[i] >> y[i]; }
for (int i = n; i < MAX; i++) {
x[i] = y[i] = -1;
}
int m;
cin >> m;
int rpx = 10, rpy = 10;
for (int i = 0; i < m; i++) {
char d;
int l;
cin >> d >> l;
int dx = 0, dy = 0;
if (d == 'N') {
dy = 1;
} else if (d == 'E') {
dx = 1;
} else if (d == 'S') {
dy = -1;
} else if (d == 'W') {
dx = -1;
}
for (int i = 0; i < l; i++) {
rpx += dx;
rpy += dy;
for (int j = 0; j < n; j++) {
if (rpx == x[j] && rpy == y[j]) {
x[j] = y[j] = -1;
}
}
}
}
bool tf = true;
rep(i, n) {
if (x[i] != -1) {
cout << "No" << '\n';
tf = false;
break;
}
}
if (tf) {
cout << "yes" << '\n';
}
}
}
|
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 20
int main() {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int x[MAX], y[MAX];
rep(i, n) { cin >> x[i] >> y[i]; }
for (int i = n; i < MAX; i++) {
x[i] = y[i] = -1;
}
int m;
cin >> m;
int rpx = 10, rpy = 10;
for (int i = 0; i < m; i++) {
char d;
int l;
cin >> d >> l;
int dx = 0, dy = 0;
if (d == 'N') {
dy = 1;
} else if (d == 'E') {
dx = 1;
} else if (d == 'S') {
dy = -1;
} else if (d == 'W') {
dx = -1;
}
for (int i = 0; i < l; i++) {
rpx += dx;
rpy += dy;
for (int j = 0; j < n; j++) {
if (rpx == x[j] && rpy == y[j]) {
x[j] = y[j] = -1;
}
}
}
}
bool tf = true;
rep(i, n) {
if (x[i] != -1) {
cout << "No" << '\n';
tf = false;
break;
}
}
if (tf) {
cout << "Yes" << '\n';
}
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 341
|
#include <iostream>
using namespace std;
int main(void) {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int stone[21][21];
for (int y = 0; y < 21; y++) {
for (int x = 0; x < 21; x++) {
stone[y][x] = 0;
}
}
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
stone[y][x] = 1;
}
int m;
int x = 10, y = 10;
cin >> m;
for (int i = 0; i < m; i++) {
char d;
int l;
cin >> d;
cin >> l;
for (int j = 0; j < l; j++) {
if (d == 'N') {
y++;
}
if (d == 'E') {
x++;
}
if (d == 'S') {
y--;
}
if (d == 'W') {
x--;
}
if (stone[y][x] == 1) {
stone[y][x] = 0;
n--;
}
}
}
cout << (n == 0 ? "YES" : "NO") << endl;
}
}
|
#include <iostream>
using namespace std;
int main(void) {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int stone[21][21];
for (int y = 0; y < 21; y++) {
for (int x = 0; x < 21; x++) {
stone[y][x] = 0;
}
}
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
stone[y][x] = 1;
}
int m;
int x = 10, y = 10;
cin >> m;
for (int i = 0; i < m; i++) {
char d;
int l;
cin >> d;
cin >> l;
for (int j = 0; j < l; j++) {
if (d == 'N') {
y++;
}
if (d == 'E') {
x++;
}
if (d == 'S') {
y--;
}
if (d == 'W') {
x--;
}
if (stone[y][x] == 1) {
stone[y][x] = 0;
n--;
}
}
}
cout << (n == 0 ? "Yes" : "No") << endl;
}
}
|
[["-", 31, 16, 12, 23, 0, 41, 64, 5, 0, 6], ["+", 31, 16, 12, 23, 0, 41, 64, 5, 0, 6], ["-", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6], ["+", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6]]
| 1
| 281
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long int lli;
typedef pair<int, int> mp;
int main() {
int x[30], y[30];
char d[40];
int l[40];
int n, m;
int mama[30];
while (scanf("%d", &n), n) {
fill(mama, mama + 30, 0);
int rx = 10, ry = 10;
rep(i, n) scanf("%d %d", &x[i], &y[i]);
scanf("%d", &m);
rep(i, m) {
// scanf(" %c%d",&d[i],&l[i]);
cin >> d[i] >> l[i];
if (d[i] == 'N') {
reg(j, ry, ry + l[i]) {
rep(k, n) {
if (x[k] == rx && y[k] == j)
mama[k] = 1;
}
}
ry = ry + l[i];
} else if (d[i] == 'E') {
reg(j, rx, rx + l[i]) {
rep(k, n) {
if (x[k] == j && y[k] == ry)
mama[k] = 1;
}
}
rx = rx + l[i];
} else if (d[i] == 'S') {
reg(j, ry - l[i], ry) {
rep(k, n) {
if (x[k] == rx && y[k] == j)
mama[k] = 1;
}
}
ry = ry - l[i];
} else if (d[i] == 'W') {
reg(j, rx - l[i], rx) {
rep(k, n) {
if (x[k] == j && y[k] == ry)
mama[k] = 1;
}
}
rx = rx - l[i];
}
}
bool yu = true;
rep(i, n) {
if (mama[i] == 0)
yu = false;
}
if (yu)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long int lli;
typedef pair<int, int> mp;
int main() {
int x[30], y[30];
char d[40];
int l[40];
int n, m;
int mama[30];
while (scanf("%d", &n), n) {
fill(mama, mama + 30, 0);
int rx = 10, ry = 10;
rep(i, n) scanf("%d %d", &x[i], &y[i]);
scanf("%d", &m);
rep(i, m) {
// scanf(" %c%d",&d[i],&l[i]);
cin >> d[i] >> l[i];
if (d[i] == 'N') {
reg(j, ry, ry + l[i]) {
rep(k, n) {
if (x[k] == rx && y[k] == j)
mama[k] = 1;
}
}
ry = ry + l[i];
} else if (d[i] == 'E') {
reg(j, rx, rx + l[i]) {
rep(k, n) {
if (x[k] == j && y[k] == ry)
mama[k] = 1;
}
}
rx = rx + l[i];
} else if (d[i] == 'S') {
reg(j, ry - l[i], ry) {
rep(k, n) {
if (x[k] == rx && y[k] == j)
mama[k] = 1;
}
}
ry = ry - l[i];
} else if (d[i] == 'W') {
reg(j, rx - l[i], rx) {
rep(k, n) {
if (x[k] == j && y[k] == ry)
mama[k] = 1;
}
}
rx = rx - l[i];
}
}
bool yu = true;
rep(i, n) {
if (mama[i] == 0)
yu = false;
}
if (yu)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 539
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
while (true) {
int N;
cin >> N;
if (N == 0)
break;
int gems_pos[21][2];
for (int i = 0; i < N; i++) {
cin >> gems_pos[i][0];
cin >> gems_pos[i][1];
}
int M;
cin >> M;
int count = 0;
int x = 10;
int y = 10;
for (int i = 0; i < M; i++) {
char c;
int diff;
cin >> c;
cin >> diff;
int des_x = x;
int des_y = y;
switch (c) {
case 'N':
des_y += diff;
break;
case 'S':
des_y -= diff;
break;
case 'E':
des_x += diff;
break;
case 'W':
des_x -= diff;
break;
}
// debug
// printf("x:%d y:%d\n", des_x, des_y);
for (int i = 0; i < N; i++) {
if (((x <= gems_pos[i][0] && gems_pos[i][0] <= des_x) ||
(des_x <= gems_pos[i][0] && gems_pos[i][0] <= x)) &&
((y <= gems_pos[i][1] && gems_pos[i][1] <= des_y) ||
(des_y <= gems_pos[i][1] && gems_pos[i][1] <= y))) {
count++;
// printf("found\n");
gems_pos[i][0] = -1;
}
}
x = des_x;
y = des_y;
}
if (count == N) {
puts("YES");
} else {
puts("NO");
}
}
}
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
while (true) {
int N;
cin >> N;
if (N == 0)
break;
int gems_pos[21][2];
for (int i = 0; i < N; i++) {
cin >> gems_pos[i][0];
cin >> gems_pos[i][1];
}
int M;
cin >> M;
int count = 0;
int x = 10;
int y = 10;
for (int i = 0; i < M; i++) {
char c;
int diff;
cin >> c;
cin >> diff;
int des_x = x;
int des_y = y;
switch (c) {
case 'N':
des_y += diff;
break;
case 'S':
des_y -= diff;
break;
case 'E':
des_x += diff;
break;
case 'W':
des_x -= diff;
break;
}
// debug
// printf("x:%d y:%d\n", des_x, des_y);
for (int i = 0; i < N; i++) {
if (((x <= gems_pos[i][0] && gems_pos[i][0] <= des_x) ||
(des_x <= gems_pos[i][0] && gems_pos[i][0] <= x)) &&
((y <= gems_pos[i][1] && gems_pos[i][1] <= des_y) ||
(des_y <= gems_pos[i][1] && gems_pos[i][1] <= y))) {
count++;
// printf("found\n");
gems_pos[i][0] = -1;
}
}
x = des_x;
y = des_y;
}
if (count == N) {
puts("Yes");
} else {
puts("No");
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 355
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_N 20
#define MAX_M 30
int main(void) {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int x[MAX_N], y[MAX_M];
REP(i, n) cin >> x[i] >> y[i];
int m;
cin >> m;
bool cnt[MAX_N];
memset(cnt, false, sizeof(cnt));
int mx = 10, my = 10;
REP(i, m) {
string dir;
int dist;
cin >> dir >> dist;
if (dir == "N") {
REP(i, n) {
if (x[i] == mx && my + dist >= y[i] && my <= y[i])
cnt[i] = true;
}
my += dist;
} else if (dir == "E") {
REP(i, n) {
if (y[i] == my && mx + dist >= x[i] && mx <= y[i])
cnt[i] = true;
}
mx += dist;
} else if (dir == "S") {
REP(i, n) {
if (x[i] == mx && my - dist <= y[i] && my >= y[i])
cnt[i] = true;
}
my -= dist;
} else if (dir == "W") {
REP(i, n) {
if (y[i] == my && mx - dist <= x[i] && mx >= x[i])
cnt[i] = true;
}
mx -= dist;
}
}
bool flag = true;
REP(i, n) if (!cnt[i]) flag = false;
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_N 20
#define MAX_M 30
int main(void) {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int x[MAX_N], y[MAX_M];
REP(i, n) cin >> x[i] >> y[i];
int m;
cin >> m;
bool cnt[MAX_N];
memset(cnt, false, sizeof(cnt));
int mx = 10, my = 10;
REP(i, m) {
string dir;
int dist;
cin >> dir >> dist;
if (dir == "N") {
REP(i, n) {
if (x[i] == mx && my + dist >= y[i] && my <= y[i])
cnt[i] = true;
}
my += dist;
} else if (dir == "E") {
REP(i, n) {
if (y[i] == my && mx + dist >= x[i] && mx <= x[i])
cnt[i] = true;
}
mx += dist;
} else if (dir == "S") {
REP(i, n) {
if (x[i] == mx && my - dist <= y[i] && my >= y[i])
cnt[i] = true;
}
my -= dist;
} else if (dir == "W") {
REP(i, n) {
if (y[i] == my && mx - dist <= x[i] && mx >= x[i])
cnt[i] = true;
}
mx -= dist;
}
}
bool flag = true;
REP(i, n) if (!cnt[i]) flag = false;
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 16, 12, 69, 28, 22], ["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 423
|
#include <iostream>
using namespace std;
int main() {
int N;
while (cin >> N, N) {
int m[21][21] = {0};
for (int i = 0; i < N; ++i) {
int x, y;
cin >> x >> y;
++m[x][y];
}
int px = 10, py = 10;
int M;
cin >> M;
int ans = m[px][py];
for (int i = 0; i < M; ++i) {
char d;
int l;
cin >> d >> l;
int dx = d == 'E' ? 1 : d == 'W' ? -1 : 0;
int dy = d == 'N' ? 1 : d == 'S' ? -1 : 0;
for (int j = 0; j < l; ++j) {
px += dx, py += dy;
ans += m[px][py];
m[px][py] = 0;
}
}
if (ans == N)
cout << "Yes" << endl;
else
cout << ans << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int N;
while (cin >> N, N) {
int m[21][21] = {0};
for (int i = 0; i < N; ++i) {
int x, y;
cin >> x >> y;
++m[x][y];
}
int px = 10, py = 10;
int M;
cin >> M;
int ans = m[px][py];
for (int i = 0; i < M; ++i) {
char d;
int l;
cin >> d >> l;
int dx = d == 'E' ? 1 : d == 'W' ? -1 : 0;
int dy = d == 'N' ? 1 : d == 'S' ? -1 : 0;
for (int j = 0; j < l; ++j) {
px += dx, py += dy;
ans += m[px][py];
m[px][py] = 0;
}
}
if (ans == N)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
[["-", 75, 76, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 236
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
typedef long long ll;
typedef pair<int, int> ii;
struct NODE {
int x, y;
NODE() { x = y = 0; }
NODE(int x, int y) : x(x), y(y) {}
};
int main() {
int n;
while (cin >> n, n) {
vector<NODE> vec(n);
vector<bool> ok(n);
rep(i, n) {
int xx, yy;
cin >> xx >> yy;
vec[i] = NODE(xx, yy);
}
int m;
cin >> m;
int x = 10, y = 10;
rep(i, m) {
string way;
int dis;
cin >> way >> dis;
rep(j, dis) {
if (way == "N")
y++;
else if (way == "E")
x++;
else if (way == "W")
x--;
else
y--;
if (DEBUG)
cout << x << "\t" << y << endl;
rep(k, n) if (x == vec[k].x && y == vec[k].y) ok[k] = true;
}
}
bool flag = true;
rep(i, n) flag = (flag & ok[i]);
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
typedef long long ll;
typedef pair<int, int> ii;
struct NODE {
int x, y;
NODE() { x = y = 0; }
NODE(int x, int y) : x(x), y(y) {}
};
int main() {
int n;
while (cin >> n, n) {
vector<NODE> vec(n);
vector<bool> ok(n);
rep(i, n) {
int xx, yy;
cin >> xx >> yy;
vec[i] = NODE(xx, yy);
}
int m;
cin >> m;
int x = 10, y = 10;
rep(i, m) {
string way;
int dis;
cin >> way >> dis;
rep(j, dis) {
if (way == "N")
y++;
else if (way == "E")
x++;
else if (way == "W")
x--;
else
y--;
if (DEBUG)
cout << x << "\t" << y << endl;
rep(k, n) if (x == vec[k].x && y == vec[k].y) ok[k] = true;
}
}
bool flag = true;
rep(i, n) flag = (flag & ok[i]);
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 1
| 341
|
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int h[21][21];
lp(i, 21) {
lp(j, 21) { h[i][j] = 0; }
}
lp(i, n) {
int a, b;
cin >> a >> b;
h[a][b] = 1;
}
int m, count = 0;
cin >> m;
int nowx = 10, nowy = 10;
if (h[nowx][nowy] == 1) {
count++;
h[nowx][nowy] = 0;
}
lp(i, m) {
char a;
int b;
cin >> a >> b;
if (a == 'N') {
lp(j, b) {
nowy++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'S') {
lp(j, b) {
nowy--;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'E') {
lp(j, b) {
nowx++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'W') {
lp(j, b) {
nowx++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
}
if (count == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int h[21][21];
lp(i, 21) {
lp(j, 21) { h[i][j] = 0; }
}
lp(i, n) {
int a, b;
cin >> a >> b;
h[a][b] = 1;
}
int m, count = 0;
cin >> m;
int nowx = 10, nowy = 10;
if (h[nowx][nowy] == 1) {
count++;
h[nowx][nowy] = 0;
}
lp(i, m) {
char a;
int b;
cin >> a >> b;
if (a == 'N') {
lp(j, b) {
nowy++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'S') {
lp(j, b) {
nowy--;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'E') {
lp(j, b) {
nowx++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'W') {
lp(j, b) {
nowx--;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
}
if (count == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 14, 8, 9, 0, 1, 0, 27, 17, 68]]
| 1
| 391
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t;
char o;
while (1) {
int a[30][30] = {}, x, y, gx = 10, gy = 10, count = 0;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> x >> y;
a[y][x] = 1;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> o >> t;
if (o == 'N') {
for (int i = 0; i <= t; i++)
a[gy + i][gx] = 0;
gy += t;
}
if (o == 'S') {
for (int i = 0; i <= t; i++)
a[gy - i][gx] = 0;
gy -= t;
}
if (o == 'E') {
for (int i = 0; i <= t; i++)
a[gy][gx + i] = 0;
gx += t;
}
if (o == 'W') {
for (int i = 0; i <= t; i++)
a[gy][gx - i] = 0;
gx -= t;
}
}
for (int i = 1; i <= 20; i++) {
for (int j = 1; j <= 20; j++) {
if (a[i][j] == 1)
count++;
}
}
if (count == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t;
char o;
while (1) {
int a[30][30] = {}, x, y, gx = 10, gy = 10, count = 0;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> x >> y;
a[y][x] = 1;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> o >> t;
if (o == 'N') {
for (int i = 0; i <= t; i++)
a[gy + i][gx] = 0;
gy += t;
}
if (o == 'S') {
for (int i = 0; i <= t; i++)
a[gy - i][gx] = 0;
gy -= t;
}
if (o == 'E') {
for (int i = 0; i <= t; i++)
a[gy][gx + i] = 0;
gx += t;
}
if (o == 'W') {
for (int i = 0; i <= t; i++)
a[gy][gx - i] = 0;
gx -= t;
}
}
for (int i = 0; i <= 20; i++) {
for (int j = 0; j <= 20; j++) {
if (a[i][j] == 1)
count++;
}
}
if (count == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 359
|
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
vector<string> r;
while (true) {
int gem = 0, gemgot = 0;
int map[21][21] = {{0}};
cin >> gem;
if (gem == 0) {
break;
}
for (int i = 0; i < gem; i++) {
int x = 0, y = 0;
scanf("%d %d", &x, &y);
map[x][y] = 1;
}
int rx = 10, ry = 10;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int d = 0;
int dx = 0, dy = 0;
char dest[8];
scanf("%s %d", dest, &d);
if (dest[0] == 'N') {
dy = 1;
} else if (dest[0] == 'S') {
dy = -1;
} else if (dest[0] == 'W') {
dx = -1;
} else if (dest[0] == 'E') {
dx = 1;
}
for (int j = 0; j < d; j++) {
rx += dx;
ry += dy;
if (map[rx][ry] == 1) {
map[rx][ry] = 0;
gemgot++;
}
}
}
if (gem == gemgot) {
r.push_back("YES");
} else {
r.push_back("NO");
}
}
for (int i = 0; i < r.size(); i++) {
cout << r[i] << endl;
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
vector<string> r;
while (true) {
int gem = 0, gemgot = 0;
int map[21][21] = {{0}};
cin >> gem;
if (gem == 0) {
break;
}
for (int i = 0; i < gem; i++) {
int x = 0, y = 0;
scanf("%d %d", &x, &y);
map[x][y] = 1;
}
int rx = 10, ry = 10;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int d = 0;
int dx = 0, dy = 0;
char dest[8];
scanf("%s %d", dest, &d);
if (dest[0] == 'N') {
dy = 1;
} else if (dest[0] == 'S') {
dy = -1;
} else if (dest[0] == 'W') {
dx = -1;
} else if (dest[0] == 'E') {
dx = 1;
}
for (int j = 0; j < d; j++) {
rx += dx;
ry += dy;
if (map[rx][ry] == 1) {
map[rx][ry] = 0;
gemgot++;
}
}
}
if (gem == gemgot) {
r.push_back("Yes");
} else {
r.push_back("No");
}
}
for (int i = 0; i < r.size(); i++) {
cout << r[i] << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 364
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
typedef pair<string, int> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
bool jewel[21][21];
bool can[21][21];
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int main() {
int n, m;
while (cin >> n && n) {
memset(jewel, false, sizeof(jewel));
memset(can, false, sizeof(can));
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
jewel[x][y] = true;
}
cin >> m;
int c = 0;
int x = 10;
int y = 10;
can[x][y] = true;
for (int i = 0; i < m; i++) {
int d;
int dire;
char to;
cin >> to >> d;
if (to == 'N') {
dire = 0;
} else if (to == 'E') {
dire = 1;
} else if (to == 'S') {
dire = 2;
} else {
dire = 3;
}
for (int j = 0; j < d; j++) {
x += dx[dire];
y += dy[dire];
can[x][y] = true;
}
}
for (int i = 0; i <= 20; i++) {
for (int j = 0; j <= 20; j++)
if (can[i][j] && jewel[i][j])
c++;
}
if (c == n)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
typedef pair<string, int> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
bool jewel[21][21];
bool can[21][21];
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int main() {
int n, m;
while (cin >> n && n) {
memset(jewel, false, sizeof(jewel));
memset(can, false, sizeof(can));
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
jewel[x][y] = true;
}
cin >> m;
int c = 0;
int x = 10;
int y = 10;
can[x][y] = true;
for (int i = 0; i < m; i++) {
int d;
int dire;
char to;
cin >> to >> d;
if (to == 'N') {
dire = 0;
} else if (to == 'E') {
dire = 1;
} else if (to == 'S') {
dire = 2;
} else {
dire = 3;
}
for (int j = 0; j < d; j++) {
x += dx[dire];
y += dy[dire];
can[x][y] = true;
}
}
for (int i = 0; i <= 20; i++) {
for (int j = 0; j <= 20; j++)
if (can[i][j] && jewel[i][j])
c++;
}
if (c == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 477
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
bool gemsOnField[21][21] = {};
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
gemsOnField[y][x] = true;
}
int cx = 10, cy = 10, m;
cin >> m;
for (int i = 0; i < m; i++) {
char d;
int l;
cin.ignore();
cin >> d >> l;
switch (d) {
case 'N':
for (int j = 0; j < l; j++) {
gemsOnField[++cy][cx] = false;
}
break;
case 'E':
for (int j = 0; j < l; j++) {
gemsOnField[cy][++cx] = false;
}
break;
case 'S':
for (int j = 0; j < l; j++) {
gemsOnField[--cy][cx] = false;
}
break;
case 'W':
for (int j = 0; j < l; j++) {
gemsOnField[cy][--cx] = false;
}
break;
}
}
bool isAllGemsRecovered = true;
for (int y = 0; y < 21; y++) {
for (int x = 0; x < 21; x++) {
if (gemsOnField[y][x]) {
isAllGemsRecovered = false;
}
}
}
if (isAllGemsRecovered) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
bool gemsOnField[21][21] = {};
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
gemsOnField[y][x] = true;
}
int cx = 10, cy = 10, m;
cin >> m;
for (int i = 0; i < m; i++) {
char d;
int l;
cin.ignore();
cin >> d >> l;
switch (d) {
case 'N':
for (int j = 0; j < l; j++) {
gemsOnField[++cy][cx] = false;
}
break;
case 'E':
for (int j = 0; j < l; j++) {
gemsOnField[cy][++cx] = false;
}
break;
case 'S':
for (int j = 0; j < l; j++) {
gemsOnField[--cy][cx] = false;
}
break;
case 'W':
for (int j = 0; j < l; j++) {
gemsOnField[cy][--cx] = false;
}
break;
}
}
bool isAllGemsRecovered = true;
for (int y = 0; y < 21; y++) {
for (int x = 0; x < 21; x++) {
if (gemsOnField[y][x]) {
isAllGemsRecovered = false;
}
}
}
if (isAllGemsRecovered) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 353
|
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
int f[21][21];
char news;
int d;
int x, y;
int flag;
while (cin >> n && n) {
for (int i = 1; i < 21; ++i) {
for (int j = 1; j < 21; ++j) {
f[i][j] = 0;
}
}
for (int i = 0; i < n; ++i) {
cin >> x >> y;
f[x][y] = 1;
}
x = 10, y = 10;
f[x][y] = 0;
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> news >> d;
if (news == 'N')
for (int j = 1; j <= d; ++j)
f[x][++y] = 0;
if (news == 'E')
for (int j = 1; j <= d; ++j)
f[++x][y] = 0;
if (news == 'W')
for (int j = 1; j <= d; ++j)
f[--x][y] = 0;
if (news == 'S')
for (int j = 1; j <= d; ++j)
f[x][--y] = 0;
}
flag = 0;
for (int i = 1; i < 21; ++i) {
for (int j = 1; j < 21; ++j) {
if (f[i][j]) {
flag = 1;
break;
}
}
if (flag)
break;
}
if (flag)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
int f[21][21];
char news;
int d;
int x, y;
int flag;
while (cin >> n && n) {
for (int i = 0; i < 21; ++i) {
for (int j = 0; j < 21; ++j) {
f[i][j] = 0;
}
}
for (int i = 0; i < n; ++i) {
cin >> x >> y;
f[x][y] = 1;
}
x = 10, y = 10;
f[x][y] = 0;
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> news >> d;
if (news == 'N')
for (int j = 1; j <= d; ++j)
f[x][++y] = 0;
if (news == 'E')
for (int j = 1; j <= d; ++j)
f[++x][y] = 0;
if (news == 'W')
for (int j = 1; j <= d; ++j)
f[--x][y] = 0;
if (news == 'S')
for (int j = 1; j <= d; ++j)
f[x][--y] = 0;
}
flag = 0;
for (int i = 0; i < 21; ++i) {
for (int j = 0; j < 21; ++j) {
if (f[i][j]) {
flag = 1;
break;
}
}
if (flag)
break;
}
if (flag)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 391
|
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
struct P {
int x, y;
};
vector<P> list;
int input() {
int N;
cin >> N;
if (N == 0)
return false;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
list.push_back(P{a, b});
}
return true;
}
int vx[] = {0, 1, 0, -1};
int vy[] = {1, 0, -1, 0};
bool solve() {
int M;
cin >> M;
P r = P{10, 10};
vector<int> use;
use.resize(list.size());
for (int i = 0; i < use.size(); i++) {
use[i] = 0;
}
for (int i = 0; i < M; i++) {
char c;
int d;
cin >> c >> d;
int v;
switch (c) {
case 'N':
v = 0;
break;
case 'E':
v = 1;
break;
case 'S':
v = 2;
break;
case 'W':
v = 3;
break;
}
int xx = r.x + vx[v] * d;
int yy = r.y + vy[v] * d;
for (int j = 0; j < list.size(); j++) {
if ((yy == r.y &&
((r.x <= list[j].x && list[j].x <= xx && list[j].y == yy) ||
(xx <= list[j].x && list[j].x <= r.x && list[j].y == yy))) ||
(xx == r.x &&
((r.y <= list[j].y && list[j].y <= yy && list[j].x == xx) ||
(yy <= list[j].y && list[j].y <= r.y && list[j].x == xx)))) {
use[j] = true;
}
}
r.x = xx;
r.y = yy;
}
for (int i = 0; i < use.size(); i++) {
if (!use[i])
return false;
}
return true;
}
int main() {
while (input()) {
if (solve()) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
struct P {
int x, y;
};
vector<P> list;
int input() {
int N;
cin >> N;
list.clear();
if (N == 0)
return false;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
list.push_back(P{a, b});
}
return true;
}
int vx[] = {0, 1, 0, -1};
int vy[] = {1, 0, -1, 0};
bool solve() {
int M;
cin >> M;
P r = P{10, 10};
vector<int> use;
use.resize(list.size());
for (int i = 0; i < use.size(); i++) {
use[i] = 0;
}
for (int i = 0; i < M; i++) {
char c;
int d;
cin >> c >> d;
int v;
switch (c) {
case 'N':
v = 0;
break;
case 'E':
v = 1;
break;
case 'S':
v = 2;
break;
case 'W':
v = 3;
break;
}
int xx = r.x + vx[v] * d;
int yy = r.y + vy[v] * d;
for (int j = 0; j < list.size(); j++) {
if ((yy == r.y &&
((r.x <= list[j].x && list[j].x <= xx && list[j].y == yy) ||
(xx <= list[j].x && list[j].x <= r.x && list[j].y == yy))) ||
(xx == r.x &&
((r.y <= list[j].y && list[j].y <= yy && list[j].x == xx) ||
(yy <= list[j].y && list[j].y <= r.y && list[j].x == xx)))) {
use[j] = true;
}
}
r.x = xx;
r.y = yy;
}
for (int i = 0; i < use.size(); i++) {
if (!use[i])
return false;
}
return true;
}
int main() {
while (input()) {
if (solve()) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
| 1
| 566
|
import java.io.*;
import java.util.*;
public class Main {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
public void run() {
boolean[][] map = new boolean[1000][1000];
while (true) {
int n = in.nextInt();
if (n == 0)
break;
for (int i = 0; i < map.length; i++)
Arrays.fill(map[i], false);
for (int i = 0; i < n; i++) {
int x = in.nextInt(), y = in.nextInt();
map[y + 400][x + 400] = true;
}
int res = 0;
int x = 410, y = 410;
int q = in.nextInt();
for (int i = 0; i < q; i++) {
char order = in.next().charAt(0);
int times = in.nextInt();
int vx = order == 'E' ? 1 : order == 'W' ? -1 : 0;
int vy = order == 'N' ? 1 : order == 'S' ? -1 : 0;
for (int j = 0; j < times; j++) {
x += vx;
y += vy;
if (map[y][x]) {
map[y][x] = false;
res++;
}
}
}
System.out.println(res == n ? "YES" : "NO");
}
out.close();
}
public static void main(String[] args) { new Main().run(); }
public void mapDebug(int[][] a) {
System.out.println("--------map display---------");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.printf("%3d ", a[i][j]);
}
System.out.println();
}
System.out.println("----------------------------");
System.out.println();
}
public void debug(Object... obj) {
System.out.println(Arrays.deepToString(obj));
}
class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
// stream = new FileInputStream(new File("dec.in"));
}
int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; }
int nextInt() { return Integer.parseInt(next()); }
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
long nextLong() { return Long.parseLong(next()); }
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
double nextDouble() { return Double.parseDouble(next()); }
double[] nextDoubleArray(int n) {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++)
array[i] = next();
return array;
}
String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
}
}
|
import java.io.*;
import java.util.*;
public class Main {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
public void run() {
boolean[][] map = new boolean[1000][1000];
while (true) {
int n = in.nextInt();
if (n == 0)
break;
for (int i = 0; i < map.length; i++)
Arrays.fill(map[i], false);
for (int i = 0; i < n; i++) {
int x = in.nextInt(), y = in.nextInt();
map[y + 400][x + 400] = true;
}
int res = 0;
int x = 410, y = 410;
int q = in.nextInt();
for (int i = 0; i < q; i++) {
char order = in.next().charAt(0);
int times = in.nextInt();
int vx = order == 'E' ? 1 : order == 'W' ? -1 : 0;
int vy = order == 'N' ? 1 : order == 'S' ? -1 : 0;
for (int j = 0; j < times; j++) {
x += vx;
y += vy;
if (map[y][x]) {
map[y][x] = false;
res++;
}
}
}
System.out.println(res == n ? "Yes" : "No");
}
out.close();
}
public static void main(String[] args) { new Main().run(); }
public void mapDebug(int[][] a) {
System.out.println("--------map display---------");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.printf("%3d ", a[i][j]);
}
System.out.println();
}
System.out.println("----------------------------");
System.out.println();
}
public void debug(Object... obj) {
System.out.println(Arrays.deepToString(obj));
}
class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
// stream = new FileInputStream(new File("dec.in"));
}
int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; }
int nextInt() { return Integer.parseInt(next()); }
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
long nextLong() { return Long.parseLong(next()); }
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
double nextDouble() { return Double.parseDouble(next()); }
double[] nextDoubleArray(int n) {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++)
array[i] = next();
return array;
}
String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
}
}
|
[["-", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["-", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491]]
| 3
| 1,024
|
import java.util.Scanner;
/**
* Created by Reopard on 2014/05/06.
*/
public class Main {
public static void main(String args[]) {
char direction;
int N, M, robot_x, robot_y, distance, count;
int x[] = new int[20];
int y[] = new int[20];
String line;
Scanner sc = new Scanner(System.in);
while (true) {
N = sc.nextInt();
if (N == 0)
break;
for (int i = 0; i < N; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
M = sc.nextInt();
count = 0;
robot_x = 10;
robot_y = 10;
for (int i = 0; i < M; i++) {
line = sc.next();
direction = line.charAt(0);
for (distance = sc.nextInt(); distance > 0; distance--) {
switch (direction) {
case 'N':
robot_y++;
break;
case 'E':
robot_x++;
break;
case 'S':
robot_y--;
break;
case 'W':
robot_x--;
break;
default:
System.exit(0);
}
for (int j = 0; j < N; j++) {
if (robot_x == x[j] && robot_y == y[j]) {
count++;
x[j] = -1;
y[j] = -1;
}
}
}
}
if (count == N)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
|
import java.util.Scanner;
/**
* Created by Reopard on 2014/05/06.
*/
public class Main {
public static void main(String args[]) {
char direction;
int N, M, robot_x, robot_y, distance, count;
int x[] = new int[20];
int y[] = new int[20];
String line;
Scanner sc = new Scanner(System.in);
while (true) {
N = sc.nextInt();
if (N == 0)
break;
for (int i = 0; i < N; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
M = sc.nextInt();
count = 0;
robot_x = 10;
robot_y = 10;
for (int i = 0; i < M; i++) {
line = sc.next();
direction = line.charAt(0);
for (distance = sc.nextInt(); distance > 0; distance--) {
switch (direction) {
case 'N':
robot_y++;
break;
case 'E':
robot_x++;
break;
case 'S':
robot_y--;
break;
case 'W':
robot_x--;
break;
default:
System.exit(0);
}
for (int j = 0; j < N; j++) {
if (robot_x == x[j] && robot_y == y[j]) {
count++;
x[j] = -1;
y[j] = -1;
}
}
}
}
if (count == N)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
|
[["-", 64, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 64, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["-", 75, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 75, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 338
|
#include <stdio.h>
int main() {
int n, m;
int x, y, a, b;
int board[21][21];
int i, j;
char c;
int f;
while (scanf("%d", &n), n) {
x = 10;
y = 10;
f = 0;
for (i = 0; i < 21; i++) {
for (j = 0; j < 21; j++) {
board[i][j] = 0;
}
}
for (i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
board[a][b] = 1;
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%s %d", &c, &a);
for (j = 0; j < a; j++) {
if (c == 'E')
x++;
else if (c == 'S')
y--;
else if (c == 'W')
x--;
else if (c == 'N')
y++;
if (board[x][y] == 1)
board[x][y] = 0;
}
}
for (i = 0; i < 21; i++) {
for (j = 0; j < 21; j++) {
if (board[i][j] == 1)
f = 1;
}
}
if (f == 1)
puts("No");
else
puts("Yeszzzz");
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, m;
int x, y, a, b;
int board[21][21];
int i, j;
char c;
int f;
while (scanf("%d", &n), n) {
x = 10;
y = 10;
f = 0;
for (i = 0; i < 21; i++) {
for (j = 0; j < 21; j++) {
board[i][j] = 0;
}
}
for (i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
board[a][b] = 1;
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%s %d", &c, &a);
for (j = 0; j < a; j++) {
if (c == 'E')
x++;
else if (c == 'S')
y--;
else if (c == 'W')
x--;
else if (c == 'N')
y++;
if (board[x][y] == 1)
board[x][y] = 0;
}
}
for (i = 0; i < 21; i++) {
for (j = 0; j < 21; j++) {
if (board[i][j] == 1)
f = 1;
}
}
if (f == 1)
puts("No");
else
puts("Yes");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 340
|
#include <stdio.h>
#include <string.h>
#define N_MAX 20
#define M_MAX 30
struct MAPS {
int y;
int x;
};
struct COMMAND {
char direction;
int step;
};
int main(int argc, char **argv) {
int N;
int M;
char map[20][20];
struct MAPS gem[N_MAX];
struct COMMAND command[M_MAX];
struct MAPS robot = {10, 10};
int gembag = 0;
int counti, countj;
char inputline[6];
for (counti = 0; counti < 20; counti++) {
for (countj = 0; countj < 20; countj++) {
map[counti][countj] = 0;
}
}
while (1) {
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%d", &N);
if (N == 0)
break;
for (counti = 0; counti < N; counti++) {
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%d%d", &gem[counti].x, &gem[counti].y);
}
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%d", &M);
for (counti = 0; counti < M; counti++) {
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%c%d", &command[counti].direction,
&command[counti].step);
}
for (counti = 0; counti < N; counti++) {
map[gem[counti].y][gem[counti].x] = 1;
}
for (counti = 0; counti < M; counti++) {
switch (command[counti].direction) {
case 'N':
for (countj = 0; countj < command[counti].step; countj++) {
robot.y++;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
case 'E':
for (countj = 0; countj < command[counti].step; countj++) {
robot.x++;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
case 'W':
for (countj = 0; countj < command[counti].step; countj++) {
robot.x--;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
case 'S':
for (countj = 0; countj < command[counti].step; countj++) {
robot.y--;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
}
}
if (gembag == N) {
printf("Yes\n");
} else {
printf("No\n");
}
for (counti = 0; counti < N; counti++) {
map[gem[counti].y][gem[counti].x] = 0;
}
gembag = 0;
robot.x = 10;
robot.y = 10;
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define N_MAX 20
#define M_MAX 30
struct MAPS {
int y;
int x;
};
struct COMMAND {
char direction;
int step;
};
int main(int argc, char **argv) {
int N;
int M;
char map[21][21];
struct MAPS gem[N_MAX];
struct COMMAND command[M_MAX];
struct MAPS robot = {10, 10};
int gembag = 0;
int counti, countj;
char inputline[10];
for (counti = 0; counti < 20; counti++) {
for (countj = 0; countj < 20; countj++) {
map[counti][countj] = 0;
}
}
while (1) {
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%d", &N);
if (N == 0)
break;
for (counti = 0; counti < N; counti++) {
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%d%d", &gem[counti].x, &gem[counti].y);
}
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%d", &M);
for (counti = 0; counti < M; counti++) {
fgets(inputline, sizeof(inputline), stdin);
sscanf(inputline, "%c%d", &command[counti].direction,
&command[counti].step);
}
for (counti = 0; counti < N; counti++) {
map[gem[counti].y][gem[counti].x] = 1;
}
for (counti = 0; counti < M; counti++) {
switch (command[counti].direction) {
case 'N':
for (countj = 0; countj < command[counti].step; countj++) {
robot.y++;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
case 'E':
for (countj = 0; countj < command[counti].step; countj++) {
robot.x++;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
case 'W':
for (countj = 0; countj < command[counti].step; countj++) {
robot.x--;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
case 'S':
for (countj = 0; countj < command[counti].step; countj++) {
robot.y--;
if (map[robot.y][robot.x] == 1) {
map[robot.y][robot.x] = 0;
gembag++;
}
}
break;
}
}
if (gembag == N) {
printf("Yes\n");
} else {
printf("No\n");
}
for (counti = 0; counti < N; counti++) {
map[gem[counti].y][gem[counti].x] = 0;
}
gembag = 0;
robot.x = 10;
robot.y = 10;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
| 0
| 716
|
#include <stdio.h>
int main() {
int map[21][21];
int i, j;
int A, M;
int x, y;
int in1, in2;
char c[2], a;
int dx, dy;
int count;
while (1) {
scanf("%d", &A);
if (A == 0) {
break;
}
for (i = 0; i < 20; i++) {
for (j = 0; j < 20; j++) {
map[i][j] = 0;
}
}
for (i = 0; i < A; i++) {
scanf("%d %d", &in1, &in2);
map[in1][in2] = 1;
}
scanf("%d", &M);
count = 0;
x = 10;
y = 10;
if (map[x][y] == 1) {
map[x][y] = 0;
count++;
}
for (i = 0; i < M; i++) {
scanf("%s %d", c, &in1);
if (c[0] == 'N') {
dx = 0;
dy = 1;
}
if (c[0] == 'S') {
dx = 0;
dy = -1;
}
if (c[0] == 'W') {
dx = -1;
dy = 0;
}
if (c[0] == 'E') {
dx = 1;
dy = 0;
}
for (j = 0; j < in1; j++) {
x += dx;
y += dy;
if (map[x][y] == 1) {
map[x][y] = 0;
count++;
}
}
}
if (count == A) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int map[21][21];
int i, j;
int A, M;
int x, y;
int in1, in2;
char c[2], a;
int dx, dy;
int count;
while (1) {
scanf("%d", &A);
if (A == 0) {
break;
}
for (i = 0; i < 21; i++) {
for (j = 0; j < 21; j++) {
map[i][j] = 0;
}
}
for (i = 0; i < A; i++) {
scanf("%d %d", &in1, &in2);
map[in1][in2] = 1;
}
scanf("%d", &M);
count = 0;
x = 10;
y = 10;
if (map[x][y] == 1) {
map[x][y] = 0;
count++;
}
for (i = 0; i < M; i++) {
scanf("%s %d", c, &in1);
if (c[0] == 'N') {
dx = 0;
dy = 1;
}
if (c[0] == 'S') {
dx = 0;
dy = -1;
}
if (c[0] == 'W') {
dx = -1;
dy = 0;
}
if (c[0] == 'E') {
dx = 1;
dy = 0;
}
for (j = 0; j < in1; j++) {
x += dx;
y += dy;
if (map[x][y] == 1) {
map[x][y] = 0;
count++;
}
}
}
if (count == A) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 397
|
#include <stdio.h>
#include <string.h>
typedef struct {
int x;
int y;
} dir;
int map[21][21];
dir ds[4] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int d2n(char dir) {
return dir == 'N' ? 0 : dir == 'W' ? 1 : dir == 'S' ? 2 : 3;
}
int main() {
int x, y, n, gn, i, st, step, count, j;
char dir, str[29], *s;
st = 0;
do {
fgets(str, 29, stdin);
gn = atoi(str);
if (gn == 0)
break;
st++;
for (i = 0; i < gn; i++) {
fgets(str, 29, stdin);
s = strchr(str, ' ');
*s = '\0';
x = atoi(str);
y = atoi(s + 1);
map[y][x] = st;
}
x = y = 10;
count = (map[y][x] == st) ? 1 : 0;
fgets(str, 29, stdin);
n = atoi(str);
for (i = 0; i < n; i++) {
fgets(str, 29, stdin);
dir = str[0];
step = atoi(str + 2);
for (j = 0; j < step; j++) {
x += ds[d2n(dir)].x;
y += ds[d2n(dir)].y;
if (map[y][x] == st) {
count++;
map[y][x] = 0;
}
}
}
printf("%s\n", (count == gn) ? "YES" : "NO");
} while (1);
return 0;
}
|
#include <stdio.h>
#include <string.h>
typedef struct {
int x;
int y;
} dir;
int map[21][21];
dir ds[4] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int d2n(char dir) {
return dir == 'N' ? 0 : dir == 'W' ? 1 : dir == 'S' ? 2 : 3;
}
int main() {
int x, y, n, gn, i, st, step, count, j;
char dir, str[29], *s;
st = 0;
do {
fgets(str, 29, stdin);
gn = atoi(str);
if (gn == 0)
break;
st++;
for (i = 0; i < gn; i++) {
fgets(str, 29, stdin);
s = strchr(str, ' ');
*s = '\0';
x = atoi(str);
y = atoi(s + 1);
map[y][x] = st;
}
x = y = 10;
count = (map[y][x] == st) ? 1 : 0;
fgets(str, 29, stdin);
n = atoi(str);
for (i = 0; i < n; i++) {
fgets(str, 29, stdin);
dir = str[0];
step = atoi(str + 2);
for (j = 0; j < step; j++) {
x += ds[d2n(dir)].x;
y += ds[d2n(dir)].y;
if (map[y][x] == st) {
count++;
map[y][x] = 0;
}
}
}
printf("%s\n", (count == gn) ? "Yes" : "No");
} while (1);
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 41, 64, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 41, 64, 5, 0, 6], ["-", 0, 2, 3, 4, 0, 41, 75, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 41, 75, 5, 0, 6]]
| 0
| 406
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.