Submission #580970

#TimeUsernameProblemLanguageResultExecution timeMemory
580970JomnoiStations (IOI20_stations)C++17
0 / 100
847 ms660 KiB
#include <bits/stdc++.h> #include "stations.h" using namespace std; const int MAX_N = 1005; int N, timer; vector <int> graph[MAX_N]; int depth[MAX_N], st[MAX_N], en[MAX_N]; void init(int n) { N = n, timer = 0; for(int i = 0; i < N; i++) { st[i] = en[i] = 0; graph[i].clear(); } } void dfs(int u, int p) { st[u] = timer++; for(auto v : graph[u]) { if(v != p) { depth[v] = depth[u] + 1; dfs(v, u); } } en[u] = timer++; } vector <int> label(int n, int k, vector <int> u, vector <int> v) { init(n); for(int i = 0; i < N - 1; i++) { graph[u[i]].push_back(v[i]); graph[v[i]].push_back(u[i]); } dfs(0, -1); vector <int> S, T; for(int i = 0; i < N; i++) { if(depth[i] % 2 == 0) { S.push_back(st[i]); } else { T.push_back(en[i]); } } sort(S.begin(), S.end()); sort(T.begin(), T.end()); vector <int> labels(N); for(int i = 0; i < N; i++) { if(depth[i] % 2 == 0) { labels[i] = lower_bound(S.begin(), S.end(), st[i]) - S.begin(); } else { labels[i] = lower_bound(T.begin(), T.end(), en[i]) - T.begin() + S.size(); } } return labels; } int find_next_station(int s, int t, vector <int> c) { if(c[0] > s) { // s is labeled with st if(t < s) { return c.back(); } for(int i = 0; i < c.size(); i++) { if(t <= c[i]) { return c[i]; } } return c.back(); } else { // s is labeled with en if(t > s) { return c[0]; } for(int i = c.size() - 1; i >= 0; i--) { if(t >= c[i]) { return c[i]; } } return c[0]; } }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(int i = 0; i < c.size(); 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...