Submission #431525

#TimeUsernameProblemLanguageResultExecution timeMemory
431525idk321Stations (IOI20_stations)C++17
54.96 / 100
1200 ms824 KiB
#include "stations.h" #include <vector> using namespace std; #include <bits/stdc++.h> const int M = 1000000000; const int N = 1000; int in[N]; int out[N]; vector<int> adj[N]; vector<int> labels; int n, k; int timer; void dfs2(int node, int par) { timer++; in[node] = timer; for (int next : adj[node]) { if (next == par) continue; dfs2(next, node); } out[node] = timer; } array<int, 2> getInAndOut(int num) { int cur = 0; for (int i = 0; i < 1000; i++) { if (cur + 1000 - i < num) { cur += 1000 - i; continue; } for (int j = i; j < 1000; j++) { if (cur == num) { return {i, j}; } cur++; } } } int getLabel(int nin, int nout) { int cur = 0; for (int i = 0; i < 1000; i++) { if (i < nin) { cur += (1000 - i); continue; } for (int j = i; j < 1000; j++) { if (i == nin && j == nout) { return cur; } cur++; } } return -1; } std::vector<int> label(int n1, int k1, std::vector<int> u, std::vector<int> v) { n = n1; k = k1; labels.assign(n, 0); for (int i = 0; i < n; i++) adj[i].clear(); for (int i = 0; i < u.size(); i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } timer = -1; dfs2(0, -1); for (int i = 0; i < n; i++) { labels[i] = getLabel(in[i], out[i]); } return labels; } int find_next_station(int s, int t, std::vector<int> c) { int sIn = getInAndOut(s)[0]; int sOut = getInAndOut(s)[1]; int tIn = getInAndOut(t)[0]; int tOut = getInAndOut(t)[1]; if (sIn <= tIn && tOut <= sOut) { for (int next : c) { int nextIn = getInAndOut(next)[0]; int nextOut = getInAndOut(next)[1]; if (!(nextIn <= sIn && sOut <= nextOut) && (nextIn <= tIn && tOut <= nextOut)) return next; } } else { for (int next : c) { int nextIn = getInAndOut(next)[0]; int nextOut = getInAndOut(next)[1]; if (nextIn <= sIn && sOut <= nextOut) return next; } } return c[0]; }

Compilation message (stderr)

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