QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#854745#9961. CowsZawosWA 0ms3804kbC++232.4kb2025-01-12 07:25:482025-01-12 07:25:48

Judging History

你现在查看的是最新测评结果

  • [2025-01-12 07:25:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2025-01-12 07:25:48]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vi=vector<int>;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
//上
const int inf = 1e9+10;
int f(int x,int l,int r){
    if( x < l) return x;
    if( l-1+2*(r-l+1) <= x){
        x -=(r-l+1);
        return x;
    }
    return (l-1)+(x-(l-1)+1)/2;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<ll> v(n);
    FOR(i,0,n) cin >> v[i];
    int l = 0;
    int r = 1e9;
    int ans = 1e9;
    while(l <= r){
        int mid =(l+r)/2;
        int req = 0;
        int lx = inf;
        int rx = inf;
        int ly = inf;
        int ry = inf;
        bool ok = true;
        for(int i = 0; i < n; i++){
            if(req == 0){
                int x = v[i];
                if(lx <= rx){
                    x = f(x,lx,rx);
                }
                if(ly <= ry){
                    x = f(x,ly,ry);
                }
                if(x <= mid){
                    req = 0;
                    lx = x+1;
                    rx = mid;
                    ly = inf;
                    ry = inf;
                }else{
                    req = 1;
                    int co = (x-mid);
                    if(mid>= co){
                        lx = mid-co+1;
                        rx = mid;
                    }else{
                        ok = false;
                        break;
                    }
                }
            }else{
                if(v[i] < lx){
                    req = 0;
                    ly = rx+1;
                    ry = mid;
                    rx = lx-1;
                    lx =v[i]+1;
                }else{
                    req = 1;
                    int diff = (rx-lx);
                    rx = lx-1;
                    lx = rx-diff;
                    if(lx <= 0){
                        ok = false;
                        break;
                    }
                }
            }
        }
        if(req) ok = false;
        if(ok){
            ans = mid;
            r = mid-1;
        }else l= mid +1;
    }
    cout <<ans <<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

8
6 0 5 5 6 3 0 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

6
7 6 5 2 6 8

output:

7

result:

ok 1 number(s): "7"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

10
5 9 3 4 3 2 5 8 2 3

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

10
1 18 3 15 0 14 20 15 14 12

output:

14

result:

ok 1 number(s): "14"

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

10
1 18 3 15 0 14 20 15 15 12

output:

14

result:

wrong answer 1st numbers differ - expected: '15', found: '14'