#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
#include "Joi.h"
vector<int>E[20000];
bool used[20000];
int dep[20000];
int height[20000];
vector<int>vs;
int dfs(int v,int d){
used[v]=true;
dep[v]=d;
vs.push_back(v);
for(int u:E[v]){
if(used[u])continue;
height[v]=max(height[v],dfs(u,d+1)+1);
vs.push_back(v);
}
return height[v];
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
rep(i,M){
E[A[i]].push_back(B[i]);
E[B[i]].push_back(A[i]);
}
dfs(0,0);
if(height[0]<60){
set<int>se1,se2;
for(int v:vs){
if(!se1.count(v)){
se2.insert(v);
}
if(se2.size()==60){
int cnt=0;
for(int i:se2){
MessageBoard(i,X>>cnt&1);
cnt++;
}
for(int i:se2){
se1.insert(i);
}
se2.clear();
}
}
int cnt=0;
for(int i:se2){
MessageBoard(i,X>>cnt&1);
cnt++;
}
return;
}
rep(i,N){
dep[i]%=60;
MessageBoard(i,X>>dep[i]&1);
}
}
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
#include "Ioi.h"
static vector<int>E[20000];
static vector<int>G[20000];
static bool used[20000];
static int dep[20000];
static int height[20000];
static int par[20000];
static vector<int>vs;
static int vid[20000];
static int dfs(int v,int p,int d){
used[v]=true;
vid[v]=vs.size();
vs.push_back(v);
par[v]=p;
dep[v]=d;
for(int u:E[v]){
if(used[u])continue;
G[v].push_back(u);
height[v]=max(height[v],dfs(u,v,d+1)+1);
vs.push_back(v);
}
return height[v];
}
long long Ioi(int N, int M, int A[], int B[], int Pos, int V, int T) {
rep(i,M){
E[A[i]].push_back(B[i]);
E[B[i]].push_back(A[i]);
}
dfs(0,-1,0);
if(height[0]<60){
set<int>se1,se2;
map<int,int>id;
for(int v:vs){
if(!se1.count(v)){
se2.insert(v);
}
if(se2.size()==60){
int cnt=0;
for(int i:se2){
id[i]=cnt;
cnt++;
}
for(int i:se2){
se1.insert(i);
}
se2.clear();
}
}
int cnt=0;
for(int i:se2){
id[i]=cnt;
cnt++;
}
int x=vid[Pos];
set<int>se;
int r;
for(r=x;r<vs.size();r++){
se.insert(id[vs[r]]);
if(se.size()==60)break;
}
if(r==vs.size())r=vs.size()-1;
int l;
for(l=x;l>=0;l--){
se.insert(id[vs[l]]);
if(se.size()==60)break;
}
if(l==-1)l=0;
set<int>Se;
int l2;
for(l2=x;l2>=0;l2--){
Se.insert(id[vs[l2]]);
if(Se.size()==60)break;
}
if(l2==-1)l2=0;
int r2;
for(r2=x;r2<vs.size();r2++){
Se.insert(id[vs[r2]]);
if(Se.size()==60)break;
}
if(r2==vs.size())r2=vs.size()-1;
if(r2-l2+min(r2-x,x-l2)<r-l+min(r-x,x-l)){
swap(l,l2);
swap(r,r2);
}
set<int>SE;
int l3=x,r3=x;
while(1){
if(l3>0){
SE.insert(id[vs[--l3]]);
}
if(r3<vs.size()-1){
SE.insert(id[vs[++r3]]);
}
if(SE.size()==60)break;
}
if(r3-l3+min(r3-x,x-l3)<r-l+min(r-x,x-l)){
swap(l,l3);
swap(r,r3);
}
map<int,vector<int>>MP;
rep(i,vs.size()){
MP[id[vs[i]]].push_back(i);
}
int l4=x,r4=x;
rep(i,60){
int Min=INT_MAX;
int t=-1;
auto it=lower_bound(MP[i].begin(),MP[i].end(),x);
if(it!=MP[i].end()){
Min=*it-x;
t=*it;
}
if(it!=MP[i].begin()){
it--;
if(Min>x-*it){
Min=x-*it;
t=*it;
}
}
assert(Min<=900);
l4=min(l4,*it);
r4=max(r4,*it);
}
if(r4-l4+min(r4-x,x-l4)<r-l+min(r-x,x-l)){
swap(l,l4);
swap(r,r4);
}
ll ans=0;
ans|=ll(V)<<id[Pos];
if(abs(x-l)<abs(x-r)){
//left
for(int i=x-1;i>=l;i--){
ans|=ll(Move(vs[i]))<<id[vs[i]];
}
for(int i=l+1;i<=r;i++){
ans|=ll(Move(vs[i]))<<id[vs[i]];
}
}
else{
//right
for(int i=x+1;i<=r;i++){
ans|=ll(Move(vs[i]))<<id[vs[i]];
}
for(int i=r-1;i>=l;i--){
ans|=ll(Move(vs[i]))<<id[vs[i]];
}
}
return ans;
}
rep(i,N){
dep[i]%=60;
}
int pos=Pos;
set<int>se{dep[pos]};
ll ans=ll(V)<<dep[pos];
while(1){
if(se.size()==60||pos==0){
break;
}
pos=par[pos];
ans|=ll(Move(pos))<<dep[pos];
se.insert(dep[pos]);
}
while(1){
if(se.size()==60)break;
for(int u:G[pos]){
if(height[u]+1==height[pos]){
pos=u;
ans|=ll(Move(pos))<<dep[pos];
se.insert(dep[pos]);
break;
}
}
}
return ans;
}
Compilation message
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:67:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(r=x;r<vs.size();r++){
~^~~~~~~~~~
Ioi.cpp:71:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(r==vs.size())r=vs.size()-1;
~^~~~~~~~~~~
Ioi.cpp:87:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(r2=x;r2<vs.size();r2++){
~~^~~~~~~~~~
Ioi.cpp:91:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(r2==vs.size())r2=vs.size()-1;
~~^~~~~~~~~~~
Ioi.cpp:103:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(r3<vs.size()-1){
~~^~~~~~~~~~~~
Ioi.cpp:2:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,n)for(int i=0;i<(n);i++)
^
Ioi.cpp:115:3: note: in expansion of macro 'rep'
rep(i,vs.size()){
^~~
Ioi.cpp:121:8: warning: variable 't' set but not used [-Wunused-but-set-variable]
int t=-1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2416 KB |
Output is correct |
2 |
Correct |
7 ms |
2312 KB |
Output is correct |
3 |
Correct |
7 ms |
2436 KB |
Output is correct |
4 |
Correct |
7 ms |
2416 KB |
Output is correct |
5 |
Correct |
7 ms |
2356 KB |
Output is correct |
6 |
Correct |
8 ms |
2312 KB |
Output is correct |
7 |
Correct |
8 ms |
2344 KB |
Output is correct |
8 |
Correct |
7 ms |
2288 KB |
Output is correct |
9 |
Correct |
7 ms |
2436 KB |
Output is correct |
10 |
Correct |
6 ms |
2176 KB |
Output is correct |
11 |
Correct |
10 ms |
2692 KB |
Output is correct |
12 |
Correct |
5 ms |
2212 KB |
Output is correct |
13 |
Correct |
8 ms |
2516 KB |
Output is correct |
14 |
Correct |
8 ms |
2388 KB |
Output is correct |
15 |
Correct |
3 ms |
2316 KB |
Output is correct |
16 |
Correct |
8 ms |
2392 KB |
Output is correct |
17 |
Correct |
7 ms |
2516 KB |
Output is correct |
18 |
Correct |
8 ms |
2444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
5980 KB |
Output is correct |
2 |
Correct |
41 ms |
5792 KB |
Output is correct |
3 |
Correct |
41 ms |
5868 KB |
Output is correct |
4 |
Correct |
45 ms |
5820 KB |
Output is correct |
5 |
Correct |
26 ms |
5172 KB |
Output is correct |
6 |
Correct |
25 ms |
4648 KB |
Output is correct |
7 |
Correct |
29 ms |
4800 KB |
Output is correct |
8 |
Correct |
24 ms |
4928 KB |
Output is correct |
9 |
Correct |
29 ms |
4796 KB |
Output is correct |
10 |
Correct |
40 ms |
5824 KB |
Output is correct |
11 |
Correct |
40 ms |
5840 KB |
Output is correct |
12 |
Correct |
45 ms |
5552 KB |
Output is correct |
13 |
Correct |
41 ms |
5460 KB |
Output is correct |
14 |
Correct |
49 ms |
5696 KB |
Output is correct |
15 |
Correct |
41 ms |
5932 KB |
Output is correct |
16 |
Correct |
44 ms |
5940 KB |
Output is correct |
17 |
Correct |
48 ms |
5820 KB |
Output is correct |
18 |
Correct |
44 ms |
5868 KB |
Output is correct |
19 |
Correct |
50 ms |
5688 KB |
Output is correct |
20 |
Correct |
20 ms |
4928 KB |
Output is correct |
21 |
Correct |
18 ms |
4988 KB |
Output is correct |
22 |
Correct |
25 ms |
4680 KB |
Output is correct |
23 |
Correct |
27 ms |
4936 KB |
Output is correct |
24 |
Correct |
24 ms |
4728 KB |
Output is correct |
25 |
Correct |
32 ms |
5048 KB |
Output is correct |
26 |
Correct |
22 ms |
4808 KB |
Output is correct |
27 |
Correct |
22 ms |
4800 KB |
Output is correct |
28 |
Correct |
22 ms |
4928 KB |
Output is correct |
29 |
Correct |
26 ms |
4592 KB |
Output is correct |
30 |
Correct |
20 ms |
4688 KB |
Output is correct |
31 |
Correct |
6 ms |
2176 KB |
Output is correct |
32 |
Correct |
8 ms |
2304 KB |
Output is correct |
33 |
Correct |
6 ms |
2388 KB |
Output is correct |
34 |
Correct |
6 ms |
2312 KB |
Output is correct |
35 |
Correct |
7 ms |
2176 KB |
Output is correct |
36 |
Correct |
7 ms |
2048 KB |
Output is correct |
37 |
Correct |
5 ms |
2296 KB |
Output is correct |
38 |
Correct |
8 ms |
2220 KB |
Output is correct |
39 |
Correct |
8 ms |
2312 KB |
Output is correct |
40 |
Correct |
8 ms |
2420 KB |
Output is correct |
41 |
Correct |
6 ms |
2176 KB |
Output is correct |
42 |
Correct |
6 ms |
2312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2308 KB |
Output is correct |
2 |
Correct |
7 ms |
2312 KB |
Output is correct |
3 |
Correct |
5 ms |
2188 KB |
Output is correct |
4 |
Correct |
8 ms |
2724 KB |
Output is correct |
5 |
Correct |
10 ms |
2736 KB |
Output is correct |
6 |
Correct |
10 ms |
2736 KB |
Output is correct |
7 |
Correct |
10 ms |
2620 KB |
Output is correct |
8 |
Correct |
6 ms |
2868 KB |
Output is correct |
9 |
Correct |
22 ms |
5636 KB |
Output is correct |
10 |
Correct |
25 ms |
5576 KB |
Output is correct |
11 |
Correct |
23 ms |
5568 KB |
Output is correct |
12 |
Correct |
6 ms |
2356 KB |
Output is correct |
13 |
Correct |
7 ms |
2312 KB |
Output is correct |
14 |
Correct |
5 ms |
2176 KB |
Output is correct |
15 |
Correct |
7 ms |
2316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
5816 KB |
Output is correct |
2 |
Correct |
32 ms |
5892 KB |
Output is correct |
3 |
Correct |
41 ms |
5844 KB |
Output is correct |
4 |
Partially correct |
47 ms |
5696 KB |
Partially correct |
5 |
Correct |
23 ms |
5184 KB |
Output is correct |
6 |
Correct |
22 ms |
4808 KB |
Output is correct |
7 |
Correct |
26 ms |
4936 KB |
Output is correct |
8 |
Correct |
24 ms |
4680 KB |
Output is correct |
9 |
Correct |
26 ms |
4848 KB |
Output is correct |
10 |
Correct |
39 ms |
5820 KB |
Output is correct |
11 |
Partially correct |
45 ms |
5696 KB |
Partially correct |
12 |
Partially correct |
45 ms |
5552 KB |
Partially correct |
13 |
Partially correct |
46 ms |
5424 KB |
Partially correct |
14 |
Partially correct |
43 ms |
5432 KB |
Partially correct |
15 |
Partially correct |
48 ms |
6060 KB |
Partially correct |
16 |
Partially correct |
44 ms |
5952 KB |
Partially correct |
17 |
Partially correct |
53 ms |
5824 KB |
Partially correct |
18 |
Correct |
54 ms |
5832 KB |
Output is correct |
19 |
Partially correct |
66 ms |
5824 KB |
Partially correct |
20 |
Correct |
19 ms |
4928 KB |
Output is correct |
21 |
Correct |
19 ms |
5124 KB |
Output is correct |
22 |
Correct |
22 ms |
4852 KB |
Output is correct |
23 |
Correct |
20 ms |
4844 KB |
Output is correct |
24 |
Correct |
26 ms |
4872 KB |
Output is correct |
25 |
Correct |
25 ms |
5016 KB |
Output is correct |
26 |
Correct |
28 ms |
5008 KB |
Output is correct |
27 |
Correct |
26 ms |
5008 KB |
Output is correct |
28 |
Correct |
23 ms |
4856 KB |
Output is correct |
29 |
Correct |
31 ms |
4592 KB |
Output is correct |
30 |
Correct |
28 ms |
4860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
5800 KB |
Output is correct |
2 |
Correct |
47 ms |
6032 KB |
Output is correct |
3 |
Correct |
44 ms |
5824 KB |
Output is correct |
4 |
Incorrect |
46 ms |
6032 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |