QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171141 | #6626. Real Mountains | shuopihua | 3 | 2ms | 3620kb | C++14 | 2.0kb | 2023-09-09 16:31:54 | 2023-09-09 16:31:56 |
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 1000003
#define ll long long
using namespace std;
int n;
int a[1000005];
int b[1000005];
inline void in(int &n){
n=0;
char c=getchar();
while(c<'0' || c>'9') c=getchar();
while(c>='0'&&c<='9') n=n*10+c-'0',c=getchar();
return ;
}
inline bool check(){
int mx=0,ps=0;
for(int i=1;i<=n;i++)
if(mx<a[i]) mx=a[i],ps=i;
for(int i=ps;i>=1;i--)
if(a[i]<a[i-1]) return false;
for(int i=ps;i<n;i++)
if(a[i]<a[i+1]) return false;
return true;
}
inline void init(){
int l=1,r=n,mn=1e9;
for(int i=1;i<=n;i++) mn=min(mn,a[i]);
for(int i=2;i<=n;i++)
if(a[i]>=a[i-1]&&a[i]==mn) l=i;
else break;
for(int i=n-1;i>=1;i--)
if(a[i]>=a[i+1]&&a[i]==mn) r=i;
else break;
if(l>r){puts("0");exit(0);}
n=r-l+1;
for(int i=1;i<=n;i++) b[i]=a[i+l-1];
for(int i=1;i<=n;i++) a[i]=b[i];
return ;
}
int main(){
// freopen("repair.in","r",stdin);
// freopen("repair.out","w",stdout);
in(n);
for(int i=1;i<=n;i++) in(a[i]);
init();
ll s=0;
while(!check()){
int mn=1e9,p1=0,p2=0;
for(int i=1;i<=n;i++)
if(mn>a[i]) mn=a[i],p1=i;
for(int i=1;i<=n;i++)
if(a[i]==mn) p2=i;
ll s1=0,s2=0;
int m1=1e9,m2=1e9;
for(int i=1;i<p1;i++)
if(a[i]>mn) m1=min(m1,a[i]);
for(int i=p1+1;i<=n;i++)
if(a[i]>mn) m2=min(m2,a[i]);
if(p1==p2){
a[p1]++;
(s+=mn+m1+m2)%=mod;
continue;
}
s1=mn+m1+m2;
m1=mn+1,m2=1e9;
for(int i=p2+1;i<=n;i++)
if(a[i]>mn) m2=min(m2,a[i]);
s1+=mn+m1+m2;
m1=1e9,m2=1e9;
for(int i=1;i<p2;i++)
if(a[i]>mn) m1=min(m1,a[i]);
for(int i=p2+1;i<=n;i++)
if(a[i]>mn) m2=min(m2,a[i]);
s2+=mn+m1+m2;
m1=1e9,m2=mn+1;
for(int i=1;i<p1;i++)
if(a[i]>mn) m1=min(m1,a[i]);
s2+=mn+m1+m2;
(s+=min(s1,s2))%=mod;
int tt=0;
for(int i=1;i<=n;i++)
if(a[i]==mn) a[i]++,tt++;
tt-=2;
(s+=tt*(mn*3+2)%mod)%=mod;
}
printf("%lld\n",s);
return 0;
}
/*
10
72 33 22 22 13 49 53 57 72 85
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 1ms
memory: 3600kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40403
result:
ok 1 number(s): "40403"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...
output:
481053
result:
ok 1 number(s): "481053"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3300kb
input:
5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
5000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
12595
result:
ok 1 number(s): "12595"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
output:
299
result:
ok 1 number(s): "299"
Test #8:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
5000 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
224232
result:
ok 1 number(s): "224232"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4...
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3616kb
input:
5000 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4...
output:
499735
result:
ok 1 number(s): "499735"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
5000 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...
output:
461407
result:
ok 1 number(s): "461407"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 3560kb
input:
5000 37 39 93 78 85 71 59 21 57 96 61 59 23 16 57 90 13 59 85 70 62 67 78 97 16 60 8 48 28 53 4 24 1 97 97 98 57 87 96 91 74 54 100 76 86 86 46 39 100 57 70 76 73 55 84 93 64 6 84 39 75 94 30 15 3 31 11 34 27 10 6 81 30 76 60 9 4 47 1 88 17 71 61 30 19 10 4 57 79 37 22 74 84 8 91 58 15 45 7 98 32 46...
output:
166949
result:
wrong answer 1st numbers differ - expected: '216624', found: '166949'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%