QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#532821#5080. Folding StickBongoCatEnjoyer#WA 0ms3856kbC++141.4kb2024-08-25 12:46:312024-08-25 12:46:31

Judging History

你现在查看的是最新测评结果

  • [2024-08-25 12:46:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-08-25 12:46:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define forr(i, s, n) for (ll i = s; i < n; ++i)
#define fori(i, s, n) for (ll i = s; i > n; --i)
#define fora(i, n) for (auto i: n)
#define vi vector<int>
#define vll vector<ll>
#define prints(n) cout << (n) << " "
#define println(n) cout << (n) << "\n"
#define newl() cout << "\n"

const int MOD = 998244353;
// const int MOD = 1e9 + 7;

void solve() {
    ll n; cin >> n;
    vector<ll> a(n); fora(&x, a) cin >> x;
    vector<ll> suf(n + 1), pre(n + 1);

    fori(i, n - 1, -1) suf[i] = suf[i + 1] + a[i];
    forn(i, n) pre[i + 1] = pre[i] + a[i];

    ll ans = max(a[0], suf[1]);
    vector<ll> dp(n, LONG_LONG_MAX); dp[0] = a[0];

    ll p = 0;
    forr(i, 1, n) {
        dp[i] = dp[i - 1] + a[i];

        forr(j, p, i) {
            // prints(pre[i + 1] - pre[j + 1]); println(dp[j]);
            if (pre[i + 1] - pre[j + 1] >= dp[j]) {
                dp[i] = pre[i + 1] - pre[j + 1];
                ans = min(ans, max(dp[i], suf[i + 1]));
                p = j + 1;
                // println("DEMN");
                break;
            }
        }
    }

    println(ans);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3852kb

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3856kb

input:

9
5 6 3 4 8 8 2 2 5

output:

12

result:

wrong answer 1st lines differ - expected: '9', found: '12'