# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
643343 | Augustyn | Group Photo (JOI21_ho_t3) | C++14 | 395 ms | 196676 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n,h[5001],gdzie[5001];
int dp[5011],ilewiek[5011][5011],ilemn[5011][5011];
int czynap(int a,int b)
{
if(gdzie[a]<gdzie[b])
return 1;
return 0;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&h[i]);
gdzie[h[i]]=i;
}
for(int i=1;i<=n;++i)
{
for(int j=n;j>i;--j)
ilewiek[i][j]=ilewiek[i][j+1]+czynap(j,i);
for(int j=i;j>0;--j)
ilemn[i][j]=ilemn[i][j+1]+czynap(j,i);
ilemn[i][0]+=ilemn[i][1];
for(int j=i;j>=0;--j)
ilewiek[i][j]+=ilewiek[i][j+1];
}
for(int i=n;i>=0;--i)
{
for(int j=n;j>=0;--j)
ilewiek[i][j]+=ilewiek[i+1][j];
for(int j=n;j>=0;--j)
ilemn[i][j]+=ilemn[i+1][j];
}
for(int i=1;i<=n;++i)
{
dp[i]=INT_MAX;
for(int j=1;j<=i;++j)
{
dp[i]=min(dp[i],dp[j-1]+ilewiek[j][i+1]-ilewiek[i+1][i+1]+ilemn[j][j]-ilemn[i+1][j]);
}
}
printf("%d",dp[n]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |