제출 #1266133

#제출 시각아이디문제언어결과실행 시간메모리
1266133gustavo_dShortcut (IOI16_shortcut)C++20
0 / 100
0 ms328 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 3000; const ll INF = 1e18; int n; ll pf[MAXN], sf[MAXN]; int p[MAXN], pfPai[MAXN], sfPai[MAXN]; ll pos[MAXN+2]; ll find_shortcut(int N, vector<int> l, vector<int> d, int c) { n = N; pf[0] = d[0]; pfPai[0] = 0; for (int i=0; i<n-1; i++) { pfPai[i+1] = (d[i+1] >= pf[i]+l[i] ? i+1 : pfPai[i]); pf[i+1] = max( (ll)d[i+1], pf[i] + l[i] ); } sf[n-1] = d[n-1]; sfPai[n-1] = n-1; for (int i=n-2; i>=0; i--) { sfPai[i] = (d[i] >= sf[i+1] + l[i] ? i : sfPai[i+1]); sf[i] = max( (ll)d[i], sf[i+1] + l[i] ); } int center = 0; for (int i=0; i<n-1; i++) { if (pf[i] + sf[i+1] + l[i] > pf[center] + sf[center+1] + l[center]) center = i; } n = 0; pos[n++] = 0; bool left = false, right = false; if (d[pfPai[center]] > 0) { left = true; p[n] = pfPai[center]; pos[n++] = d[pfPai[center]]; } for (int i=pfPai[center]; i<sfPai[center+1]; i++) { pos[n] = pos[n-1] + l[i]; p[n] = i+1; n++; } if (d[sfPai[center+1]] > 0) { right = true; pos[n] = pos[n-1] + d[sfPai[center+1]]; n++; } int pL = pfPai[center], pR = sfPai[center+1]; ll costL = (pL > 0 ? pf[pL-1] + l[pL-1] + d[pL] : 0LL), costR = (pR < N-1 ? sf[pR+1] + l[pR] + d[pR] : 0LL); ll ans = pf[center] + sf[center + 1] + l[center]; for (int i=left; i<n-right; i++) { for (int j=i+1; j<n-right; j++) { if (pos[j] - pos[i] <= c) continue; ll res = max({pos[i] + c + pos[n-1] - pos[j], costL, costR}); for (int u=i+1; u<j; u++) { for (int v=u+1; v<j; v++) { res = max({ res, min(pos[v]-pos[u], pos[j]-pos[i]+c-(pos[v]-pos[u])) }); } } for (int k=i+1; k<j; k++) { res = max({ res, min(pos[k], pos[j]-pos[k]+c+pos[i]) + d[p[k]], min(pos[n-1]-pos[k], pos[k]-pos[i]+c+pos[n-1]-pos[j]) + d[p[k]] }); } ans = min(ans, res); } } return ans; }

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

shortcut.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
shortcut_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...