# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001803 | vjudge1 | Liteh and Newfiteh (INOI20_litehfiteh) | C++17 | 2037 ms | 1628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int lg[N], n, a[N];
int calc(int l, int r, int dec=0) {
if(lg[r-l+1] == 0)return -1;
if(l == r) {
if(a[l]-dec > 1)return -1;
return a[l]-dec;
}
int mn = 1e9;
for(int i = l;i<=r;i++) {
mn=min(mn, a[i]-dec);
}
mn = (mn>0);
int mid = (l+r)/2;
long long L = calc(l, mid, dec+mn);
long long R = calc(mid+1, r, dec+mn);
if(L == -1 or R==-1)return -1;
return L+R+mn;
}
int main () {
{
int cntlg=1;
for(int i = 1;i<N;i*=2) {
lg[i]=cntlg++;
}
}
cin >> n;
for(int i = 0;i<n;i++) {
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |