Submission #414833

# Submission time Handle Problem Language Result Execution time Memory
414833 2021-05-31T08:44:10 Z amoo_safar City (JOI17_city) C++17
8 / 100
523 ms 42168 KB
#include "Encoder.h"
#include <bits/stdc++.h>

using namespace std;


const int N = 30e4;
const int bl = 115;
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 = 30e4;
const int bl = 115;
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 19 ms 8852 KB Output is correct
2 Correct 19 ms 8800 KB Output is correct
3 Correct 22 ms 8828 KB Output is correct
4 Correct 20 ms 8856 KB Output is correct
5 Correct 22 ms 8808 KB Output is correct
6 Correct 20 ms 8928 KB Output is correct
7 Correct 19 ms 8776 KB Output is correct
8 Correct 20 ms 8852 KB Output is correct
9 Correct 19 ms 8828 KB Output is correct
10 Correct 20 ms 8832 KB Output is correct
11 Correct 19 ms 8836 KB Output is correct
12 Correct 20 ms 8832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 17360 KB Output is correct - L = 590976
2 Correct 216 ms 17380 KB Output is correct - L = 618192
3 Correct 212 ms 17408 KB Output is correct - L = 583200
4 Correct 232 ms 17332 KB Output is correct - L = 511272
5 Correct 475 ms 41448 KB Output is correct - L = 221343840
6 Correct 468 ms 41472 KB Output is correct - L = 223431696
7 Correct 490 ms 41420 KB Output is correct - L = 221134860
8 Correct 482 ms 41168 KB Output is correct - L = 194721732
9 Correct 415 ms 42136 KB Output is correct - L = 22159656
10 Correct 419 ms 42080 KB Output is correct - L = 2134512
11 Correct 417 ms 42080 KB Output is correct - L = 253692
12 Correct 426 ms 42168 KB Output is correct - L = 40824
13 Correct 451 ms 41844 KB Output is correct - L = 109322784
14 Correct 465 ms 41620 KB Output is correct - L = 172871172
15 Correct 221 ms 17444 KB Output is correct - L = 584172
16 Correct 221 ms 17376 KB Output is correct - L = 605556
17 Correct 222 ms 17432 KB Output is correct - L = 594864
18 Partially correct 523 ms 41596 KB Output is partially correct - L = 271580688
19 Correct 519 ms 41556 KB Output is correct - L = 241778196
20 Incorrect 520 ms 41604 KB Wrong Answer [6]
21 Halted 0 ms 0 KB -