제출 #538599

#제출 시각아이디문제언어결과실행 시간메모리
538599chaoyue선물상자 (IOI15_boxes)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; #define ll long long ll delivery(int N, int K, int L, int p[]){ ll split = L/2, idx=0, lsize=1, rsize=1, f0, ans; vector<ll> left(N), right(N); left[0] = 0, right[0] = 0; while(idx < N && p[idx] <= split){ left[lsize] = p[idx] * 2; if(lsize >= K) left[lsize] += left[lsize-K]; idx++, lsize++; } while(idx < N){ right[rsize] = (L - p[idx]) * 2; if(rsize >= K) right[rsize] += right[rsize-K]; idx++, rsize++; } //left is non-decreasing //pre array will flip left & right arrays vector<ll> lpre(lsize), rpre(rsize); lpre[0] = 0; rpre[0] = 0; for(ll i=1; i<lsize; i++){ lpre[i] = lpre[i-1] + left[lsize-i] - left[lsize-i-1]; } for(ll i=1; i<rsize; i++){ rpre[i] = rpre[i-1] + right[rsize-i] - right[rsize-i-i]; } f0 = left[lsize-1] + right[rsize-1]; //initial answer if 0 loops vector<ll> opt(K, 0); //calculates optimal value of lpre assuming rpre takes i souvenirs for(ll i=0; i<K; i++){ for(ll j=0; j<N/K; j++){ idx = K - i + j*K; opt[idx] = max(opt[idx], lpre[idx] - (j+1) * N); } } for(int i=0; i<rsize; i++){ ans = max(ans, rpre[i] + opt[i%K] - i/K); } ans = max(f0, f0-ans); return ans; }

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:8:47: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
    8 |  ll split = L/2, idx=0, lsize=1, rsize=1, f0, ans;
      |                                               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...