제출 #198415

#제출 시각아이디문제언어결과실행 시간메모리
198415FerThugGato12500Split the Attractions (IOI19_split)C++14
컴파일 에러
0 ms0 KiB
#include<iostream> #include<algorithm> #include<vector> #include<string.h> using namespace std; vector<int> ed[100001]; int need[3]; int n, m; bool vis[100001]; int cld[100001]; int dfs(int ind) { int D=1; vis[ind]=true; for(int i = 0; i < ed[ind].size(); i++) if(!vis[ed[ind][i]]) D+=dfs(ed[ind][i]); return (cld[ind] = D); } int bus(int ind) { bool z=true; vis[ind]=true; for(int i = 0; i < ed[ind].size(); i++) if(!vis[ed[ind][i]] && cld[ed[ind][i]]>=n/2) z=false; if(n-cld[ind]>=n/2) z=false; if(z) return ind; int D=-1; for(int i = 0; i < ed[ind].size(); i++) if(!vis[ed[ind][i]]) D=max(bus(ed[ind][i]), D); return D; } int centroide() { dfs(1); memset(vis, false, sizeof(vis)); return bus(1); } vector<int> ans[3]; int rey; typedef struct { int to, cld; }Wasd; bool operator < (const Wasd &a, const Wasd &b) { return a.cld < b.cld; } void expand(int ind) { vis[ind]=true; ans[rey].push_back(ind); if(ans[rey].size()==need[rey]) return; vector<Wasd> ed2; Wasd te; for(int i = 0; i < ed[ind].size(); i++) { te.to=ed[ind][i]; te.cld=cld[te.to]-cld[ind]; if(te.cld<0) te.cld=cld[te.to]; ed2.push_back(te); } sort(ed2.begin(), ed2.end()); for(int i = 0; i < ed2.size(); i++) if(!vis[ed2[i].to] && ans[rey].size()<need[rey]) expand(ed2[i].to); return; } int res[100001]; int[] find_split(int N, int a, int b, int c, int p[], int q[]) { n=N; need[0]=a; need[1]=b; need[2]=c; m=sizeof(p); int x, y; for(int i = 0; i < m; i++) { x=p[i]; y=q[i]; ed[x].push_back(y); ed[y].push_back(x); } int cnt = centroide(); if(need[0]<=max(need[1], need[2]) && need[0]>=min(need[2], need[1])) rey=0; else if(need[1]<=max(need[0], need[2]) && need[1]>=min(need[2], need[0])) rey=1; else rey=2; memset(vis, false, sizeof(vis)); expand(cnt); if(need[0]<=need[1] && need[0]<=need[2]) rey=0; else if(need[1]<=need[0] && need[1]<=need[2]) rey=1; else rey=2; for(int i = 0; i < n; i++) if(!vis[i]) { expand(i); if(ans[rey].size()==need[rey]) break; ans[rey].clear(); } for(int k = 0; k < 3; k++) for(int i = 0; i < ans[k].size(); i++) res[ans[k][i]]=k+1; if(ans[0].size()>0 && ans[1].size()>0) rey=2; else if(ans[1].size()>0 && ans[2].size()>0) rey=0; else rey=1; for(int i = 0; i < n; i++) if(res[i]==0) res[i] = rey+1; vector<int> find_split(vector<int> respuesta); for(int i = 0; i < n; i++) respuesta.push_back(res[i]); return respuesta; }

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

split.cpp: In function 'int dfs(int)':
split.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ed[ind].size(); i++)
                 ~~^~~~~~~~~~~~~~~~
split.cpp: In function 'int bus(int)':
split.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ed[ind].size(); i++)
                 ~~^~~~~~~~~~~~~~~~
split.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ed[ind].size(); i++)
                 ~~^~~~~~~~~~~~~~~~
split.cpp: In function 'void expand(int)':
split.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(ans[rey].size()==need[rey])
     ~~~~~~~~~~~~~~~^~~~~~~~~~~
split.cpp:60:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ed[ind].size(); i++)
                 ~~^~~~~~~~~~~~~~~~
split.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ed2.size(); i++)
                 ~~^~~~~~~~~~~~
split.cpp:69:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(!vis[ed2[i].to] && ans[rey].size()<need[rey])
                         ~~~~~~~~~~~~~~~^~~~~~~~~~
split.cpp: At global scope:
split.cpp:74:4: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
 int[] find_split(int N, int a, int b, int c, int p[], int q[])
    ^
split.cpp:74:4: error: decomposition declaration cannot be declared with type 'int'
 int[] find_split(int N, int a, int b, int c, int p[], int q[])
    ^~
split.cpp:74:4: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
split.cpp:74:4: error: empty decomposition declaration
split.cpp:74:7: error: expected initializer before 'find_split'
 int[] find_split(int N, int a, int b, int c, int p[], int q[])
       ^~~~~~~~~~