# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1073014 |
2024-08-24T08:36:06 Z |
Ignut |
Stations (IOI20_stations) |
C++17 |
|
627 ms |
764 KB |
// Ignut
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1111;
vector<int> tree[N];
vector<int> dist;
void dfs(int v, int par, int d) {
dist[v] = d;
for (int to : tree[v])
if (to != par)
dfs(to, v, d + 1);
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i = 0; i < n; i ++) {
tree[i].clear();
}
for (int i = 0; i < n - 1; i ++) {
tree[u[i]].push_back(v[i]);
tree[v[i]].push_back(u[i]);
}
vector<int> lbl(n);
dist.resize(n);
for (int i = 0; i < n; i ++) {
dfs(i, -1, 0);
vector<pair<int, int>> vec;
for (int j = 0; j < n; j ++) vec.push_back({dist[j], j});
sort(vec.begin(), vec.end());
lbl[i] = 0;
for (int j = 0; j < n; j ++) lbl[i] = lbl[i] * 10 + vec[j].second + 1;
}
// for (int val : lbl) cerr << val << ' ';
// cerr << '\n';
return lbl;
}
const int INF = 1e9 + 123;
int find_next_station(int s, int t, vector<int> c) {
if (c.size() == 1) return c[0];
for (int val : c) if (val == t) return t;
// int tval;
int tval = to_string(t)[0];
while (t >= 10) t /= 10;
if (t != tval)
s /= 0;
tval = t;
int bestPos = INF, ret = -1;
for (int v : c) {
string str = to_string(v);
for (int i = 0; i < str.size(); i ++) {
if ((str[i] - '0') == tval) {
if (i < bestPos) {
bestPos = i;
ret = v;
}
}
}
}
return ret;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:11: warning: division by zero [-Wdiv-by-zero]
61 | s /= 0;
| ~~^~~~
stations.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < str.size(); i ++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
308 ms |
544 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1803652948 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
318 ms |
520 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=-106048686 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
552 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=0, label=1868970828 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
627 ms |
684 KB |
Output is correct |
2 |
Correct |
494 ms |
684 KB |
Output is correct |
3 |
Correct |
417 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Incorrect |
2 ms |
764 KB |
Wrong query response. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
287 ms |
544 KB |
Invalid labels (duplicates values). scenario=1, label=294615046 |
2 |
Halted |
0 ms |
0 KB |
- |