Submission #414837

# Submission time Handle Problem Language Result Execution time Memory
414837 2021-05-31T08:50:24 Z amoo_safar City (JOI17_city) C++17
100 / 100
545 ms 43028 KB
#include "Encoder.h"
#include <bits/stdc++.h>

using namespace std;


const int N = 33e4;
const int bl = 110;
const int sd = 58;

int mk[N];
mt19937 rng(sd);
vector<int> V;

vector<int> G[N];
int st[N], fn[N], T = 0;

void DFS(int u, int p){
	st[u] = T ++;
	shuffle(G[u].begin(), G[u].end(), rng);
	bool fl = false;
	for(auto adj : G[u])
		if((adj != p) && ((int) G[adj].size() == 1))
			fl = true;
	if(fl){
		for(auto adj : G[u]){
			if(adj != p && G[adj].size() == 1){
				st[adj] = T;
				fn[adj] = T + 1;
			}
		}
		T ++;
	} 
	for(auto adj : G[u])
		if(adj != p && G[adj].size() > 1)
			DFS(adj, u);
	fn[u] = T;

	while(mk[fn[u] - st[u] ] == -1){
		fn[u] ++;
		T ++;
	}
	// cerr << "!! " << u << ' ' << st[u] << ' ' << fn[u] << '\n'; 
}

void Encode(int _n, int A[], int B[]){
	memset(mk, -1, sizeof mk);
	int cnt = 0;

	for(int i = 1; i < N; i++){
		int pr = (i + bl - 1) / bl;
		// if(i > N / 2) pr += pr;
		uniform_int_distribution<> Amoo(1, pr);
		if(Amoo(rng) == 1){
			mk[i] = V.size();
			V.push_back(i);
		}
	}
	int sz = V.size();
	for(int i = 0; i < _n - 1; i++)
		G[A[i]].push_back(B[i]), G[B[i]].push_back(A[i]);
	T = 0;
	DFS(0, -1);
	cerr << "! " << V.size() << '\n';
	// for(int i = 0; i < _n; i++)
	// 	cerr << "! " << st[i] << ' ' << fn[i] << '\n';
	
	for(int i = 0; i < _n; i++){
		Code(i, 1ll * sz * st[i] + mk[fn[i] - st[i]]);
	}
}
#include "Device.h"

#include <bits/stdc++.h>

using namespace std;

const int N = 33e4;
const int bl = 110;
const int sd = 58;

mt19937 rng2(sd);
vector<int> V2;

void InitDevice(){
	for(int i = 1; i < N; i++){
		int pr = (i + bl - 1) / bl;
		uniform_int_distribution<> Amoo(1, pr);

		if(Amoo(rng2) == 1)
			V2.push_back(i);
	}
}

int Answer(long long S, long long T){
	if(S == T)
		return 2;
	int sz = V2.size();
	int s1 = S / sz, f1 = s1 + V2[S % sz];
	int s2 = T / sz, f2 = s2 + V2[T % sz];

	if(s2 <= s1 && s1 < f2) return 0;
	if(s1 <= s2 && s2 < f1) return 1;
	return 2;
}

Compilation message

Encoder.cpp: In function 'void Encode(int, int*, int*)':
Encoder.cpp:48:6: warning: unused variable 'cnt' [-Wunused-variable]
   48 |  int cnt = 0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 9580 KB Output is correct
2 Correct 22 ms 9716 KB Output is correct
3 Correct 22 ms 9696 KB Output is correct
4 Correct 20 ms 9692 KB Output is correct
5 Correct 20 ms 9548 KB Output is correct
6 Correct 20 ms 9616 KB Output is correct
7 Correct 23 ms 9664 KB Output is correct
8 Correct 20 ms 9600 KB Output is correct
9 Correct 20 ms 9688 KB Output is correct
10 Correct 20 ms 9732 KB Output is correct
11 Correct 20 ms 9700 KB Output is correct
12 Correct 23 ms 9720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 18216 KB Output is correct - L = 575840
2 Correct 216 ms 18168 KB Output is correct - L = 600384
3 Correct 213 ms 18220 KB Output is correct - L = 566400
4 Correct 216 ms 18180 KB Output is correct - L = 497488
5 Correct 497 ms 42304 KB Output is correct - L = 215497264
6 Correct 495 ms 42188 KB Output is correct - L = 217290864
7 Correct 496 ms 42224 KB Output is correct - L = 216614960
8 Correct 528 ms 42180 KB Output is correct - L = 189681696
9 Correct 420 ms 42940 KB Output is correct - L = 21521312
10 Correct 476 ms 43028 KB Output is correct - L = 2108896
11 Correct 453 ms 42944 KB Output is correct - L = 251104
12 Correct 426 ms 42968 KB Output is correct - L = 39648
13 Correct 439 ms 42600 KB Output is correct - L = 106255696
14 Correct 484 ms 42408 KB Output is correct - L = 169363040
15 Correct 210 ms 18244 KB Output is correct - L = 567344
16 Correct 223 ms 18228 KB Output is correct - L = 591888
17 Correct 228 ms 18164 KB Output is correct - L = 577728
18 Correct 473 ms 42460 KB Output is correct - L = 257578896
19 Correct 515 ms 42536 KB Output is correct - L = 234813392
20 Correct 477 ms 42436 KB Output is correct - L = 235888608
21 Correct 510 ms 42532 KB Output is correct - L = 190449168
22 Correct 525 ms 42340 KB Output is correct - L = 234077072
23 Correct 488 ms 42388 KB Output is correct - L = 234714272
24 Correct 545 ms 42304 KB Output is correct - L = 236250160
25 Correct 518 ms 42392 KB Output is correct - L = 236243552
26 Correct 521 ms 42288 KB Output is correct - L = 240759648
27 Correct 499 ms 42244 KB Output is correct - L = 244117456