| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 388516 | luciocf | Group Photo (JOI21_ho_t3) | C++14 | 922 ms | 67552 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3+10;
const int inf = 1e9+10;
struct FenwickTree
{
int bit[maxn];
void upd(int x, int v)
{
for (; x < maxn; x += (x&-x))
bit[x] += v;
}
int soma(int x)
{
int ans = 0;
for (; x > 0; x -= (x&-x))
ans += bit[x];
return ans;
}
int get(int l, int r)
{
if (l > r) return 0;
return soma(r) - soma(l-1);
}
} BIT[2];
int a[maxn];
int val[maxn][maxn];
int dp[maxn];
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int x;
scanf("%d", &x);
a[x] = i;
}
for (int l = 1; l <= n; l++)
{
memset(BIT[0].bit, 0, sizeof BIT[0].bit);
memset(BIT[1].bit, 0, sizeof BIT[1].bit);
for (int i = l; i <= n; i++)
BIT[0].upd(a[i], 1);
for (int r = l; r <= n; r++)
{
val[l][r] = val[l][r-1];
val[l][r] -= BIT[1].get(a[r]+1, n);
val[l][r] += BIT[0].get(1, a[r]-1);
BIT[1].upd(a[r], 1);
}
}
for (int i = 1; i <= n; i++)
{
dp[i] = inf;
for (int j = 1; j <= i; j++)
dp[i] = min(dp[i], val[j][i] + dp[j-1]);
}
printf("%d\n", dp[n]);
}
컴파일 시 표준 에러 (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... | ||||
