QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340460 | #3306. Alchemy | Ishy | WA | 0ms | 5836kb | C++14 | 2.3kb | 2024-02-29 07:36:17 | 2024-02-29 07:36:18 |
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), 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: 0
Wrong Answer
time: 0ms
memory: 5836kb
input:
1 1
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'