# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
71930 |
2018-08-26T00:57:52 Z |
IvanC |
City (JOI17_city) |
C++17 |
|
592 ms |
59040 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<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;
vector<ii> guloso;
for(int u : grafo[v]){
if(u == p) continue;
guloso.push_back(ii(tam[u],u));
}
sort(guloso.rbegin(),guloso.rend());
for(ii par : guloso){
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 |
9 ms |
12488 KB |
Output is correct |
2 |
Correct |
8 ms |
12544 KB |
Output is correct |
3 |
Correct |
7 ms |
12544 KB |
Output is correct |
4 |
Correct |
8 ms |
12544 KB |
Output is correct |
5 |
Correct |
6 ms |
12544 KB |
Output is correct |
6 |
Correct |
8 ms |
12544 KB |
Output is correct |
7 |
Correct |
7 ms |
12408 KB |
Output is correct |
8 |
Correct |
7 ms |
12544 KB |
Output is correct |
9 |
Correct |
7 ms |
12544 KB |
Output is correct |
10 |
Correct |
8 ms |
12544 KB |
Output is correct |
11 |
Correct |
8 ms |
12544 KB |
Output is correct |
12 |
Correct |
8 ms |
12544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
19520 KB |
Output is correct - L = 157286400 |
2 |
Correct |
169 ms |
19488 KB |
Output is correct - L = 162791424 |
3 |
Correct |
166 ms |
19392 KB |
Output is correct - L = 156499968 |
4 |
Correct |
169 ms |
19440 KB |
Output is correct - L = 137625600 |
5 |
Partially correct |
546 ms |
57120 KB |
Output is partially correct - L = 56669241344 |
6 |
Partially correct |
539 ms |
57336 KB |
Output is partially correct - L = 56418893824 |
7 |
Partially correct |
538 ms |
57328 KB |
Output is partially correct - L = 56585355264 |
8 |
Partially correct |
531 ms |
56520 KB |
Output is partially correct - L = 49152000000 |
9 |
Partially correct |
449 ms |
58648 KB |
Output is partially correct - L = 5626134528 |
10 |
Partially correct |
430 ms |
59040 KB |
Output is partially correct - L = 531365888 |
11 |
Correct |
418 ms |
58968 KB |
Output is correct - L = 62390272 |
12 |
Correct |
456 ms |
58816 KB |
Output is correct - L = 11010048 |
13 |
Partially correct |
476 ms |
58240 KB |
Output is partially correct - L = 27047231488 |
14 |
Partially correct |
489 ms |
58048 KB |
Output is partially correct - L = 43835195392 |
15 |
Correct |
170 ms |
19432 KB |
Output is correct - L = 155451392 |
16 |
Correct |
172 ms |
19544 KB |
Output is correct - L = 160956416 |
17 |
Correct |
173 ms |
19440 KB |
Output is correct - L = 159383552 |
18 |
Partially correct |
507 ms |
57800 KB |
Output is partially correct - L = 62130487296 |
19 |
Partially correct |
548 ms |
57920 KB |
Output is partially correct - L = 65206484992 |
20 |
Partially correct |
512 ms |
57952 KB |
Output is partially correct - L = 65505067008 |
21 |
Partially correct |
492 ms |
57824 KB |
Output is partially correct - L = 46301184000 |
22 |
Partially correct |
534 ms |
57832 KB |
Output is partially correct - L = 64981565440 |
23 |
Partially correct |
532 ms |
57880 KB |
Output is partially correct - L = 64973963264 |
24 |
Partially correct |
548 ms |
57800 KB |
Output is partially correct - L = 65223262208 |
25 |
Partially correct |
592 ms |
57752 KB |
Output is partially correct - L = 65326022656 |
26 |
Partially correct |
577 ms |
57616 KB |
Output is partially correct - L = 65379762176 |
27 |
Partially correct |
579 ms |
57232 KB |
Output is partially correct - L = 65450541056 |