QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385075#2177. Group PhotoRikku_eq0 1ms3960kbC++14986b2024-04-10 15:15:202024-04-10 15:15:20

Judging History

你现在查看的是最新测评结果

  • [2024-04-10 15:15:20]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3960kb
  • [2024-04-10 15:15:20]
  • 提交

answer

#include <bits/stdc++.h>
#define N 5005
using namespace std;
typedef long long ll;

int n, a[N], cnt[N][N], f[N], bit[N];

void add (int x) { while (x<=n) { bit[x]++; x+=(x&(-x)); } }
int qry (int x) { int res=0; while (x) { res+=bit[x]; x-=(x&(-x)); } return res; }

int cal (int l, int r)
{
    int len=r-l+1;
    return cnt[1][r]-cnt[1][l-1]-cnt[l][r]+(len*(len-1)/2)-cnt[l][r];
}

int main ()
{
    // freopen("0test.in", "r", stdin);
    // freopen("0test.out", "w", stdout);

    scanf("%d", &n);
    for (int i=1; i<=n; i++) { scanf("%d", &a[i]); }

    for (int l=1; l<=n; l++) {
        fill(bit+1, bit+n+1, 0);
        for (int r=l; r<=n; r++) {
            add(a[r]);
            cnt[l][r]=cnt[l][r-1]+r-l+1-qry(a[r]);
        }
    }
    
    for (int i=1; i<=n; i++) {
        f[i]=i*(i-1)/2;
        for (int j=i; j>=1; j--) {
            f[i]=min(f[i], f[j-1]+cal(j, i));
        }
    }
    printf("%d\n", f[n]);

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 3872kb

input:

3
3 1 2

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

4
4 1 2 3

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

5
1 4 5 2 3

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

6
1 5 6 3 4 2

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

7
1 7 4 5 2 6 3

output:

5

result:

ok single line: '5'

Test #6:

score: -5
Wrong Answer
time: 0ms
memory: 3960kb

input:

8
4 1 6 7 5 2 8 3

output:

6

result:

wrong answer 1st lines differ - expected: '7', found: '6'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%