Submission #101112

# Submission time Handle Problem Language Result Execution time Memory
101112 2019-03-16T17:02:47 Z gs14004 Library (JOI18_library) C++17
100 / 100
499 ms 4472 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
const int MAXN = 1005;

int n;
int dp[MAXN][MAXN];

int query(int s, int e){
	if(s > e) return 0;
	if(dp[s][e]) return dp[s][e];
	vector<int> v(n);
	fill(v.begin() + s, v.begin() + e + 1, 1);
	return dp[s][e] = Query(v);
}

vector<int> gph[MAXN];
vector<int> dfn;

void dfs(int x, int p){
	dfn.push_back(x + 1);
	for(auto &i : gph[x]){
		if(i != p){
			dfs(i, x);
		}
	}
}

void Solve(int N){
	if(N == 1){
		Answer({1});
		return;
	}
	n = N;
	for(int i=1; i<N; i++){
		int interesting = query(0, i - 1) + 1 - query(0, i);
		for(int j=0; j<interesting; j++){
			int s = 1, e = i;
			while(s != e){
				int m = (s + e) / 2;
				if(query(m, i) >= query(m, i - 1) + 1 - j){
					e = m;
				}
				else s = m + 1;
			}
			gph[i].push_back(s - 1);
			gph[s - 1].push_back(i);
		//	printf("has edge %d %d\n", s - 1, i);
		}
	}
	for(int i=0; i<N; i++){
		if(gph[i].size() == 1){
			dfs(i, -1);
			break;
		}
	}
	Answer(dfn);
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1016 KB # of queries: 2388
2 Correct 39 ms 1064 KB # of queries: 2435
3 Correct 34 ms 1028 KB # of queries: 2483
4 Correct 44 ms 1016 KB # of queries: 2544
5 Correct 40 ms 1144 KB # of queries: 2512
6 Correct 39 ms 1144 KB # of queries: 2484
7 Correct 44 ms 1028 KB # of queries: 2577
8 Correct 48 ms 940 KB # of queries: 2433
9 Correct 48 ms 1016 KB # of queries: 2529
10 Correct 16 ms 812 KB # of queries: 1461
11 Correct 2 ms 256 KB # of queries: 0
12 Correct 2 ms 384 KB # of queries: 2
13 Correct 2 ms 384 KB # of queries: 5
14 Correct 3 ms 384 KB # of queries: 9
15 Correct 4 ms 384 KB # of queries: 74
16 Correct 5 ms 412 KB # of queries: 174
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1016 KB # of queries: 2388
2 Correct 39 ms 1064 KB # of queries: 2435
3 Correct 34 ms 1028 KB # of queries: 2483
4 Correct 44 ms 1016 KB # of queries: 2544
5 Correct 40 ms 1144 KB # of queries: 2512
6 Correct 39 ms 1144 KB # of queries: 2484
7 Correct 44 ms 1028 KB # of queries: 2577
8 Correct 48 ms 940 KB # of queries: 2433
9 Correct 48 ms 1016 KB # of queries: 2529
10 Correct 16 ms 812 KB # of queries: 1461
11 Correct 2 ms 256 KB # of queries: 0
12 Correct 2 ms 384 KB # of queries: 2
13 Correct 2 ms 384 KB # of queries: 5
14 Correct 3 ms 384 KB # of queries: 9
15 Correct 4 ms 384 KB # of queries: 74
16 Correct 5 ms 412 KB # of queries: 174
17 Correct 499 ms 4064 KB # of queries: 17517
18 Correct 393 ms 4032 KB # of queries: 17184
19 Correct 384 ms 4088 KB # of queries: 17448
20 Correct 377 ms 3896 KB # of queries: 16160
21 Correct 319 ms 3832 KB # of queries: 15233
22 Correct 470 ms 4272 KB # of queries: 17402
23 Correct 392 ms 4088 KB # of queries: 17463
24 Correct 165 ms 2168 KB # of queries: 7880
25 Correct 489 ms 4112 KB # of queries: 17069
26 Correct 406 ms 3704 KB # of queries: 15873
27 Correct 167 ms 2168 KB # of queries: 7892
28 Correct 388 ms 4472 KB # of queries: 15472
29 Correct 429 ms 4344 KB # of queries: 15453
30 Correct 405 ms 4344 KB # of queries: 15472