#include "doll.h"
#ifdef LOCAL
//#ifdef AMOGUS
#include <cstdio>
#include <cstdlib>
namespace {
constexpr int P_MAX = 20000000;
constexpr int S_MAX = 400000;
int M, N;
std::vector<int> A;
bool answered;
int S;
std::vector<int> IC, IX, IY;
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
void wrong_answer(const char *MSG) {
printf("Wrong Answer: %s\n", MSG);
exit(0);
}
void simulate() {
if (S > S_MAX) {
char str[50];
sprintf(str, "over %d switches", S_MAX);
wrong_answer(str);
}
for (int i = 0; i <= M; ++i) {
if (!(-S <= IC[i] && IC[i] <= M)) {
wrong_answer("wrong serial number");
}
}
for (int j = 1; j <= S; ++j) {
if (!(-S <= IX[j - 1] && IX[j - 1] <= M)) {
wrong_answer("wrong serial number");
}
if (!(-S <= IY[j - 1] && IY[j - 1] <= M)) {
wrong_answer("wrong serial number");
}
}
int P = 0;
std::vector<bool> state(S + 1, false);
int pos = IC[0];
int k = 0;
FILE *file_log = fopen("log.txt", "w");
fprintf(file_log, "0\n");
for (;;) {
fprintf(file_log, "%d\n", pos);
if (pos < 0) {
if (++P > P_MAX) {
fclose(file_log);
char str[50];
sprintf(str, "over %d inversions", P_MAX);
wrong_answer(str);
}
state[-pos] = !state[-pos];
pos = state[-pos] ? IX[-(1 + pos)] : IY[-(1 + pos)];
} else {
if (pos == 0) {
break;
}
if (k >= N) {
fclose(file_log);
wrong_answer("wrong motion");
}
if (pos != A[k++]) {
fclose(file_log);
wrong_answer("wrong motion");
}
pos = IC[pos];
}
}
fclose(file_log);
if (k != N) {
wrong_answer("wrong motion");
}
for (int j = 1; j <= S; ++j) {
if (state[j]) {
wrong_answer("state 'Y'");
}
}
printf("Accepted: %d %d\n", S, P);
}
} // namespace
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y) {
if (answered) {
wrong_answer("answered not exactly once");
}
answered = true;
// check if input format is correct
if ((int)C.size() != M + 1) {
wrong_answer("wrong array length");
}
if (X.size() != Y.size()) {
wrong_answer("wrong array length");
}
S = int(X.size());
IC = C;
IX = X;
IY = Y;
}
int main() {
M = read_int();
N = read_int();
A.resize(N);
for (int k = 0; k < N; ++k) {
A[k] = read_int();
}
answered = false;
create_circuit(M, A);
if (!answered) {
wrong_answer("answered not exactly once");
}
FILE *file_out = fopen("out.txt", "w");
fprintf(file_out, "%d\n", S);
for (int i = 0; i <= M; ++i) {
fprintf(file_out, "%d\n", IC[i]);
}
for (int j = 1; j <= S; ++j) {
fprintf(file_out, "%d %d\n", IX[j - 1], IY[j - 1]);
}
fclose(file_out);
simulate();
return 0;
}
#endif
#include <ios>
#include <vector>
#include <cassert>
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, p, n) for(int i=(p); i<=(n); ++i)
#define RFOR(i, p, n) for(int i=(p); i>=(n); --i)
#define V std::vector
#define F std::function
#define sz(A) int(A.size())
#define all(A) A.begin(), A.end()
typedef long long ll;
typedef V <int> vi;
typedef V <ll> vll;
typedef V <bool> vb;
void create_circuit(int M, vi A) {
while (sz(A)&(sz(A)+1))
A.emplace_back(-1);
A.emplace_back(0);
int n = sz(A),comp;
for (comp=1; comp<n; comp<<=1);
int s=comp-1;
vi X(s+1, -1),Y(s+1, -1);
comp>>=1,--comp;
FOR(i, 1, comp)
X[i]=i<<1,Y[i]=(i<<1)+1;
vi ile(s+1, 0);
for (int i : A){
int a=1;
while (a<=comp){
int b=(a<<1)+(ile[a]&1);
++ile[a];
a=b;
}
assert(ile[a]<2);
if (ile[a]&1)
Y[a]=i;
else
X[a]=i;
ile[a]^=1;
}
FOR(i, 1, s)
assert(!(ile[i]&1));
vi C(M+1, -1); // jeszcze 0
FOR(i, 1, comp)
X[i]*=-1,Y[i]*=-1;
X.erase(X.begin()),Y.erase(Y.begin());
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
2 |
Partially correct |
63 ms |
9128 KB |
Output is partially correct |
3 |
Partially correct |
59 ms |
9036 KB |
Output is partially correct |
4 |
Partially correct |
67 ms |
9284 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Output is partially correct |
2 |
Partially correct |
63 ms |
9128 KB |
Output is partially correct |
3 |
Partially correct |
59 ms |
9036 KB |
Output is partially correct |
4 |
Partially correct |
67 ms |
9284 KB |
Output is partially correct |
5 |
Partially correct |
69 ms |
9680 KB |
Output is partially correct |
6 |
Partially correct |
71 ms |
9540 KB |
Output is partially correct |
7 |
Partially correct |
67 ms |
9540 KB |
Output is partially correct |
8 |
Partially correct |
67 ms |
9548 KB |
Output is partially correct |
9 |
Partially correct |
58 ms |
9036 KB |
Output is partially correct |
10 |
Partially correct |
67 ms |
9432 KB |
Output is partially correct |
11 |
Partially correct |
64 ms |
9292 KB |
Output is partially correct |
12 |
Partially correct |
60 ms |
9036 KB |
Output is partially correct |
13 |
Partially correct |
61 ms |
9160 KB |
Output is partially correct |
14 |
Partially correct |
63 ms |
9304 KB |
Output is partially correct |
15 |
Partially correct |
62 ms |
9300 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
604 KB |
Output is partially correct |
17 |
Correct |
33 ms |
5896 KB |
Output is correct |
18 |
Partially correct |
59 ms |
9044 KB |
Output is partially correct |
19 |
Partially correct |
65 ms |
9036 KB |
Output is partially correct |
20 |
Partially correct |
65 ms |
9284 KB |
Output is partially correct |
21 |
Partially correct |
64 ms |
9284 KB |
Output is partially correct |
22 |
Partially correct |
63 ms |
9280 KB |
Output is partially correct |