제출 #968540

#제출 시각아이디문제언어결과실행 시간메모리
968540gry3125Bitaro's travel (JOI23_travel)C++14
5 / 100
3089 ms3896 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; 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++; } while(count<N){ 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]; count++; } cout << dist << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

travel.cpp: In function 'int main()':
travel.cpp:42:24: 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...