제출 #560938

#제출 시각아이디문제언어결과실행 시간메모리
560938Koosha_mv즐거운 행로 (APIO20_fun)C++14
100 / 100
206 ms24736 KiB
#include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first #include "fun.h" const int N=1e5+99; int n,rt,lid,last[N],dist[N]; vector<int> ans,g[N],vec[N]; int cmp(int u,int v){ return dist[u]<dist[v]; } int get1(int u,int v){ return hoursRequired(u,v); } int get2(int u,int v){ return attractionsBehind(u,v); } int get(int u){ if(vec[u].size()==0) return -N; return dist[vec[u].back()]; } void findcentroid(){ int sz=n+1; rt=-1; f(i,0,n){ int res=get2(0,i); if(res>=(n+1)/2 && res<sz){ rt=i; sz=res; } } } bool check(){ f(i,0,3){ int sum=0; f(j,0,3) sum+=vec[j].size(); if(sum==2*sz(vec[i])){ return 1; } } return 0; } vector<int> createFunTour(int _n, int Q) { vector<int> adj; n=_n; findcentroid(); f(i,0,n){ dist[i]=get1(rt,i); if(dist[i]==1) adj.pb(i); } f(i,0,n){ if(rt==i) continue ; f(j,0,adj.size()){ if(j==adj.size()-1 || dist[i]==get1(adj[j],i)+1){ vec[j].pb(i); break; } } } lid=3; last[0]=last[1]=N; f(i,0,3) sort(all(vec[i]),cmp); f(i,1,3) if(vec[i].size()>vec[0].size()) swap(vec[i],vec[0]); int i=0; if(vec[1].size()+vec[2].size()<vec[0].size()){ while(vec[0].size()){ ans.pb(vec[0].back()); vec[0].pop_back(); if(vec[1].size() && (get(1)>=get(2))) ans.pb(vec[1].back()),vec[1].pop_back(); else if(vec[2].size()) ans.pb(vec[2].back()),vec[2].pop_back(); } ans.pb(rt); return ans; } while(check()==0){ int id=-1; f(i,0,3) if(vec[i].size() && i!=lid && (id==-1 || get(id)<get(i))){ id=i; } last[i]=dist[vec[id].back()]; ans.pb(vec[id].back()); vec[id].pop_back(); lid=id; i^=1; } f_(i,1,0){ if(vec[i].size()<vec[i+1].size()){ swap(vec[i],vec[i+1]); if(lid==i || lid==i+1) lid^=i^(i+1); } } if(get(0)<=last[i] && max(get(1),get(2))<=last[i^1]){ while(vec[0].size()){ ans.pb(vec[0].back()); vec[0].pop_back(); if(vec[2].size()==0 || (vec[1].size() && dist[vec[1].back()]>dist[vec[2].back()])){ ans.pb(vec[1].back()); vec[1].pop_back(); } else{ ans.pb(vec[2].back()); vec[2].pop_back(); } } } else if(get(0)<=last[i^1] && max(get(1),get(2))==get(3^lid) && max(get(1),get(2))<=last[i]){ while(vec[0].size()){ if(vec[2].size()==0 || (vec[1].size() && dist[vec[1].back()]>dist[vec[2].back()])){ ans.pb(vec[1].back()); vec[1].pop_back(); } else{ ans.pb(vec[2].back()); vec[2].pop_back(); } ans.pb(vec[0].back()); vec[0].pop_back(); } } else{ eror(2); assert(0); } ans.pb(rt); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   73 |   f(j,0,adj.size()){
      |     ~~~~~~~~~~~~~~             
fun.cpp:73:3: note: in expansion of macro 'f'
   73 |   f(j,0,adj.size()){
      |   ^
fun.cpp:74:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    if(j==adj.size()-1 || dist[i]==get1(adj[j],i)+1){
      |       ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...