QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883675 | #9961. Cows | wdnmdwrnmmp | WA | 1ms | 3712kb | C++14 | 2.0kb | 2025-02-05 17:56:44 | 2025-02-05 17:56:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb emplace_back
#define fi first
#define se second
using vi=vector<int>;
using pi=pair<int,int>;
template<typename T> bool chmin(T &x,const T &y){
if(y<x){
x=y;
return true;
}
return false;
}
template<typename T> bool chmax(T &x,const T &y){
if(y>x){
x=y;
return true;
}
return false;
}
namespace Debug{
template<typename T> void _debug(char *s, T x){
cerr<< s <<" = "<< x <<endl;
}
template<typename T, typename ...Ar> void _debug(char *s, T x, Ar... y){
while(*s != ',') cerr<< *s++;
cerr<<" = "<< x <<",";
_debug(s+1, y...);
}
}
using namespace Debug;
#define gdb(...) _debug((char*)#__VA_ARGS__, __VA_ARGS__)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int n; cin>>n;
vi a(n+1);
rep(i,1,n){
cin>>a[i];
}
auto chk=[&](int t){
auto calc=[&](int x,pi rg){
if(x <= rg.fi){
return x;
}
if(x >= rg.se*2 - rg.fi){
return x-(rg.se-rg.fi);
}
return rg.fi + (x-rg.fi+1)/2;
};
tuple<bool, pi, pi> lst{0, {t, t}, {t, t}};
rep(i,1,n){
auto [op, rg0, rg1]=lst;
// gdb(t, i, op, rg0.fi, rg0.se, rg1.fi, rg1.se);
if(op==0){
int t0=calc(a[i], rg1);
int t1=calc(t0, rg0);
// gdb(i, t0, t1, t);
if(t1 <= t){
lst = {0, {t1, t}, {t, t}};
}
else{
if(t-(t1-t)<0){
return false;
}
lst = {1, {t-(t1-t), t}, {-1, -1}};
}
}
else{
if(a[i] <= rg0.fi){
lst = {0, {a[i], rg0.fi}, {rg0.se, t}};
}
else{
int t0 = rg0.fi-(a[i]-rg0.fi);
if(t0<0){
return false;
}
lst = {1, {t0, rg0.fi}, {-1, -1}};
}
}
}
return get<0>(lst) == 0;
};
int l=0, r=*max_element(a.begin(), a.end());
while(l<r){
int mid=(l+r)/2;
if(chk(mid)){
r=mid;
}
else{
l=mid+1;
}
}
cout<< l <<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
5 5 4 0 4 6
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 1 4 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
1 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
8 6 0 5 5 6 3 0 6
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3712kb
input:
6 7 6 5 2 6 8
output:
6
result:
wrong answer 1st numbers differ - expected: '7', found: '6'