QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#169039 | #6626. Real Mountains | shuopihua | 0 | 0ms | 1700kb | C++14 | 1.2kb | 2023-09-09 11:16:03 | 2023-09-09 11:16:05 |
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 1000003
using namespace std;
int n;
int a[5005];
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;
}
int main(){
// freopen("repair.in","r",stdin);
// freopen("repair.out","w",stdout);
in(n);
for(int i=1;i<=n;i++) in(a[i]);
int 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=p1;i<=n;i++)
if(a[i]==mn) p2=i;
int x=min(a[p1-1],a[p2+1]);
(s+=((x-mn)*(a[p1-1]+a[p2+1])%mod+(mn+x-1)*(x-mn)/2%mod)%mod*(p2-p1+1)%mod)%=mod;
for(int i=p1;i<=p2;i++) a[i]=x;
}
printf("%d\n",s);
return 0;
}
/*
8
8 8 6 3 1 2 5 7
8 8 6 3 1 2 5 7
(3,1,2)
8 8 6 3 2 2 5 7
(3,2,5)*2
8 8 6 3 3 3 5 7
(6,3,5)*3
(6,4,5)*3
8 8 6 5 5 5 5 7
(6,5,7)*4
8 8 6 6 6 6 6 7
(8,6,7)*5
8 8 7 7 7 7 7 7
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 1700kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1624kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: -3
Wrong Answer
time: 0ms
memory: 1540kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
44479
result:
wrong answer 1st numbers differ - expected: '40403', found: '44479'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
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:
0%