Submission #592647

#TimeUsernameProblemLanguageResultExecution timeMemory
592647PiejanVDCStations (IOI20_stations)C++17
100 / 100
996 ms852 KiB
#include <bits/stdc++.h> #include "stations.h" using namespace std; vector<int>adj[1005]; vector<int>l; int curr = 0; void dfs(int u, bool f, int e = -1) { if(f) l[u] = curr++; for(auto z : adj[u]) if(z != e) { dfs(z, 1 - f, u); } if(!f) l[u] = curr++; } vector<int>label(int n, int k, vector<int>u, vector<int>v) { l.resize(n, -1); curr = 0; for(int i = 0 ; i < n ; 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); for(auto z : l) assert(z != -1); return l; } int find_next_station(int s, int t, vector<int>c) { if(c.size() == 1) return c[0]; if(s == 0) { for(int i = 0 ; i < c.size() ; i++) { if(t >= s && t <= c[i]) return c[i]; } } if(s < c[0]) { if(t <= c.back() && t <= s) return c.back(); if(t >= c.back() && t >= s) return c.back(); for(int i = 0 ; i < c.size()-1 ; i++) { if(t >= s && t <= c[i]) return c[i]; } } else { if(t <= c[0] && t <= s) return c[0]; if(t >= c[0] && t >= s) return c[0]; for(int i = c.size()-1 ; i > 0 ; i--) { if(t <= s && t >= c[i]) return c[i]; } } }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i = 0 ; i < c.size() ; i++) {
      |                         ~~^~~~~~~~~~
stations.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int i = 0 ; i < c.size()-1 ; i++) {
      |                         ~~^~~~~~~~~~~~
stations.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
   76 | }
      | ^
#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...