QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#515625#5507. Investorsporridge_dustWA 31ms434424kbC++141.2kb2024-08-11 19:42:132024-08-11 19:42:13

Judging History

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

  • [2024-08-11 19:42:13]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:434424kb
  • [2024-08-11 19:42:13]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 6e3 + 100;

int T, n, k;
int a[N], sum[N][N], val[N][N];
int f[N][N];

void init () {
	for (int i = 0; i <= n; i ++ ) 
		for (int j = 0; j <= n; j ++ ) 
			sum[i][j] = 0, val[i][j] = 0, f[i][j] = 0x3f3f3f3f;
	f[0][0] = 0;
}

void solve (int l, int r, int jl, int jr, int j) {
	int mid = l + r >> 1, jc = jl;
	for (int i = jl; i <= min(mid - 1, jr); i ++ ) if (f[i][j - 1] + sum[i + 1][mid] < f[jc][j - 1] + sum[jc + 1][mid]) jc = i;
	f[mid][j] = f[jc][j - 1] + sum[jc + 1][mid];
	if (l < mid) solve(l, mid - 1, jl, jc, j);
	if (mid < r) solve(mid + 1, r, jc, jr, j);
}

int main () {
	cin >> T;
	n = 6e3; init(); 
	while (T -- ) {
		cin >> n >> k;
		for (int i = 1; i <= n; i ++ ) cin >> a[i];
		for (int i = 1; i <= n; i ++ ) 
			for (int j = i - 1; j >= 1; j -- ) 
				val[j][i] = val[j + 1][i] + (a[i] < a[j]);
		for (int i = 1; i < n; i ++ ) 
			for (int j = i + 1; j <= n; j ++ ) 
				sum[i][j] = sum[i][j - 1] + val[i][j];
		
		for (int i = 1; i <= k + 1; i ++ ) solve(1, n, 0, n, i);
		cout << f[n][k + 1] << '\n';
		init();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 31ms
memory: 434424kb

input:

2
6 1
4 5 6 2 2 1
6 2
4 5 6 2 2 1

output:

2
0

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 23ms
memory: 433540kb

input:

349
6 2
2 1 2 1 2 1
48 12
42 47 39 39 27 25 22 44 45 13 5 48 38 4 37 6 24 10 42 38 12 37 31 19 44 6 29 17 7 12 7 26 35 24 15 9 37 3 27 21 33 29 34 20 14 30 31 21
48 12
1 43 17 46 17 39 40 22 25 2 22 12 4 11 38 12 4 11 1 5 39 44 37 10 19 20 42 45 2 45 37 20 48 34 16 41 23 18 13 44 47 21 29 4 23 18 16...

output:

1
18
15
145
0
2
1
0
13
13
23
0
0
0
1
0
0
0
0
0
0
0
0
161
3
0
0
1
0
1061109567
0
0
0
0
1
1061109567
3
0
0
1
0
0
1
0
0
1
4
0
0
0
0
0
0
0
0
2
0
2
0
1061109567
8
280
0
0
34
4
0
1
0
0
3
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
0
0
2
0
0
0
0
0
0
0
8
1
8
0
0
0
0
1
11
5
0
0
0
6
0
1061109567
0
0
0
1
0
0...

result:

wrong answer 30th lines differ - expected: '0', found: '1061109567'