QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135923 | #2299. Heating Up | mojospy | WA | 1ms | 3432kb | C++14 | 1.4kb | 2023-08-06 15:43:59 | 2023-08-06 15:44:03 |
Judging History
answer
#include<iostream>
#include<functional>
#include<queue>
#include<unordered_set>
using namespace std;
const int N=5e5+3;
typedef long long int ll;
ll a[N];
int n;
class cmp{
public:
bool operator()(const int i,const int j)const{
return a[i]>a[j];
}
};
int deal(int id){
if(id==n) return 0;
else if(id<0) return n-1;
else return id;
}
bool isvaild(ll num){
for(int i=0;i<n;++i){
if(num>=a[i]){
priority_queue<int,vector<int>,cmp> q;
unordered_set<int> s;
s.insert(i);
//s.insert(deal(i+1));
//s.insert(deal(i-1));
s.insert(deal(i+1));
s.insert(deal(i-1));
q.push(deal(i+1));
q.push(deal(i-1));
num+=a[i];
bool flag=true;
while(!q.empty()){
if(num<a[q.top()]){
flag=false;
break;
}
int cur=q.top();
q.pop();
num+=a[cur];
s.insert(cur);
if(s.find(deal(cur+1))==s.end()){
s.insert(deal(cur+1));
q.push(deal(cur+1));
}
if(s.find(deal(cur-1))==s.end()){
s.insert(deal(cur-1));
q.push(deal(cur-1));
}
}
//cout<<endl;
if(flag) return true;
}
}
return false;
}
int main(){
ll l=1e13+5,r=-1;
cin>>n;
for(int i=0;i<n;++i){
cin>>a[i];
l=min(l,a[i]);
r=max(r,a[i]);
}
if(a[0]=269655) cout<<isvaild(3)<<endl;
while(l<=r){
ll mid=(r+l)/2;
if(isvaild(mid)){
r=mid-1;
}else{
l=mid+1;
}
}
cout<<l;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3432kb
input:
4 10 20 15 1
output:
0 21
result:
wrong answer 1st lines differ - expected: '9', found: '0'