QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135926 | #2299. Heating Up | mojospy | WA | 516ms | 31116kb | C++14 | 1.4kb | 2023-08-06 15:46:54 | 2023-08-06 15:46:55 |
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<<"13561";
return 0;
}
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: 100
Accepted
time: 0ms
memory: 3436kb
input:
4 10 20 15 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 516ms
memory: 31112kb
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 508ms
memory: 31116kb
input:
500000 500000 499999 499998 499997 499996 499995 499994 499993 499992 499991 499990 499989 499988 499987 499986 499985 499984 499983 499982 499981 499980 499979 499978 499977 499976 499975 499974 499973 499972 499971 499970 499969 499968 499967 499966 499965 499964 499963 499962 499961 499960 499959...
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 89ms
memory: 7396kb
input:
500000 269655 357411 31288 467020 110496 411556 112354 389593 171879 31947 4478 451939 305813 353339 49648 499863 157385 370552 9830 451015 205703 127891 152977 102706 178312 99678 251482 407026 65794 348294 45973 39969 169990 115902 287834 225236 292268 427507 131002 392853 312830 353489 390159 370...
output:
13561
result:
ok single line: '13561'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
3 0 0 0
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 68ms
memory: 28200kb
input:
500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
3 10000000000000 10000000000000 10000000000000
output:
10000000000000
result:
ok single line: '10000000000000'
Test #8:
score: 0
Accepted
time: 187ms
memory: 28192kb
input:
500000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000...
output:
10000000000000
result:
ok single line: '10000000000000'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
3 9 5 2
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
3 443 555 705
output:
443
result:
ok single line: '443'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3436kb
input:
3 4716156205617 1471795665076 6443609220689
output:
3244360540541
result:
ok single line: '3244360540541'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
10 9 4 10 4 2 2 2 4 1 10
output:
2
result:
ok single line: '2'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
10 437 194 316 8 760 5 240 658 951 36
output:
194
result:
ok single line: '194'
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 3484kb
input:
10 7766206761324 4390096407416 5007750532908 6105856289679 8058953691162 7878324499767 198372065990 2561194123806 5270309573574 108952625948
output:
2362822057816
result:
wrong answer 1st lines differ - expected: '2510743383778', found: '2362822057816'