# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
71931 |
2018-08-26T00:59:56 Z |
IvanC |
City (JOI17_city) |
C++17 |
|
604 ms |
82160 KB |
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 250010;
typedef long long ll;
typedef pair<int,int> ii;
static vector<ii> guloso[MAXN];
static vector<int> grafo[MAXN];
static int tam[MAXN],ini[MAXN],fim[MAXN],dfsCount;
static void dfs_sz(int v,int p){
tam[v] = 1;
int tem_folha = 0;
for(int u : grafo[v]){
if(u == p) continue;
dfs_sz(u,v);
if(tam[u] != 1){
tam[v] += tam[u];
}
else{
if(!tem_folha){
tem_folha = 1;
tam[v] += 1;
}
}
}
}
static void dfs_euler(int v,int p){
ini[v] = ++dfsCount;
int tem_folha = 0;
for(int u : grafo[v]){
if(u == p) continue;
guloso[v].push_back(ii(tam[u],u));
}
sort(guloso[v].rbegin(),guloso[v].rend());
for(ii par : guloso[v]){
int sz_u = par.first, u = par.second;
if(sz_u != 1){
dfs_euler(u,v);
}
else{
if(!tem_folha){
tem_folha++;
dfsCount++;
ini[u] = dfsCount;
fim[u] = dfsCount;
}
else{
ini[u] = dfsCount;
fim[u] = dfsCount;
}
}
}
fim[v] = dfsCount;
}
static long long coding(int A,int B){
B -= A;
long long davez = A;
davez += (1LL << 18)*ll(B);
return davez;
}
void Encode(int N, int A[], int B[]){
for(int i = 0;i<N-1;i++){
grafo[A[i]].push_back(B[i]);
grafo[B[i]].push_back(A[i]);
}
dfs_sz(0,-1);
dfs_euler(0,-1);
for(int i = 0;i<N;i++){
ini[i]--;
fim[i]--;
}
for (int i = 0; i < N; ++i) {
Code(i, coding(ini[i],fim[i]) );
}
}
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;
void InitDevice(){
}
static void Magic(long long X, int &ini, int& fim ){
ini = 0;
fim = 0;
long long temp = (X >> 18);
fim += temp;
X -= (temp)*(1 << 18);
ini += X;
fim += ini;
}
int Answer(long long S, long long T){
if(S == T) return 2;
int inia,fima,inib,fimb;
Magic(S,inia,fima);
Magic(T,inib,fimb);
if(inia <= inib && inib <= fima) return 1;
if(inib <= inia && inia <= fimb) return 0;
return 2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
24320 KB |
Output is correct |
2 |
Correct |
13 ms |
24064 KB |
Output is correct |
3 |
Correct |
13 ms |
24064 KB |
Output is correct |
4 |
Correct |
14 ms |
24064 KB |
Output is correct |
5 |
Correct |
15 ms |
24096 KB |
Output is correct |
6 |
Correct |
12 ms |
24064 KB |
Output is correct |
7 |
Correct |
13 ms |
24064 KB |
Output is correct |
8 |
Correct |
12 ms |
24064 KB |
Output is correct |
9 |
Correct |
14 ms |
24320 KB |
Output is correct |
10 |
Correct |
13 ms |
24168 KB |
Output is correct |
11 |
Correct |
14 ms |
24264 KB |
Output is correct |
12 |
Correct |
13 ms |
24064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
31224 KB |
Output is correct - L = 157286400 |
2 |
Correct |
181 ms |
31160 KB |
Output is correct - L = 162791424 |
3 |
Correct |
181 ms |
31256 KB |
Output is correct - L = 156499968 |
4 |
Correct |
181 ms |
31368 KB |
Output is correct - L = 137625600 |
5 |
Partially correct |
579 ms |
78320 KB |
Output is partially correct - L = 56669241344 |
6 |
Partially correct |
575 ms |
78288 KB |
Output is partially correct - L = 56418893824 |
7 |
Partially correct |
545 ms |
78336 KB |
Output is partially correct - L = 56585355264 |
8 |
Partially correct |
567 ms |
76176 KB |
Output is partially correct - L = 49152000000 |
9 |
Partially correct |
454 ms |
74632 KB |
Output is partially correct - L = 5626134528 |
10 |
Partially correct |
427 ms |
74584 KB |
Output is partially correct - L = 531365888 |
11 |
Correct |
445 ms |
74408 KB |
Output is correct - L = 62390272 |
12 |
Correct |
426 ms |
74440 KB |
Output is correct - L = 11010048 |
13 |
Partially correct |
484 ms |
76240 KB |
Output is partially correct - L = 27047231488 |
14 |
Partially correct |
515 ms |
77472 KB |
Output is partially correct - L = 43835195392 |
15 |
Correct |
174 ms |
31160 KB |
Output is correct - L = 155451392 |
16 |
Correct |
173 ms |
31216 KB |
Output is correct - L = 160956416 |
17 |
Correct |
176 ms |
31280 KB |
Output is correct - L = 159383552 |
18 |
Partially correct |
493 ms |
78704 KB |
Output is partially correct - L = 62130487296 |
19 |
Partially correct |
531 ms |
79128 KB |
Output is partially correct - L = 65206484992 |
20 |
Partially correct |
534 ms |
79096 KB |
Output is partially correct - L = 65505067008 |
21 |
Partially correct |
523 ms |
77152 KB |
Output is partially correct - L = 46301184000 |
22 |
Partially correct |
568 ms |
80088 KB |
Output is partially correct - L = 64981565440 |
23 |
Partially correct |
561 ms |
80088 KB |
Output is partially correct - L = 64973963264 |
24 |
Partially correct |
568 ms |
80728 KB |
Output is partially correct - L = 65223262208 |
25 |
Partially correct |
568 ms |
81376 KB |
Output is partially correct - L = 65326022656 |
26 |
Partially correct |
588 ms |
81608 KB |
Output is partially correct - L = 65379762176 |
27 |
Partially correct |
604 ms |
82160 KB |
Output is partially correct - L = 65450541056 |