답안 #436203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436203 2021-06-24T10:23:50 Z AmineTrabelsi 도서관 (JOI18_library) C++14
19 / 100
690 ms 496 KB
#include <cstdio>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

void Solve(int N){
	vector<int> M(N);
	vector<int> res(N);
	vector<deque<int>> curr;
	vector<bool> rem(N+1,0);
	curr.push_back({1});
	int prev = 1;
	M[0] = 1;
	for(int i=2;i<=N;i++){
		M[i-1] = 1;
		int q = Query(M);
		if(q > prev){
			curr.push_back({i});
			prev = q;
		}else{
			vector<int> side;
			for(int c=0;c<(int)curr.size();c++){
				if(rem[c])continue;
				vector<int> m(N);
				m[i-1] = 1;
				for(auto cc:curr[c])m[cc-1] = 1;
				if(Query(m) == 1)side.push_back(c);
			}
			vector<int> m(N);
			m[i-1] = 1;
			for(auto cc:curr[side[0]])m[cc-1] = 1;
			bool pos = 0;
			if(curr[side[0]].size() > 1){
				m[curr[side[0]].back()-1] = 0;
				int q = Query(m);
				m[curr[side[0]].back()-1] = 1;
				if(q == 1){
					curr[side[0]].push_front(i);
				}else{
					pos = 1;
					curr[side[0]].push_back(i);
				}
			}else{
				curr[side[0]].push_front(i);
			}
			if((int)side.size() == 2){
				curr.push_back(deque<int>());
				rem[side[1]] = 1;
				rem[side[0]] = 1;
				int c = curr[side[1]].front(),d = curr[side[1]].back();
				if(pos){
					m[c-1] = 1;
					q = Query(m);
					for(auto cc:curr[side[0]])curr.back().push_back(cc);
					if(q == 1){
						for(auto cc:curr[side[1]])curr.back().push_back(cc);
					}else 
						{
						reverse(curr[side[1]].begin(),curr[side[1]].end());
						for(auto cc:curr[side[1]])curr.back().push_back(cc);
						}
				}else{
					m[d-1] = 1;
					q = Query(m);
					if(q == 1){
						for(auto cc:curr[side[1]])curr.back().push_back(cc);
						for(auto cc:curr[side[0]])curr.back().push_back(cc);
					}else{
						reverse(curr[side[1]].begin(),curr[side[1]].end());
						for(auto cc:curr[side[1]])curr.back().push_back(cc);
						for(auto cc:curr[side[0]])curr.back().push_back(cc);
					}
				}
				prev--;
			}
		}
		/*
		for(int c=0;c<(int)curr.size();c++){
			if(!rem[c]){
			for(auto j:curr[c]){
				cerr << j<<" ";
			}
			cerr << '\n';
			}
		}
		cerr<<"out\n";*/
		
	}
	res = vector<int>(curr.back().begin(),curr.back().end());
	Answer(res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 328 KB # of queries: 4635
2 Correct 86 ms 332 KB # of queries: 4835
3 Correct 70 ms 452 KB # of queries: 5106
4 Correct 111 ms 372 KB # of queries: 5241
5 Correct 95 ms 368 KB # of queries: 5130
6 Correct 87 ms 456 KB # of queries: 4995
7 Correct 103 ms 380 KB # of queries: 5144
8 Correct 68 ms 352 KB # of queries: 4563
9 Correct 124 ms 364 KB # of queries: 5329
10 Correct 31 ms 328 KB # of queries: 2210
11 Correct 1 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 2
13 Correct 1 ms 200 KB # of queries: 5
14 Correct 1 ms 200 KB # of queries: 8
15 Correct 2 ms 200 KB # of queries: 56
16 Correct 4 ms 200 KB # of queries: 159
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 328 KB # of queries: 4635
2 Correct 86 ms 332 KB # of queries: 4835
3 Correct 70 ms 452 KB # of queries: 5106
4 Correct 111 ms 372 KB # of queries: 5241
5 Correct 95 ms 368 KB # of queries: 5130
6 Correct 87 ms 456 KB # of queries: 4995
7 Correct 103 ms 380 KB # of queries: 5144
8 Correct 68 ms 352 KB # of queries: 4563
9 Correct 124 ms 364 KB # of queries: 5329
10 Correct 31 ms 328 KB # of queries: 2210
11 Correct 1 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 2
13 Correct 1 ms 200 KB # of queries: 5
14 Correct 1 ms 200 KB # of queries: 8
15 Correct 2 ms 200 KB # of queries: 56
16 Correct 4 ms 200 KB # of queries: 159
17 Runtime error 690 ms 496 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -