답안 #45161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45161 2018-04-11T15:01:03 Z reality 도서관 (JOI18_library) C++17
100 / 100
657 ms 716 KB
#include "library.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

const int N = (int)(1e6) + 5;

int was[N];

int get(int node,int n) {
	vi cnt;
	for (int i = 0;i < n;++i)
		if (!was[i])
			cnt.pb(i);
	while (cnt.size() != 1) {
		int sz = cnt.size() / 2;
		vi lf,rg;
		for (int i = 0;i < cnt.size();++i)
			if (i < sz)
				lf.pb(cnt[i]);
			else
				rg.pb(cnt[i]);
		vi cur(n,0);
		for (auto it : lf)
			cur[it] = 1;
		int s1 = Query(cur);
		cur[node] = 1;
		int s2 = Query(cur);
		if (s1 == s2)
			cnt = lf;
		else
			cnt = rg;
	}
	return cnt.back();
}
void Solve(int N)
{
	if (N == 1) {
		Answer(vi{1});
		return;
	}
	if (N == 2) {
		Answer(vi{1,2});
		return;
	}
	vi answer;
	int root = -1;
	for (int i = 0;i < N;++i) {
		vi cnt;
		for (int j = 0;j < N;++j)
			if (j != i)
				cnt.pb(1);
			else
				cnt.pb(0);
		if (Query(cnt) == 1)
			root = i;
	}
	answer.pb(root + 1);
	was[root] = 1;
	for (int i = 1;i < N;++i) {
		int nxt = get(root,N);
		answer.pb(nxt + 1);
		root = nxt;
		was[root] = 1;
	}
	Answer(answer);
}

Compilation message

library.cpp: In function 'int get(int, int)':
library.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0;i < cnt.size();++i)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 248 KB Output is correct
2 Correct 49 ms 436 KB Output is correct
3 Correct 37 ms 436 KB Output is correct
4 Correct 30 ms 448 KB Output is correct
5 Correct 51 ms 448 KB Output is correct
6 Correct 56 ms 544 KB Output is correct
7 Correct 43 ms 544 KB Output is correct
8 Correct 47 ms 544 KB Output is correct
9 Correct 40 ms 552 KB Output is correct
10 Correct 31 ms 552 KB Output is correct
11 Correct 2 ms 552 KB Output is correct
12 Correct 2 ms 552 KB Output is correct
13 Correct 2 ms 552 KB Output is correct
14 Correct 2 ms 552 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 7 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 248 KB Output is correct
2 Correct 49 ms 436 KB Output is correct
3 Correct 37 ms 436 KB Output is correct
4 Correct 30 ms 448 KB Output is correct
5 Correct 51 ms 448 KB Output is correct
6 Correct 56 ms 544 KB Output is correct
7 Correct 43 ms 544 KB Output is correct
8 Correct 47 ms 544 KB Output is correct
9 Correct 40 ms 552 KB Output is correct
10 Correct 31 ms 552 KB Output is correct
11 Correct 2 ms 552 KB Output is correct
12 Correct 2 ms 552 KB Output is correct
13 Correct 2 ms 552 KB Output is correct
14 Correct 2 ms 552 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 7 ms 552 KB Output is correct
17 Correct 432 ms 572 KB Output is correct
18 Correct 657 ms 572 KB Output is correct
19 Correct 516 ms 572 KB Output is correct
20 Correct 592 ms 572 KB Output is correct
21 Correct 417 ms 696 KB Output is correct
22 Correct 522 ms 700 KB Output is correct
23 Correct 473 ms 700 KB Output is correct
24 Correct 178 ms 700 KB Output is correct
25 Correct 501 ms 700 KB Output is correct
26 Correct 454 ms 700 KB Output is correct
27 Correct 194 ms 700 KB Output is correct
28 Correct 502 ms 700 KB Output is correct
29 Correct 496 ms 700 KB Output is correct
30 Correct 539 ms 716 KB Output is correct