답안 #388505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388505 2021-04-11T18:41:30 Z LucaDantas Group Photo (JOI21_ho_t3) C++17
100 / 100
481 ms 67408 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 5e3+10;

bool mark[maxn];

int a[maxn], val[maxn][maxn], dp[maxn];

int main() {
	int n; scanf("%d", &n);
	int inv = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		for(int j = a[i]+1; j <= n; j++) {
			inv += mark[j];
			val[a[i]][j] += mark[j];
		}
		for(int j = a[i]-1; j >= 1; j--)
			val[j][a[i]] -= mark[j];
		mark[a[i]] = 1;
	}
	for(int sz = 2; sz <= n; sz++) {
		for(int i = 1; i+sz <= n; i++) {
			int j = i + sz;
			val[i][j] += val[i][j-1] + val[i+1][j] - val[i+1][j-1];
		}
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= i; j++)
			dp[i] = max(dp[i], val[j][i] + dp[j-1]);
	printf("%d\n", inv - dp[n]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 1076 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 1076 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 1100 KB Output is correct
31 Correct 4 ms 4712 KB Output is correct
32 Correct 6 ms 4684 KB Output is correct
33 Correct 5 ms 4684 KB Output is correct
34 Correct 4 ms 4684 KB Output is correct
35 Correct 6 ms 4684 KB Output is correct
36 Correct 5 ms 4684 KB Output is correct
37 Correct 5 ms 4776 KB Output is correct
38 Correct 5 ms 4684 KB Output is correct
39 Correct 5 ms 4684 KB Output is correct
40 Correct 4 ms 4684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 1076 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 1100 KB Output is correct
31 Correct 4 ms 4712 KB Output is correct
32 Correct 6 ms 4684 KB Output is correct
33 Correct 5 ms 4684 KB Output is correct
34 Correct 4 ms 4684 KB Output is correct
35 Correct 6 ms 4684 KB Output is correct
36 Correct 5 ms 4684 KB Output is correct
37 Correct 5 ms 4776 KB Output is correct
38 Correct 5 ms 4684 KB Output is correct
39 Correct 5 ms 4684 KB Output is correct
40 Correct 4 ms 4684 KB Output is correct
41 Correct 481 ms 67248 KB Output is correct
42 Correct 461 ms 67308 KB Output is correct
43 Correct 473 ms 67304 KB Output is correct
44 Correct 446 ms 67280 KB Output is correct
45 Correct 441 ms 67292 KB Output is correct
46 Correct 442 ms 67336 KB Output is correct
47 Correct 439 ms 67316 KB Output is correct
48 Correct 466 ms 67268 KB Output is correct
49 Correct 435 ms 67264 KB Output is correct
50 Correct 452 ms 67336 KB Output is correct
51 Correct 434 ms 67268 KB Output is correct
52 Correct 459 ms 67312 KB Output is correct
53 Correct 467 ms 67404 KB Output is correct
54 Correct 457 ms 67336 KB Output is correct
55 Correct 445 ms 67408 KB Output is correct