QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666390 | #9313. Make Max | Saptak3315 | WA | 752ms | 17044kb | C++20 | 2.1kb | 2024-10-22 18:09:36 | 2024-10-22 18:09:36 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc=1,tc1=1;
cin>>tc;
up:
while(tc--){
ll n;
cin>>n;
vector<ll>a(n+5);
for(ll i=1;i<=n;i++){
cin>>a[i];
}
ll c=0,lst=a[1];
set<array<ll,3>>st;
for(ll i=1;i<=n;i++){
if(a[i]==lst){
c++;
}
else {
st.insert({lst,i-c,i-1});
c=1,lst=a[i];
}
}
st.insert({lst,n-c+1,n});
ll ans=0;
while(1){
if(st.size()==1){
break;
}
auto v=*st.begin();
st.erase(v);
ll val=v[0],sta=v[1],en=v[2],mn=1e18;
ans+=(v[2]-v[1]+1);
//cout<<val<<" "<<sta<<" "<<en<<' ';
if(sta!=1){
mn=a[sta-1];
}
if(en!=n){
mn=min(mn,a[en+1]);
}
a[sta]=mn,a[en]=mn;
if(a[sta-1]==a[en+1]){
ll fr=0,ba=n+1;
for(ll i=sta-2;i>=1;i--){
if(a[i]!=a[i+1]){
fr=i;
break;
}
}
for(ll i=en+2;i<=n;i++){
if(a[i]!=a[i-1]){
ba=i;
break;
}
}
st.erase({mn,fr+1,sta-1});
st.erase({mn,en+1,ba-1});
st.insert({mn,fr+1,ba-1});
//cout<<ans<<"\n";
continue;
}
if(mn==a[sta-1]){
ll lst=0;
for(ll i=sta-2;i>=1;i--){
if(a[i]!=a[i+1]){
lst=i;
break;
}
}
st.erase({mn,lst+1,sta-1});
st.insert({mn,lst+1,en});
}
else {
ll lst=n+1;
for(ll i=en+2;i<=n;i++){
if(a[i]!=a[i-1]){
lst=i;
break;
}
}
st.erase({mn,en+1,lst-1});
st.insert({mn,sta,lst-1});
}
//cout<<ans<<"\n";
}
cout<<ans<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3
result:
ok 4 number(s): "1 0 3 3"
Test #2:
score: -100
Wrong Answer
time: 752ms
memory: 17044kb
input:
2 198018 875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...
output:
47208837609 57223095753
result:
wrong answer 1st numbers differ - expected: '4084978', found: '47208837609'