QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#72116 | #5080. Folding Stick | ricky0129# | WA | 2ms | 3912kb | C++14 | 1003b | 2023-01-14 05:43:01 | 2023-01-14 05:43:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define FOR(i,n) for(int i=0;i<n;i++)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
const int MOD = (int)1e9+7;
int n;
const int N = 1e5+1;
int A[N];
int dp[N];
int solve(int i){
if(i>=n) return 0;
if(dp[i]!=-1) return dp[i];
//ingore the fold
int ans = solve(i+1);
int j = i;
ll curr = 0;
while(j<n && curr<A[i]){
j++;
curr+=A[j];
}
if(j==n-1) j++;
//cout<<i<<" "<<j<<endl;
ans = max(ans,solve(j)+A[i]);
return ans;
}
int main()
{
cin>>n;
ll tot = 0;
FOR(i,n){
cin>>A[i];
tot+=A[i];
}
memset(dp,-1,sizeof(dp));
tot-=solve(0);
cout<<tot<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3868kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3736kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 3912kb
input:
9 5 6 3 4 8 8 2 2 5
output:
12
result:
wrong answer 1st lines differ - expected: '9', found: '12'