#include "doll.h"
#include <iostream>
#include <vector>
using namespace std;
#define fort(s,e) for(int i = s; i < e; i++)
//void answer(vector<int>a,vector<int>b,vector<int>c);
void create_circuit(int m, vector<int> a){
int asc = a.size();
a.push_back(0);
vector<int>trig(m+1);
vector<int>xx,yy;
fort(0,m+1){
trig[i] = -1;
}
int asp = 1;
vector<int>dec;
int jl = 0;
while(asc){
jl++;
asp*=2;
dec.push_back(asc%2);
asc/=2;
}
asc = a.size();
for(int i = 0; i < asp/2-1;i++){
xx.push_back(-(i+1)*2);
yy.push_back(-(i+1)*2-1);
}
for(int i = asp/2 - 1;i < asp - 1;i++){
xx.push_back(-1);
yy.push_back(-1);
}
int xl = asp / 2 - asc / 2;
int yl = asp / 2 - asc / 2 - asc % 2;
int l = 0;
for(int i = 0; i < asp;i++){
int ci = i;
int rev = 0;
int j = 0;
while(j < jl){
rev *= 2;
rev += ci % 2;
ci/=2;
j++;
}
if(rev % 2){
if(asp/2 - 1 - rev/2 < xl){
continue;
}
l++;
xx[asp - 2 - rev/2] = a[(int)a.size()-l];
} else {
if(asp/2 - 1 - rev/2 < yl){
continue;
}
l++;
yy[asp - 2 - rev/2] = a[(int)a.size()-l];
}
if(l == (int)a.size()){
break;
}
}
for(int j = (int)yy.size()-1;j>=1;j--){
if(yy[j] == -1){
if((j-1) % 2){
yy[(j-1)/2] = -1;
} else {
xx[(j-1)/2] = -1;
}
}
}
vector<int>table;
int cr = 0;
for(int i = 0; i < asp - 1; i++){
table.push_back(cr);
if(yy[i] != -1){
cr++;
}
}
vector<int> x,y;
for(int i = 0; i < asp - 1; i++){
if(yy[i] != -1){
if(xx[i] < 0){
x.push_back(-table[-xx[i]-1]-1);
} else {
x.push_back(xx[i]);
}
if(yy[i] < 0){
y.push_back(-table[-yy[i]-1]-1);
} else {
y.push_back(yy[i]);
}
}
}
answer(trig,x,y);
return;
}
/*
#include <cstdio>
#include <cstdlib>
FILE * read;
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 (fscanf(read,"%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 = X.size();
IC = C;
IX = X;
IY = Y;
}
int main() {
read = fopen("06-01.txt","r");
if(read == NULL){
cout << "oof" << endl;
return 0;
}
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;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
42 ms |
5296 KB |
Output is correct |
3 |
Correct |
35 ms |
4884 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1356 KB |
Output is correct |
6 |
Correct |
67 ms |
6212 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
42 ms |
5296 KB |
Output is correct |
3 |
Correct |
35 ms |
4884 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1356 KB |
Output is correct |
6 |
Correct |
67 ms |
6212 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
73 ms |
8184 KB |
Output is correct |
9 |
Correct |
71 ms |
8568 KB |
Output is correct |
10 |
Correct |
92 ms |
10808 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
42 ms |
5296 KB |
Output is correct |
3 |
Correct |
35 ms |
4884 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1356 KB |
Output is correct |
6 |
Correct |
67 ms |
6212 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
73 ms |
8184 KB |
Output is correct |
9 |
Correct |
71 ms |
8568 KB |
Output is correct |
10 |
Correct |
92 ms |
10808 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
85 ms |
10392 KB |
Output is correct |
15 |
Correct |
58 ms |
7804 KB |
Output is correct |
16 |
Correct |
105 ms |
10152 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
86 ms |
10468 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
54 ms |
7432 KB |
Output is correct |
3 |
Correct |
60 ms |
7484 KB |
Output is correct |
4 |
Correct |
75 ms |
9524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
54 ms |
7432 KB |
Output is correct |
3 |
Correct |
60 ms |
7484 KB |
Output is correct |
4 |
Correct |
75 ms |
9524 KB |
Output is correct |
5 |
Correct |
101 ms |
10024 KB |
Output is correct |
6 |
Correct |
86 ms |
9852 KB |
Output is correct |
7 |
Correct |
86 ms |
9888 KB |
Output is correct |
8 |
Correct |
83 ms |
9780 KB |
Output is correct |
9 |
Correct |
54 ms |
7420 KB |
Output is correct |
10 |
Correct |
79 ms |
9652 KB |
Output is correct |
11 |
Correct |
79 ms |
9636 KB |
Output is correct |
12 |
Correct |
55 ms |
7452 KB |
Output is correct |
13 |
Correct |
95 ms |
7548 KB |
Output is correct |
14 |
Correct |
55 ms |
7708 KB |
Output is correct |
15 |
Correct |
91 ms |
7820 KB |
Output is correct |
16 |
Correct |
3 ms |
464 KB |
Output is correct |
17 |
Correct |
62 ms |
7720 KB |
Output is correct |
18 |
Correct |
83 ms |
7428 KB |
Output is correct |
19 |
Correct |
56 ms |
7440 KB |
Output is correct |
20 |
Correct |
78 ms |
9652 KB |
Output is correct |
21 |
Correct |
89 ms |
9528 KB |
Output is correct |
22 |
Correct |
112 ms |
9636 KB |
Output is correct |