# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
388176 | BartolM | Group Photo (JOI21_ho_t3) | C++17 | 860 ms | 524 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=5005;
struct Fenwick{
int F[N];
Fenwick() {
memset(F, 0, sizeof F);
}
int query(int x) {
int ret=0;
for (x++; x>0; x-=x&-x) ret+=F[x];
return ret;
}
void update(int x, int val) {
for (x++; x<N; x+=x&-x) F[x]+=val;
}
void reset() {
memset(F, 0, sizeof F);
}
};
int n;
int p[N], pos[N];
int dp[N];
Fenwick F1, F2;
void solve() {
dp[n+1]=0;
for (int i=n; i>0; --i) {
dp[i]=INF;
F1.reset(); F2.reset();
for (int j=i; j<=n; ++j) F1.update(pos[j], 1);
int dod=0;
for (int j=i; j<=n; ++j) {
dod+=F1.query(pos[j]-1)-(F2.query(n)-F2.query(pos[j]));
dp[i]=min(dp[i], dp[j+1]+dod);
F2.update(pos[j], 1);
}
}
printf("%d\n", dp[1]);
}
void load() {
scanf("%d", &n);
for (int i=1; i<=n; ++i) {
scanf("%d", &p[i]);
pos[p[i]]=i;
}
}
int main() {
load();
solve();
return 0;
}
컴파일 시 표준 에러 (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... |