# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
946007 |
2024-03-14T09:31:36 Z |
yellowtoad |
Rail (IOI14_rail) |
C++17 |
|
47 ms |
852 KB |
#include "rail.h"
#include <iostream>
#include <algorithm>
#include <vector>
#define f first
#define s second
#define get getDistance
using namespace std;
long long cur, dis, pos, l, r, mid, xx;
vector<long long> c, d;
vector<pair<long long, long long>> tmp;
pair<long long,long long> dist[5010];
void findLocation(int n, int x, int location[], int stype[])
{
for (int i = 1; i < n; i++) dist[i] = {get(0,i),i};
sort(dist+1,dist+n);
location[0] = x; stype[0] = 1;
location[dist[1].s] = x+dist[1].f; stype[dist[1].s] = 2;
d.push_back(x+dist[1].f);
cur = dist[1].s;
for (int i = 2; i < n; i++) {
dis = get(cur,dist[i].s);
pos = d.back()-dis;
l = 0; r = d.size()-1;
while (l <= r) {
mid = (l+r)/2;
if (pos < d[mid]) r = mid-1;
else l = mid+1;
}
if (dist[i].f == d[l]-x+(d[l]-pos)) {
if (pos < x) tmp.push_back({dist[i].f-dist[1].f*2,dist[i].s});
else location[dist[i].s] = pos, stype[dist[i].s] = 1;
} else {
d.push_back(x+dist[i].f);
cur = dist[i].s;
location[dist[i].s] = x+dist[i].f;
stype[dist[i].s] = 2;
}
}
if (tmp.size()) {
location[tmp[0].s] = x-tmp[0].f; stype[tmp[0].s] = 1;
c.push_back(x-tmp[0].f);
cur = tmp[0].s;
}
for (int i = 1; i < tmp.size(); i++) {
dis = get(cur,tmp[i].s);
pos = c.back()+dis;
l = 0; r = c.size()-1;
while (l <= r) {
mid = (l+r)/2;
if (pos < c[mid]) r = mid-1;
else l = mid+1;
}
if (tmp[i].f == x-c[r]+pos-c[r]) {
location[tmp[i].s] = pos, stype[tmp[i].s] = 2;
} else {
c.push_back(x-tmp[i].f);
cur = tmp[i].s;
location[tmp[i].s] = x-tmp[i].f;
stype[tmp[i].s] = 1;
}
}
}
Compilation message
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 1; i < tmp.size(); i++) {
| ~~^~~~~~~~~~~~
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
532 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |