Submission #1024881

#TimeUsernameProblemLanguageResultExecution timeMemory
1024881HappyCapybaraStations (IOI20_stations)C++17
0 / 100
519 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); /*for (int x : in) cout << x << " "; cout << "\n"; for (int x : out) cout << x << " "; cout << "\n";*/ vector<int> l(n); for (int i=0; i<n; i++){ if (d[i] % 2) l[i] = out[i]; else l[i] = in[i]; } return l; 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]]; /*for (int x : l) cout << x << " "; cout << "\n";*/ return l; } int find_next_station(int s, int t, vector<int> c){ if (c.size() == 1) 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:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for (int i=0; i<c.size(); i++){
      |                 ~^~~~~~~~~
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=0; i<c.size()-1; i++){
      |                  ~^~~~~~~~~~~
stations.cpp:71:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     if (i == c.size()-1) d[i] = s-1;
      |         ~~^~~~~~~~~~~~~
stations.cpp:78:1: warning: control reaches end of non-void function [-Wreturn-type]
   78 | }
      | ^
#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...