| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1333306 | ricardsjansons | Group Photo (JOI21_ho_t3) | C++20 | 5091 ms | 836 KiB |
#include <bits/stdc++.h>
#define uset unordered
using namespace std;
const int N=5e3+5;
bitset<N>s[N];
int f(int l,int r){
int x=0;
for(int i=l;i<=r;i++){
for(int j=i+1;j<=r;j++){
if(s[i][j]){
x--;
}else{
x++;
}
}
}
return x;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
int a[n+1],dp[n+1]{};
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
for(int j=1;j<n;j++){
if(a[j+1]<a[j]){
swap(a[j],a[j+1]);
s[a[j]][a[j+1]]=1;
dp[0]++;
}
}
}
for(int i=1;i<=n;i++){
dp[i]=dp[i-1];
for(int j=0;j<i-1;j++){
dp[i]=min(dp[i],dp[j]+f(j+1,i));
}
}
cout<<dp[n];
}
| # | 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... | ||||
