제출 #803014

#제출 시각아이디문제언어결과실행 시간메모리
803014I_Love_EliskaM_기지국 (IOI20_stations)C++14
0 / 100
1 ms484 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<n;++i) #define pb push_back #define all(x) x.begin(), x.end() using ll = long long; const int N=1e3; int l[N], r[N]; vector<int> adj[N]; int nxt=0; int col[N]; void dfs(int u, int p, int c) { col[u]=c; l[u]=nxt++; for(auto&v:adj[u]) { if (v==p) continue; dfs(v,u,!c); } r[u]=nxt++; } vector<int> label(int n, int k, vector<int>u, vector<int> v) { forn(i,n) adj[i].clear(); nxt=0; forn(i,n-1) { adj[u[i]].pb(v[i]); adj[v[i]].pb(u[i]); } dfs(0,-1,0); vector<int> ans(n); forn(i,n) { if (col[i]) { ans[i]=l[i]; } else { ans[i]=r[i]; } } set<int> s; forn(i,n) s.insert(ans[i]); int mex=0; map<int,int> c; for(auto&x:s) c[x]=mex++; forn(i,n) ans[i]=c[ans[i]]; forn(i,n) cout<<ans[i]<<' '; cout<<'\n'; return ans; } int is_ancestor(int l, int r, int y) { //x is anc of y return l <= y && y <= r; } int find_next_station(int s, int t, vector<int> adj) { //cout<<"? "<<s<<' '<<t<<": "; for(auto&x:adj) cout<<x<<' '; cout<<'\n'; if (adj.size()==1) return adj[0]; if (s > adj.back()) { int l=2*adj[1]-1; int r=2*s; if (is_ancestor(l,r,2*t)) { for (int i=1; i<adj.size()-1; ++i) { int l=2*adj[i], r=2*adj[i+1]-1; if (is_ancestor(l,r,2*t)) return adj[i]; } return adj.back(); } else { return adj[0]; } } else { int l=2*s; int r=2*adj[adj.size()-2]+1; if (is_ancestor(l,r,2*t)) { for (int i=1; i<adj.size()-1; ++i) { int l=2*adj[i-1]+1, r=2*adj[i]; if (is_ancestor(l,r,2*t)) return adj[i]; } return adj[0]; } else { return adj.back(); } } //assert(0); exit(0); }

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

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:4:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
      |                   ^~~
stations.cpp:25:2: note: in expansion of macro 'forn'
   25 |  forn(i,n) adj[i].clear(); nxt=0;
      |  ^~~~
stations.cpp:25:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   25 |  forn(i,n) adj[i].clear(); nxt=0;
      |                            ^~~
stations.cpp:4:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
      |                   ^~~
stations.cpp:45:2: note: in expansion of macro 'forn'
   45 |  forn(i,n) cout<<ans[i]<<' '; cout<<'\n';
      |  ^~~~
stations.cpp:45:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |  forn(i,n) cout<<ans[i]<<' '; cout<<'\n';
      |                               ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    for (int i=1; i<adj.size()-1; ++i) {
      |                  ~^~~~~~~~~~~~~
stations.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for (int i=1; i<adj.size()-1; ++i) {
      |                  ~^~~~~~~~~~~~~
#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...