#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "Encoder.h"
vi adjList[250000];
int disc[250000],size[250000],num = 0;
set<int> good;
vi vv;
int doDFS(int u,int p) {
int i;
disc[u] = num++,size[u] = 1;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v != p) size[u] += doDFS(v,u);
}
auto it = good.lower_bound(size[u]);
num += *it-size[u],size[u] = *it;
return size[u];
}
void Encode(int N,int A[],int B[]) {
int i;
good.insert(1);
while (*good.rbegin() < 1e9) good.insert(max(*good.rbegin()+1,(int) (*good.rbegin()*1.08)));
for (auto it = good.begin(); it != good.end(); it++) vv.pb(*it);
for (i = 0; i < N-1; i++) {
adjList[A[i]].pb(B[i]);
adjList[B[i]].pb(A[i]);
}
doDFS(0,-1);
for (i = 0; i < N; i++) {
int p = lower_bound(vv.begin(),vv.end(),size[i])-vv.begin();
Code(i,((LLI) disc[i] << 8) | p);
}
}
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "Device.h"
vi v;
void InitDevice() {
v.pb(1);
while (v.back() < 1e9) v.pb(max(v.back()+1,(int) (v.back()*1.08)));
}
int Answer(long long int S,long long int T) {
int discX = S >> 8,finX = discX+v[S & 255]-1;
int discY = T >> 8,finY = discY+v[T & 255]-1;
if ((discX >= discY) && (discX <= finY)) return 0;
else if ((discY >= discX) && (discY <= finX)) return 1;
else return 2;
}
Compilation message
Encoder.cpp: In function 'int doDFS(int, int)':
Encoder.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (i = 0; i < adjList[u].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6396 KB |
Output is correct |
2 |
Correct |
5 ms |
6408 KB |
Output is correct |
3 |
Correct |
5 ms |
6392 KB |
Output is correct |
4 |
Correct |
5 ms |
6396 KB |
Output is correct |
5 |
Correct |
5 ms |
6480 KB |
Output is correct |
6 |
Correct |
5 ms |
6396 KB |
Output is correct |
7 |
Correct |
5 ms |
6396 KB |
Output is correct |
8 |
Correct |
5 ms |
6396 KB |
Output is correct |
9 |
Correct |
5 ms |
6396 KB |
Output is correct |
10 |
Correct |
5 ms |
6396 KB |
Output is correct |
11 |
Correct |
5 ms |
6404 KB |
Output is correct |
12 |
Correct |
5 ms |
6396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
14984 KB |
Output is correct - L = 199424 |
2 |
Correct |
186 ms |
14960 KB |
Output is correct - L = 207872 |
3 |
Correct |
188 ms |
14984 KB |
Output is correct - L = 200960 |
4 |
Correct |
186 ms |
15040 KB |
Output is correct - L = 193280 |
5 |
Correct |
480 ms |
39012 KB |
Output is correct - L = 87890944 |
6 |
Correct |
470 ms |
39172 KB |
Output is correct - L = 87412736 |
7 |
Correct |
490 ms |
39052 KB |
Output is correct - L = 88209408 |
8 |
Correct |
497 ms |
38876 KB |
Output is correct - L = 119353344 |
9 |
Correct |
421 ms |
39776 KB |
Output is correct - L = 205183488 |
10 |
Correct |
395 ms |
39796 KB |
Output is correct - L = 188701440 |
11 |
Correct |
400 ms |
39792 KB |
Output is correct - L = 220052992 |
12 |
Correct |
395 ms |
39836 KB |
Output is correct - L = 188661760 |
13 |
Correct |
436 ms |
39428 KB |
Output is correct - L = 132088320 |
14 |
Correct |
476 ms |
39284 KB |
Output is correct - L = 105700352 |
15 |
Correct |
192 ms |
15000 KB |
Output is correct - L = 202240 |
16 |
Correct |
190 ms |
15024 KB |
Output is correct - L = 201728 |
17 |
Correct |
187 ms |
15096 KB |
Output is correct - L = 190976 |
18 |
Correct |
449 ms |
39280 KB |
Output is correct - L = 203753472 |
19 |
Correct |
442 ms |
39308 KB |
Output is correct - L = 63999744 |
20 |
Correct |
456 ms |
39336 KB |
Output is correct - L = 63999744 |
21 |
Correct |
458 ms |
39460 KB |
Output is correct - L = 203754240 |
22 |
Correct |
457 ms |
39336 KB |
Output is correct - L = 65546496 |
23 |
Correct |
462 ms |
39236 KB |
Output is correct - L = 65719296 |
24 |
Correct |
467 ms |
39240 KB |
Output is correct - L = 65870336 |
25 |
Correct |
477 ms |
39324 KB |
Output is correct - L = 66526208 |
26 |
Correct |
474 ms |
39036 KB |
Output is correct - L = 70197760 |
27 |
Correct |
479 ms |
39236 KB |
Output is correct - L = 69624832 |