답안 #1094519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094519 2024-09-29T18:14:22 Z Math4Life2020 자동 인형 (IOI18_doll) C++17
100 / 100
83 ms 9456 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
const int INF = 1e9;
 
int v2(int x) {
	return __builtin_ctz(x);
}
 
int l2(int x) {
	return (31-__builtin_clz(x));
}
 
void create_circuit(int M, vector<int> A) {
	int N = A.size();
	vector<int> C;
	C.push_back(A[0]);
	for (int i=0;i<M;i++) {
		C.push_back(-1);
	}
	vector<int> X,Y;
	int CIND = 0;
	int D = l2(2*N-1);
	stack<pii> bd;
	bd.push({N,D});
	while (!bd.empty()) {
		pii p0 = bd.top(); bd.pop();
		int k = p0.first; int d = p0.second;
		if (d<=1) {
			if (k==1) {
				X.push_back(0);
				Y.push_back(-INF);
			} else if (k==2) {
				X.push_back(-INF);
				Y.push_back(-INF);
			} else {
				cout << "reporting error #1\n";
			}
		} else {
			if (k>(1<<(d-1))) {
				Y.push_back(CIND+1);
				X.push_back(CIND+(1<<(d-1)));
				bd.push({k-(1<<(d-1)),d-1});
				bd.push({(1<<(d-1)),d-1});
			} else {
				X.push_back(0);
				Y.push_back(CIND+1);
				bd.push({k,d-1});
			}
		}
		CIND++;
	}
 
	/*cout << "INIT: print C:\n";
	for (int c: C) {
		cout << c <<" ";
	}
	cout << "\nprint X: \n";
	for (int x: X) {
		cout << x << " ";
	}
	cout << "\nprint Y: \n";
	for (int y: Y) {
		cout << y << " ";
	}*/
 
	vector<bool> st;
	for (int t=0;t<(1e6);t++) {
		st.push_back(false);
	}
	for (int t=0;t<N;t++) {
		int cx = 0;
		int locp = -1;
		bool stp = 0;
		while (cx >= 0) {
			if (st[cx]==0) {
				st[cx]=1;
				locp = cx;
				stp = 0;
				cx = X[cx];
			} else {
				st[cx]=0;
				locp = cx;
				stp = 1;
				cx = Y[cx];
			}
		}
		if (cx != -INF) {
			cout << "invalid value\n";
		} else {
			int nval;
			if (t<(N-1)) {
				nval = A[t+1];
			} else {
				nval = 0;
			}
			nval++;
			if (stp==0) {
				X[locp]=-INF+nval;
			} else {
				Y[locp]=-INF+nval;
			}
		}
	}
    for (int d=0;d<X.size();d++) {
		if (X[d]>=0) {
			X[d]=-1-X[d];
		} else {
			X[d]=X[d]-(-INF+1);
		}
		if (Y[d]>=0) {
			Y[d]=-1-Y[d];
		} else {
			Y[d]=Y[d]-(-INF+1);
		}
	}
	/*cout << "print C:\n";
	for (int c: C) {
		cout << c <<" ";
	}
	cout << "\nprint X: \n";
	for (int x: X) {
		cout << x << " ";
	}
	cout << "\nprint Y: \n";
	for (int y: Y) {
		cout << y << " ";
	}
	cout << "\n";*/
	answer(C,X,Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:106:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int d=0;d<X.size();d++) {
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 28 ms 4484 KB Output is correct
3 Correct 26 ms 3968 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 7 ms 1800 KB Output is correct
6 Correct 41 ms 5648 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 28 ms 4484 KB Output is correct
3 Correct 26 ms 3968 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 7 ms 1800 KB Output is correct
6 Correct 41 ms 5648 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 59 ms 6264 KB Output is correct
9 Correct 54 ms 6920 KB Output is correct
10 Correct 83 ms 9456 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 28 ms 4484 KB Output is correct
3 Correct 26 ms 3968 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 7 ms 1800 KB Output is correct
6 Correct 41 ms 5648 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 59 ms 6264 KB Output is correct
9 Correct 54 ms 6920 KB Output is correct
10 Correct 83 ms 9456 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 76 ms 9116 KB Output is correct
15 Correct 51 ms 6020 KB Output is correct
16 Correct 76 ms 8984 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 78 ms 9368 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 44 ms 4592 KB Output is correct
3 Correct 48 ms 5752 KB Output is correct
4 Correct 72 ms 8208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 44 ms 4592 KB Output is correct
3 Correct 48 ms 5752 KB Output is correct
4 Correct 72 ms 8208 KB Output is correct
5 Correct 77 ms 8728 KB Output is correct
6 Correct 76 ms 8464 KB Output is correct
7 Correct 75 ms 8472 KB Output is correct
8 Correct 73 ms 8448 KB Output is correct
9 Correct 48 ms 5644 KB Output is correct
10 Correct 76 ms 8232 KB Output is correct
11 Correct 72 ms 8204 KB Output is correct
12 Correct 48 ms 5644 KB Output is correct
13 Correct 50 ms 5840 KB Output is correct
14 Correct 49 ms 5820 KB Output is correct
15 Correct 51 ms 5908 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 45 ms 5564 KB Output is correct
18 Correct 48 ms 5732 KB Output is correct
19 Correct 48 ms 5648 KB Output is correct
20 Correct 74 ms 8200 KB Output is correct
21 Correct 80 ms 8208 KB Output is correct
22 Correct 76 ms 8208 KB Output is correct