QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831214 | #3306. Alchemy | 通顶雪道 (Qiuyang Mang, Youran Sun, Qingshuo Guo)# | TL | 691ms | 3912kb | C++23 | 1.2kb | 2024-12-25 11:49:00 | 2024-12-25 11:49:00 |
Judging History
answer
#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int ch = 0, f = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
const int N = 1e5 + 5;
int n, a[N];
ll sum;
bool check(int x){
ll all = 0;
for(int i = x; i < n; i++) all += a[i];
ll need = 1;
for(int i = x - 1; i >= 1; i--){
if(a[i] >= need){
all += a[i] - need;
}
else{
need += need - a[i];
if(need > sum) return false;
}
}
return (a[0] + all >= need);
}
int main(){
read(n);
for(int i = 0; i < n; i++){
read(a[i]);
sum += a[i];
}
if(sum == 1){
int ans = 1;
for(int i = 0; i < n; i++){
if(a[i]) ans = max(ans, i);
}
printf("%d", ans);
return 0;
}
int ans = 0;
for(;;ans++){
if(!check(ans)) break;
}
printf("%d", ans - 1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 0 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
6 1 0 0 0 0 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
5 0 0 0 0 1
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
5 1 0 1 0 1
output:
3
result:
ok single line: '3'
Test #6:
score: 0
Accepted
time: 691ms
memory: 3912kb
input:
37720 451489069 134056336 620111578 342027410 502394496 867334619 610344031 578827762 547285146 267992868 980119426 496668202 432397098 278008842 790299797 27195229 983722405 177368018 498316364 787982913 98623319 974381888 186181726 669284760 932969833 209389252 84919178 953916913 910171707 4407773...
output:
37735
result:
ok single line: '37735'
Test #7:
score: 0
Accepted
time: 192ms
memory: 3788kb
input:
20243 471684350 97875871 557768760 955640662 518134695 999433988 49418001 188859938 824647213 917716596 87612792 972935058 881415865 792871180 604982299 37698696 822908242 851904620 788441983 322982867 23448976 589236644 778829887 739523914 576565037 597334056 513285189 891913234 928416035 649332462...
output:
20260
result:
ok single line: '20260'
Test #8:
score: -100
Time Limit Exceeded
input:
68040 90505946 57877510 356650756 172607034 771055813 371577414 620115877 414312295 627264104 457909314 378686562 309478575 273752740 820954532 925010598 279152164 302713418 746578406 787352631 978104601 447427926 775531762 116467407 741031346 102835428 397692660 360174034 477922374 804312397 969215...