# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
917096 |
2024-01-27T07:04:13 Z |
rxlfd314 |
Rail (IOI14_rail) |
C++17 |
|
292 ms |
98952 KB |
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
using ari2 = array<int, 2>;
#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)
#define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d))
#define FOR(a, b, c) REP(a, b, c, 1)
#define ROF(a, b, c) REP(a, b, c, -1)
void findLocation(int N, int first, int location[], int stype[]) {
memset(stype, 0, sizeof(stype));
location[0] = first;
stype[0] = 1;
if (N < 2)
return;
vt<vt<int>> D(N, vt<int>(N));
FOR(i, 0, N-1)
FOR(j, i+1, N-1)
D[i][j] = D[j][i] = getDistance(i, j);
int f[N];
FOR(i, 0, N-1) {
ari2 best = {INT_MAX, 0};
FOR(j, 0, N-1)
if (j != i)
best = min(best, ari2{D[i][j], j});
f[i] = best[1];
}
vt<int> adj[N];
FOR(i, 0, N-1) {
adj[i].push_back(f[i]);
if (i != f[f[i]])
adj[f[i]].push_back(i);
}
function<void(int)> dfs = [&](int i) {
for (int j : adj[i]) {
if (stype[j])
continue;
location[j] = location[i] + (stype[i] == 1 ? 1 : -1) * D[i][j];
stype[j] = 3 - stype[i];
dfs(j);
}
};
dfs(0);
FOR(i, 0, N-1) {
if (stype[i])
continue;
int j = f[i];
if (D[0][i] == D[0][f[0]] + D[f[0]][i]) { // to the left of 0
if (D[0][i] > D[0][j]) { // i is 2
stype[j] = 1;
location[j] = location[f[0]] - D[f[0]][j];
dfs(j);
} else {
stype[i] = 1;
location[i] = location[f[0]] - D[f[0]][i];
dfs(i);
}
} else {
if (D[0][i] > D[0][j]) { // i is 1
stype[j] = 2;
location[j] = location[0] + D[0][j];
dfs(j);
} else {
stype[i] = 2;
location[i] = location[0] + D[0][i];
dfs(i);
}
}
}
}
Compilation message
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:15:27: warning: 'sizeof' on array function parameter 'stype' will return size of 'int*' [-Wsizeof-array-argument]
15 | memset(stype, 0, sizeof(stype));
| ~^~~~~~
rail.cpp:14:57: note: declared here
14 | void findLocation(int N, int first, int location[], int stype[]) {
| ~~~~^~~~~~~
rail.cpp:15:20: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
15 | memset(stype, 0, sizeof(stype));
| ^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
520 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
290 ms |
98900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
98952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |