제출 #772556

#제출 시각아이디문제언어결과실행 시간메모리
772556khshg기지국 (IOI20_stations)C++14
76 / 100
781 ms748 KiB
#include"stations.h" #include<bits/stdc++.h> using namespace std; vector<vector<int>> adj; vector<int> L, R, sz; vector<bool> flor; void dfs(int s, int p, int low, bool flr) { flor[s] = flr; L[s] = low; R[s] = low; sz[s] = 1; int nxt_low = low + 1; for(auto& u : adj[s]) { if(u == p) continue; dfs(u, s, nxt_low, flr ^ 1); sz[s] += sz[u]; nxt_low = R[u] + 1; R[s] = R[u] + 1; } } pair<int, int> conv(int s) { return {s % 1000, s / 1000}; } int conv(pair<int, int> s) { return s.first + s.second * 1000; } vector<int> label(int N, int K, vector<int> u, vector<int> v) { flor.resize(N); sz.resize(N); L.resize(N); R.resize(N); adj.resize(N); for(auto& I : adj) I.clear(); for(int i = 0; i < (int)u.size(); ++i) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0, -1, 0, 0); vector<int> labels(N); for(int i = 0; i < N; ++i) labels[i] = (flor[i] ? R[i] : L[i]); return labels; } int find_next_station(int s, int t, vector<int> c) { if(s == 0) { pair<int, int> S = {0, c.back() + 1}, T = {t, t}; vector<pair<int, int>> C((int)c.size()); C[0] = {1, c[0]}; for(int i = 1; i < (int)c.size(); ++i) { C[i] = {c[i - 1] + 1, c[i]}; } int ans = -1; for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return c[ans]; } if(s < c[0]) { pair<int, int> S = {s, c.back() - 1}, T = {t, t}; vector<pair<int, int>> C((int)c.size()); C[0] = {s + 1, c[0]}; C.back() = {s - 1, c.back()}; for(int i = 1; i + 1 < (int)c.size(); ++i) { C[i] = {c[i - 1] + 1, c[i]}; } int par = -1, ans = -1; for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= S.first && C[i].second >= S.second) par = i; else if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return (ans == -1 ? c[par] : c[ans]); } pair<int, int> S = {c[0] + 1, s}, T = {t, t}; vector<pair<int, int>> C((int)c.size()); C.back() = {c.back(), s - 1}; C[0] = {c[0], s + 1}; for(int i = 1; i + 1 < (int)c.size(); ++i) { C[i] = {c[i], c[i + 1] - 1}; } int par = -1, ans = -1; for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= S.first && C[i].second >= S.second) par = i; else if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return (ans == -1 ? c[par] : c[ans]); /* pair<int, int> S = conv(s), T = conv(t); vector<pair<int, int>> C((int)c.size()); for(int i = 0; i < (int)c.size(); ++i) C[i] = conv(c[i]); int par = -1, ans = -1; for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= S.first && C[i].second >= S.second) par = i; else if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return (ans == -1 ? conv(C[par]) : conv(C[ans]));*/ return 0; }

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

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:50:18: warning: variable 'S' set but not used [-Wunused-but-set-variable]
   50 |   pair<int, int> S = {0, c.back() + 1}, T = {t, t};
      |                  ^
#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...