Submission #1024821

#TimeUsernameProblemLanguageResultExecution timeMemory
1024821HappyCapybaraStations (IOI20_stations)C++17
0 / 100
611 ms696 KiB
#include "stations.h" #include<bits/stdc++.h> using namespace std; int cnt; vector<vector<int>> g; vector<int> in, out, d; void dfs(int cur, int dep){ if (d[cur] != -1) return; d[cur] = dep; in[cur] = cnt++; for (int next : g[cur]) dfs(next, dep+1); out[cur] = cnt++; } vector<int> label(int n, int k, vector<int> u, vector<int> v){ g.resize(n); for (int i=0; i<n-1; i++){ g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } in.resize(n); out.resize(n); d.resize(n, -1); cnt = 0; dfs(0, 0); vector<int> l(n); for (int i=0; i<n; i++){ if (d[i] % 2) l[i] = out[i]; else l[i] = in[i]; } vector<int> w = l; sort(w.begin(), w.end()); unordered_map<int,int> m; for (int i=0; i<n; i++) m[w[i]] = i; for (int i=0; i<n; i++) l[i] = m[l[i]]; return l; } int find_next_station(int s, int t, vector<int> c){ if (c.size() == 0) return c[0]; if (s == 0){ vector<int> d(c.size()); for (int i=0; i<c.size(); i++){ if (i == 0) d[i] = s+1; else d[i] = c[i-1]+1; if (d[i] <= t && t <= c[i]) return c[i]; } } else { int x = 2000; for (int y : c) x = min(x, y); if (s < x){ vector<int> d(c.size()-1); for (int i=0; i<c.size()-1; i++){ if (i == 0) d[i] = s+1; else d[i] = c[i-1]+1; if (d[i] <= t && t <= c[i]) return c[i]; } return c.back(); } else { vector<int> d(c.size()); for (int i=c.size()-1; i>=0; i--){ if (i == c.size()-1) d[i] = s-1; else d[i] = c[i+1]-1; if (c[i] <= t && t <= d[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:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for (int i=0; i<c.size(); i++){
      |                 ~^~~~~~~~~
stations.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |    for (int i=0; i<c.size()-1; i++){
      |                  ~^~~~~~~~~~~
stations.cpp:64:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     if (i == c.size()-1) d[i] = s-1;
      |         ~~^~~~~~~~~~~~~
stations.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
   71 | }
      | ^
#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...