Submission #968609

#TimeUsernameProblemLanguageResultExecution timeMemory
968609gry3125Bitaro's travel (JOI23_travel)C++14
0 / 100
3 ms500 KiB
#include <iostream> #include <vector> #include <deque> #include <algorithm> using namespace std; int main() { int N; cin >> N; vector<int> x(N); for(int i=0;i<N;i++){ cin >> x[i]; } int Q; cin >> Q; int s; int dist; vector<int> v(N); int a, count; int best, min, pos, ii, smth; for(int i=0;i<Q;i++){ cin >> s; dist=0; count=0; fill(v.begin(), v.end(), 0); a=find(x.begin(), x.end(), s)-x.begin(); if(a!=N){ v[a]=1; count++; } min = 1000000000; for (int o = 0; o < N; o++) { if (v[o] == 0) { if (abs(s - x[o]) < min) { best = o; min = abs(s - x[o]); } } } dist+=abs(s - x[best]); v[best]=1; s=x[best]; pos=best; count++; while(count<N){ min = 1000000000; ii=pos+1; while(ii<N && min==1000000000){ if(v[ii]==0){ best=ii; min = abs(s - x[ii]); } ii++; } smth=0; ii=pos-1; while(ii>-1 && smth==0){ if(v[ii]==0){ if(abs(s-x[ii]<min)){ best=ii; min = abs(s - x[ii]); smth=1l; } } ii++; } for (int o = pos-1; o>-1; o--) { if (v[o] == 0) { if (abs(s - x[o]) < min) { best = o; min = abs(s - x[o]); } } } dist+=abs(s - x[best]); v[best]=1; s=x[best]; count++; } cout << dist << "\n"; } return 0; }

Compilation message (stderr)

travel.cpp: In function 'int main()':
travel.cpp:42:29: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |         dist+=abs(s - x[best]);
      |                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...