QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702038 | #5080. Folding Stick | tamthegod# | WA | 3ms | 13668kb | C++23 | 1.4kb | 2024-11-02 15:09:05 | 2024-11-02 15:09:09 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[maxN];
int sum[maxN];
int f[maxN];
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
cin >> a[i];
for(int i=1; i<=n; i++)
sum[i] = sum[i - 1] + a[i];
}
void Solve()
{
memset(f, 3, sizeof f);
f[0] = 0;
for(int i=1; i<=n; i++)
{
int low = 0, high = i - 1, mid;
while(low <= high)
{
mid = (low + high) / 2;
if(f[mid] + sum[mid] <= sum[i]) low = mid + 1;
else high = mid - 1;
}
f[i] = sum[i] - sum[high];
}
int res = oo;
for(int i=1; i<=n; i++)
res = min(res, max(f[i], sum[n] - sum[i]));
cout << res;
}
#define taskname "sol"
int32_t main()
{
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
// freopen(taskname ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
//cin >> T;
for(int itest=1; itest<=T; itest++)
{
ReadInput();
Solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 13668kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 3ms
memory: 13604kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 13620kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 13616kb
input:
9 5 6 3 4 8 8 2 2 5
output:
9
result:
ok single line: '9'
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 13596kb
input:
10 5 6 3 4 8 6 2 1 8 5
output:
13
result:
wrong answer 1st lines differ - expected: '9', found: '13'