QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340461 | #3306. Alchemy | Ishy | WA | 2ms | 6196kb | C++14 | 2.4kb | 2024-02-29 07:36:54 | 2024-02-29 07:36:56 |
Judging History
answer
// Sea, You & Me
#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) ((-x) & x)
#define MP make_pair
#define MT make_tuple
#define VI vector<int>
#define VL vector<LL>
#define VII VI::iterator
#define VLI VL::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define PII pair<int, int>
#define SI set<int>
#define SII SI::iterator
#define fi first
#define se second
using namespace std;
template<typename T> void chkmn(T &a, const T b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T b) { (a < b) && (a = b); }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int inc(const int &a, const int &b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
int res = 1;
while(k)
{
if(k & 1) Mul(res, x);
k >>= 1, Sqr(x);
}
return res;
}
template<typename T> void read(T &x)
{
x = 0;
int f = 1;
char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-')
f = -1;
ch = getchar();
}
while(isdigit(ch))
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = x * f;
}
const int N = 1e5 + 5;
int n; LL a[N << 2], w[N << 2];
bool check(int x)
{
for(int i = 0; i < n; ++i)
w[i] = a[i];
LL cnt = 1;
for(int i = x; i < n; ++i)
w[0] += w[i];
for(int i = x - 1; i >= 0; --i)
{
LL z = w[i] - cnt;
if(z > 0) w[0] += z;
if(z < 0) cnt += -z;
// if(i == x - 20) cerr << "cnt : " << cnt << '\n';
}
// cerr << "cnt : " << cnt << '\n';
return w[0] >= cnt;
}
int main()
{
read(n);
LL sum = 0;
for(int i = 0; i < n; ++i)
read(a[i]), sum += a[i];
if(sum == 1) for(int i = 0; i < n; ++i)
if(a[i] == 1) return printf("%d\n", i + (i == 0)), 0;
int l = 1, r = n + 30, res = 0;
while(l <= r)
{
int mid = (l + r) / 2;
if(check(mid))
res = mid, l = mid + 1;
else r = mid - 1;
}
printf("%d\n", res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5904kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
2 0 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5908kb
input:
6 1 0 0 0 0 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 5964kb
input:
5 0 0 0 0 1
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
5 1 0 1 0 1
output:
3
result:
ok single line: '3'
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 6196kb
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:
37738
result:
wrong answer 1st lines differ - expected: '37735', found: '37738'