Submission #44799

# Submission time Handle Problem Language Result Execution time Memory
44799 2018-04-06T13:56:42 Z tjd229 Library (JOI18_library) C++14
100 / 100
473 ms 700 KB
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;

bool use[2000];
void Solve(int N)
{
	vector<int> M(N);
	vector<int> res;
	vector<int> bitset[10];
	int a[10] = { 0 };
	int cnt[10] = { 0 };
	int i, j;
	int A=N;
	int lgN = 0;
	while (A != 0){
		lgN++;
		A >>= 1;
	}
	if (N == 1){
		res.push_back(1);
		Answer(res);
		return;
	}
	for (i = 0; i < N; i++) {
		M[i] = 1;
	}
	for (i = 0; i < N; i++){
		M[i] = 0;
		A = Query(M);
		if (A == 1){
			res.push_back(i + 1);
			use[i] = 1;
			break;
		}
		M[i] = 1;
	}
	for (i = 0; i < lgN; i++) bitset[i].resize(N, 0);
	for (i = 0; i < N; i++){
		if (use[i]) continue;
		j = 0;
		A = i+1;
		while (A != 0){
			if (A & 1) bitset[j][i] = 1,cnt[j]++;
			A >>= 1;
			j++;
		}
	}
	for (i = 0; i < lgN; i++){
		if (cnt[i])
			a[i] = Query(bitset[i]);
	}
	for (i = 1; i < N; i++){
		int bit = 0;
		int last = res.back() - 1;
		for (j = 0; j < lgN; j++){
			if (cnt[j] == 0) continue;
			bitset[j][last] = 1;
			A = Query(bitset[j]);
			if (A == a[j]) bit |= (1 << j);
			bitset[j][last] = 0;
		}
		
		res.push_back(bit);
		j = 0;
		A = bit;
		while (A != 0){
			if (A & 1){
				bitset[j][bit-1] = 0;
				if (--cnt[j])
					 a[j] = Query(bitset[j]);
			}
			A >>= 1;
			j++;
		}
	}

	Answer(res);
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 248 KB Output is correct
2 Correct 39 ms 308 KB Output is correct
3 Correct 26 ms 412 KB Output is correct
4 Correct 36 ms 420 KB Output is correct
5 Correct 35 ms 484 KB Output is correct
6 Correct 32 ms 484 KB Output is correct
7 Correct 37 ms 488 KB Output is correct
8 Correct 23 ms 620 KB Output is correct
9 Correct 44 ms 620 KB Output is correct
10 Correct 25 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 248 KB Output is correct
2 Correct 39 ms 308 KB Output is correct
3 Correct 26 ms 412 KB Output is correct
4 Correct 36 ms 420 KB Output is correct
5 Correct 35 ms 484 KB Output is correct
6 Correct 32 ms 484 KB Output is correct
7 Correct 37 ms 488 KB Output is correct
8 Correct 23 ms 620 KB Output is correct
9 Correct 44 ms 620 KB Output is correct
10 Correct 25 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
17 Correct 432 ms 620 KB Output is correct
18 Correct 446 ms 620 KB Output is correct
19 Correct 457 ms 620 KB Output is correct
20 Correct 383 ms 620 KB Output is correct
21 Correct 364 ms 700 KB Output is correct
22 Correct 473 ms 700 KB Output is correct
23 Correct 431 ms 700 KB Output is correct
24 Correct 138 ms 700 KB Output is correct
25 Correct 450 ms 700 KB Output is correct
26 Correct 435 ms 700 KB Output is correct
27 Correct 158 ms 700 KB Output is correct
28 Correct 357 ms 700 KB Output is correct
29 Correct 441 ms 700 KB Output is correct
30 Correct 428 ms 700 KB Output is correct