QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175344#5080. Folding StickcsyptWA 2ms3720kbC++171.6kb2023-09-10 17:33:022023-09-10 17:33:03

Judging History

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

  • [2023-09-10 17:33:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3720kb
  • [2023-09-10 17:33:02]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int, null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> TREE;
//tree.find_by_order() / tree.order_of_key();
int n, arr[100005], dp[100005], pre[100005];
set<pair<int, int>> s;
int inc = 0;
void solve(){
    cin >> n;
    for(int i=1; i<=n; ++i){
        cin >> arr[i];
        pre[i] = pre[i-1]+arr[i];
    }
    for(int i=1; i<n; ++i){
        int last_ind = inc, max_len = -1;
        while(!s.empty()){
            auto it = s.begin();
            if(it->first > pre[i]-pre[inc] || it->first>pre[i]-pre[it->second]){
                break;
            }
            if(pre[i]-pre[it->second]>=it->first){
                inc = max(inc, it->second);
                last_ind = inc;
                s.erase(it);
            }
            else{
                last_ind = it->second;
                max_len = it->first;
                break;
            }
        }
        if(max_len<0){
            max_len = pre[i]-pre[last_ind];
        }
        dp[i] = max(max_len, pre[i]-pre[last_ind]);
        s.insert({dp[i], i});
        //cout << dp[i] << '\n';
    }
    int ans = INT_MAX;
    for(int i=1; i<n; ++i){
        if(pre[n]-pre[i]<=dp[i]){
            ans = min(ans, dp[i]);
        }
    }
    cout << ans << '\n';

}
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3680kb

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3720kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3608kb

input:

9
5 6 3 4 8 8 2 2 5

output:

10

result:

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