Submission #296267

#TimeUsernameProblemLanguageResultExecution timeMemory
296267nvmdavaRail (IOI14_rail)C++17
30 / 100
83 ms604 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; #define ff first #define ss second int d[5005][3]; vector<pair<int, int> > rh, lh; int lo[5005], st[5005]; void solve(int con, int flip, vector<pair<int, int> >& v){ sort(v.begin(), v.end()); int r = -1; for(auto& x : v){ if(r == -1 || getDistance(r, x.ss) != x.ff - lo[r]){ lo[r = x.ss] = x.ff; st[r] = 1; } else { lo[x.ss] = lo[r] - (x.ff - lo[r]); st[x.ss] = -1; } } for(auto& x : v){ st[x.ss] *= flip; lo[x.ss] = con + flip * lo[x.ss]; } } void findLocation(int N, int first, int location[], int stype[]){ int le, ri; int n = N; le = 0; int tt = 2000000; if(n == 1){ location[0] = first; stype[0] = 1; return; } for(int i = 0; i < n; ++i){ if(le == i) continue; d[i][0] = getDistance(le, i); if(d[i][0] < tt){ ri = i; tt = d[i][0]; } } tt = 2000000; for(int i = 0; i < n; ++i){ if(ri == i) continue; d[i][1] = getDistance(ri, i); if(d[i][1] < tt){ le = i; tt = d[i][1]; } } lo[ri] = first + d[ri][0]; st[ri] = 1; lo[le] = lo[ri] - d[le][1]; st[le] = -1; d[0][0] = 2 * d[ri][0]; d[ri][1] = 2 * d[le][1]; for(int i = 0; i < n; ++i){ if(le == i || ri == i) continue; if(d[i][0] == d[i][1] + d[ri][0]) rh.push_back({d[i][1], i}); else lh.push_back({d[i][0] - (d[ri][0] - d[le][1]), i}); } solve(lo[le], 1, lh); solve(lo[ri], -1, rh); for(int i = 0; i < n; ++i){ location[i] = lo[i]; stype[i] = (st[i] == 1 ? 2 : 1); } }

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:60:26: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |  lo[ri] = first + d[ri][0];
      |                   ~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...