#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN=2.5e5, B=1<<8;
vector<int> adj[mxN];
int s[mxN], dt1, dt2;
int encrange(int a, int b) {
return b*(b-1)/2+a;
}
void dfs2(int u) {
int ds=dt2++;
for(int v : adj[u])
dfs2(v);
Code(u, 1<<26|dt1<<15|encrange(ds, dt2));
}
void dfs1(int u=0, int p=-1, int d=0) {
int ds=dt1;
s[u]=1;
if(~p)
adj[u].erase(find(adj[u].begin(), adj[u].end(), p));
for(int v : adj[u]) {
dfs1(v, u, d+1);
s[u]+=s[v];
}
if(u&&s[u]<B)
return;
sort(adj[u].begin(), adj[u].end(), [](const int &a, const int &b) {
return s[a]<s[b];
});
for(int i=0, cs; i<adj[u].size()&&s[adj[u][i]]<B; ++dt1) {
dt2=0, cs=0;
while(i<adj[u].size()&&cs+s[adj[u][i]]<B) {
cs+=s[adj[u][i]];
dfs2(adj[u][i++]);
}
}
Code(u, d<<21|encrange(ds, dt1));
}
void Encode(int n, int a[], int b[]) {
for(int i=0; i<n-1; ++i) {
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
dfs1();
}
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;
void InitDevice() {}
int Answer(long long s, long long t) {
auto decrange=[](int x) {
int l=1, r=1<<11;
while(l<r) {
int m=(l+r+1)/2;
if(m*(m-1)/2<=x)
l=m;
else
r=m-1;
}
return array<int, 2>{x-r*(r-1)/2, r};
};
auto inr=[](int x, array<int, 2> r) {
return r[0]<=x&&x<r[1];
};
if(s>>26&&t>>26) {
if((s>>15^t>>15)&(1<<11)-1)
return 2;
array<int, 2> rs=decrange(s&(1<<15)-1), rt=decrange(t&(1<<15)-1);
return inr(rt[0], rs)?1:(inr(rs[0], rt)?0:2);
}
if(s>>26)
return inr(s>>15&(1<<11)-1, decrange(t&(1<<21)-1))?0:2;
if(t>>26)
return inr(t>>15&(1<<11)-1, decrange(s&(1<<21)-1))?1:2;
int sd=s>>21, td=t>>21;
array<int, 2> rs=decrange(s&(1<<21)-1), rt=decrange(t&(1<<21)-1);
return td>sd&&inr(rt[0], rs)?1:(sd>td&&inr(rs[0], rt)?0:2);
}
Compilation message
Encoder.cpp: In function 'void dfs1(int, int, int)':
Encoder.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0, cs; i<adj[u].size()&&s[adj[u][i]]<B; ++dt1) {
~^~~~~~~~~~~~~~
Encoder.cpp:36:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<adj[u].size()&&cs+s[adj[u][i]]<B) {
~^~~~~~~~~~~~~~
Device.cpp: In function 'int Answer(long long int, long long int)':
Device.cpp:23:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
if((s>>15^t>>15)&(1<<11)-1)
~~~~~~~^~
Device.cpp:25:38: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
array<int, 2> rs=decrange(s&(1<<15)-1), rt=decrange(t&(1<<15)-1);
~~~~~~~^~
Device.cpp:25:64: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
array<int, 2> rs=decrange(s&(1<<15)-1), rt=decrange(t&(1<<15)-1);
~~~~~~~^~
Device.cpp:29:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
return inr(s>>15&(1<<11)-1, decrange(t&(1<<21)-1))?0:2;
~~~~~~~^~
Device.cpp:29:49: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
return inr(s>>15&(1<<11)-1, decrange(t&(1<<21)-1))?0:2;
~~~~~~~^~
Device.cpp:31:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
return inr(t>>15&(1<<11)-1, decrange(s&(1<<21)-1))?1:2;
~~~~~~~^~
Device.cpp:31:49: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
return inr(t>>15&(1<<11)-1, decrange(s&(1<<21)-1))?1:2;
~~~~~~~^~
Device.cpp:33:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
array<int, 2> rs=decrange(s&(1<<21)-1), rt=decrange(t&(1<<21)-1);
~~~~~~~^~
Device.cpp:33:63: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
array<int, 2> rs=decrange(s&(1<<21)-1), rt=decrange(t&(1<<21)-1);
~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12544 KB |
Output is correct |
2 |
Correct |
8 ms |
12288 KB |
Output is correct |
3 |
Correct |
9 ms |
12544 KB |
Output is correct |
4 |
Correct |
10 ms |
12544 KB |
Output is correct |
5 |
Correct |
8 ms |
12544 KB |
Output is correct |
6 |
Correct |
9 ms |
12288 KB |
Output is correct |
7 |
Correct |
8 ms |
12288 KB |
Output is correct |
8 |
Correct |
12 ms |
12544 KB |
Output is correct |
9 |
Correct |
8 ms |
12288 KB |
Output is correct |
10 |
Correct |
7 ms |
12544 KB |
Output is correct |
11 |
Correct |
10 ms |
12544 KB |
Output is correct |
12 |
Correct |
10 ms |
12288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
21472 KB |
Output is correct - L = 67218045 |
2 |
Correct |
321 ms |
21488 KB |
Output is correct - L = 67273028 |
3 |
Correct |
169 ms |
21488 KB |
Output is correct - L = 67283581 |
4 |
Correct |
174 ms |
21488 KB |
Output is correct - L = 67207039 |
5 |
Correct |
592 ms |
55792 KB |
Output is correct - L = 120077176 |
6 |
Correct |
565 ms |
55624 KB |
Output is correct - L = 119270012 |
7 |
Correct |
531 ms |
55224 KB |
Output is correct - L = 120242996 |
8 |
Correct |
569 ms |
54768 KB |
Output is correct - L = 99123071 |
9 |
Correct |
518 ms |
56536 KB |
Output is correct - L = 101318527 |
10 |
Correct |
501 ms |
56784 KB |
Output is correct - L = 99657640 |
11 |
Correct |
463 ms |
56808 KB |
Output is correct - L = 99713024 |
12 |
Correct |
456 ms |
56600 KB |
Output is correct - L = 99647488 |
13 |
Correct |
528 ms |
56152 KB |
Output is correct - L = 108584254 |
14 |
Correct |
579 ms |
55872 KB |
Output is correct - L = 114983772 |
15 |
Correct |
172 ms |
21488 KB |
Output is correct - L = 67245713 |
16 |
Correct |
207 ms |
21488 KB |
Output is correct - L = 67274356 |
17 |
Correct |
184 ms |
21632 KB |
Output is correct - L = 67221532 |
18 |
Correct |
510 ms |
55912 KB |
Output is correct - L = 99713029 |
19 |
Correct |
507 ms |
55776 KB |
Output is correct - L = 99385344 |
20 |
Correct |
491 ms |
55760 KB |
Output is correct - L = 99353610 |
21 |
Correct |
497 ms |
56032 KB |
Output is correct - L = 100368404 |
22 |
Correct |
525 ms |
55720 KB |
Output is correct - L = 99319813 |
23 |
Correct |
544 ms |
55520 KB |
Output is correct - L = 99301235 |
24 |
Correct |
599 ms |
55808 KB |
Output is correct - L = 99483683 |
25 |
Correct |
553 ms |
55792 KB |
Output is correct - L = 99389903 |
26 |
Correct |
617 ms |
55280 KB |
Output is correct - L = 99498872 |
27 |
Correct |
638 ms |
55000 KB |
Output is correct - L = 99714619 |