Created
January 26, 2013 10:39
-
-
Save anonymous/4641619 to your computer and use it in GitHub Desktop.
NEERC2012 B
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <map> | |
#include <vector> | |
#include <bitset> | |
#include <queue> | |
#include <sstream> | |
using namespace std; | |
#define all(v) (v).begin(), (v).end() | |
#define iter(v) __typeof((v).begin()) | |
#define foreach(it, v) for (iter(v) it = (v).begin(); it != (v).end(); it++) | |
#define pb push_back | |
#define mp make_pair | |
#define rep(i, n) for (int i = 0; i < (int)(n); i++) | |
#define AC {puts("accept"); fflush(stdout);} | |
#define DE {puts("decline"); fflush(stdout);} | |
#define ST {puts("stop"); fflush(stdout);} | |
int n, c, x, y, m, step; | |
int a[25]; | |
bool can[1 << 20]; | |
int main() { | |
step = 0; | |
m = 0; | |
scanf("%d%d%d", &n, &c, &x); | |
AC | |
while (x) { | |
scanf("%d", &y); | |
if (y < x) { | |
AC | |
x = y; | |
} else { | |
DE | |
} | |
} | |
while (m < n) { | |
scanf("%d", &y); | |
if (y > x) { | |
AC | |
a[m++] = y - x; | |
x = y; | |
} else { | |
DE | |
} | |
} | |
memset(can, 0, sizeof(can)); | |
int best = -1; | |
rep (mask, 1 << n) { | |
int sum = 0; | |
rep (i, n) if (mask & 1 << i) sum += a[i]; | |
if (sum <= c && sum > best) best = sum; | |
} | |
rep (mask, 1 << n) { | |
int sum = 0; | |
rep (i, n) if (mask & 1 << i) sum += a[i]; | |
if (sum == best) can[mask] = 1; | |
} | |
for (int mask = (1 << n) - 1; mask >= 0; mask--) { | |
if (can[mask]) continue; | |
rep (i, n) { | |
if (!(mask & 1 << i) && can[mask | 1 << i]) { | |
can[mask] = 1; | |
break; | |
} | |
} | |
} | |
while (x) { | |
scanf("%d", &y); | |
if (y < x) { | |
if (!y && !best) { | |
ST | |
return 0; | |
} else { | |
AC | |
} | |
x = y; | |
} else { | |
DE | |
} | |
} | |
int mask = 0; | |
while (x < best) { | |
scanf("%d", &y); | |
if (y < x) { | |
DE; | |
} else { | |
rep (i, n) { | |
if (!(mask & 1 << i) && a[i] == y - x && can[mask | 1 << i]) { | |
if (y != best) AC else ST | |
x = y; | |
mask |= 1 << i; | |
goto DONE; | |
} | |
} | |
DE; | |
DONE:; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment