QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140254 | #5500. Bars | PhantomThreshold# | WA | 190ms | 3704kb | C++20 | 824b | 2023-08-15 16:07:22 | 2023-08-15 16:07:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
vector<int> a(n+5),mk(n+5);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
vector<pair<int,int>> st;
for(int i=1;i<=n;i++)
{
while(st.size()>=2u and (st[st.size()-1].first-st[st.size()-2].first)*(a[i]-st[st.size()-1].second)-(st[st.size()-1].second-st[st.size()-2].second)*(i-st[st.size()-1].first)>=0)st.pop_back();
st.emplace_back(i,a[i]);
}
for(auto [i,x]:st)
{
mk[i]=1;
}
long long ans=0;
int last=0;
for(int i=1;i<=n;i++)
{
if(last)ans+=a[last];
if(mk[i])last=i;
}
last=n+1;
for(int i=n;i>=1;i--)
{
if(last!=n+1)ans+=a[last];
if(mk[i])last=i;
}
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
2 4 5 2 2 6 5 1 5 4 4 1
output:
33 29
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 190ms
memory: 3704kb
input:
10000 4 5 2 2 6 5 1 5 4 4 1 197 763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...
output:
33 29 184637807660 486604203610 338575311041 458946673513 296420749955 579550546230 430671642971 336463189483 225238173690 530830585076 327078524251 187526117716 585094154153 129061680368 336548832140 272416636667 280602730458 345754633893 307474973352 340358976830 489473288287 677653603843 26408806...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '184637807660'