Submission #615899

#TimeUsernameProblemLanguageResultExecution timeMemory
615899fvogel499Stations (IOI20_stations)C++17
0 / 100
984 ms47668 KiB
#include "stations.h" #include <vector> #include <bits/stdc++.h> using namespace std; vector<int> graph [1000*1000]; vector<int> assign; int curT; void dfs(int x, int p = -1, int h = 0) { if (h%2 == 0) { assign[x] = curT; curT++; } for (int y : graph[x]) if (y != p) { dfs(y, x, h+1); } if (h%2 == 1) { assign[x] = curT; curT++; } } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for (int i = 0; i < n; i++) { graph[i].clear(); } for (int i = 0; i < n-1; i++) { graph[u[i]].push_back(v[i]); graph[v[i]].push_back(u[i]); } assign = vector<int>(n, -1); curT = 0; dfs(0); return assign; } int find_next_station(int curL, int tarL, std::vector<int> adj) { sort(adj.begin(), adj.end()); if (curL == 0) { // the root for (int i : adj) { if (tarL <= i) { return i; } } assert(false); return -1; } vector<pair<int, pair<int, int>>> ints; int parent; if (adj[0] > curL) { parent = adj.back(); for (int i = 0; i < adj.size()-1; i++) { int bef = curL+1; if (i) bef = adj[i-1]+1; ints.push_back({adj[i], {bef, adj[i]}}); } } else { parent = adj[0]; assert(adj.back() < curL); for (int i = 1; i < adj.size(); i++) { int aft = curL-1; if (i+1 < adj.size()) aft = adj[i+1]-1; ints.push_back({adj[i], {adj[i], aft}}); } } for (auto i : ints) { if (i.second.second <= tarL && tarL <= i.second.second) { return i.first; } } return parent; }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:21: 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 < adj.size()-1; i++) {
      |                   ~~^~~~~~~~~~~~~~
stations.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (int i = 1; i < adj.size(); i++) {
      |                   ~~^~~~~~~~~~~~
stations.cpp:65:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |    if (i+1 < adj.size()) aft = adj[i+1]-1;
      |        ~~~~^~~~~~~~~~~~
#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...