結果
問題 |
No.1925 悪鬼三七次元
|
ユーザー |
![]() |
提出日時 | 2022-05-03 00:28:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,415 bytes |
コンパイル時間 | 2,681 ms |
コンパイル使用メモリ | 217,680 KB |
最終ジャッジ日時 | 2025-01-29 02:00:40 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 WA * 12 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI a(n); rep(i, n) cin >> a[i]; constexpr ll INF = 1002003004005006007; if (n % 2) { int m = n / 2; ll ans = INF; ll now = accumulate(a.begin(), a.begin() + m, 0LL); rep(i, m + 1) { now += a[i + m]; chmin(ans, now); now -= a[i]; } cout << ans << '\n'; return 0; } int m = n / 2; VL accmf(n + 1, INF), accmb(n + 1, INF), accm1f(n + 1, INF), accm1b(n + 1); { ll now = accumulate(a.begin(), a.begin() + m - 1, 0LL); ll acc = INF; for(int i = 0; i + m - 1 < n; i++) { now += a[i + m - 1]; chmin(acc, now); accmf[i] = acc; now -= a[i]; } } { ll now = accumulate(a.end() - (m - 1), a.end(), 0LL); ll acc = INF; for(int i = n - m; i >= 0; i--) { now += a[i]; chmin(acc, now); accmb[i] = acc; now -= a[i + m - 1]; } } m++; { ll now = accumulate(a.begin(), a.begin() + m - 1, 0LL); ll acc = INF; for(int i = 0; i + m - 1 < n; i++) { now += a[i + m - 1]; chmin(acc, now); accm1f[i] = acc; now -= a[i]; } } { ll now = accumulate(a.end() - (m - 1), a.end(), 0LL); ll acc = INF; for(int i = n - m; i >= 0; i--) { now += a[i]; chmin(acc, now); accm1b[i] = acc; now -= a[i + m - 1]; } } m--; ll ans = 0; for(int i = 0; i < n - 1; i++) { if (i < m - 1) { chmax(ans, min(accm1f[i], accmb[i + 2])); } else if (i == m - 1) { chmax(ans, accm1f[i]); } else { chmax(ans, min(accmf[i - m], accm1b[i - m + 1])); } } cout << ans << '\n'; }