Submission #798025

#TimeUsernameProblemLanguageResultExecution timeMemory
798025QwertyPiRail (IOI14_rail)C++14
30 / 100
49 ms468 KiB
#include "rail.h" #include <bits/stdc++.h> #define INF (1 << 30) using namespace std; int d0[5011], d1[5011]; void findLocation(int N, int first, int location[], int stype[]){ for(int i = 1; i < N; i++) d0[i] = getDistance(0, i); int p0 = 0; int s = INF, p1; for(int i = 1; i < N; i++) if(d0[i] < s) s = d0[i], p1 = i; for(int i = 0; i < N; i++) if(i != p1) d1[i] = getDistance(p1, i); location[p0] = first; stype[p0] = 1; location[p1] = first + s; stype[p1] = 2; vector<int> L, R; for(int i = 0; i < N; i++){ if(i != p0 && i != p1){ if(d0[i] - d1[i] == s) L.push_back(i); else R.push_back(i); } } sort(L.begin(), L.end(), [](int x, int y){ return d1[x] < d1[y]; }); sort(R.begin(), R.end(), [](int x, int y){ return d0[x] < d0[y]; }); int leftmost = p0; for(int l : L){ int dis = getDistance(leftmost, l); if(dis > d1[l] - d1[leftmost]){ location[l] = location[p1] - d1[l]; stype[l] = 1; leftmost = l; }else{ location[l] = location[leftmost] + dis; stype[l] = 2; } } int rightmost = p1; for(int r : R){ int dis = getDistance(rightmost, r); if(dis > d0[r] - d0[rightmost]){ rightmost = r; location[r] = location[p0] + d0[r]; stype[r] = 2; }else{ location[r] = location[rightmost] - dis; stype[r] = 1; } } }

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:8:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    8 |  for(int i = 1; i < N; i++) d0[i] = getDistance(0, i); int p0 = 0;
      |  ^~~
rail.cpp:8:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    8 |  for(int i = 1; i < N; i++) d0[i] = getDistance(0, i); int p0 = 0;
      |                                                        ^~~
rail.cpp:16:14: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |   if(i != p0 && i != p1){
      |      ~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...