답안 #659698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659698 2022-11-19T05:24:01 Z Sohsoh84 Diversity (CEOI21_diversity) C++17
38 / 100
7000 ms 11892 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;
const ll INF = 4e18;

int n, q, cnt[MAXN], A[MAXN];
ll dp[MAXN];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		int A[i];
		cin >> A[i];
		cnt[A[i]]++;
	}

	vector<int> vec = {0};
	for (int i = 0; i < MAXN; i++)
		if (cnt[i])
			vec.push_back(cnt[i]);

	int m = vec.size() - 1;
	sort(all(vec));

	fill(dp, dp + MAXN, INF);
	dp[0] = 0;
	ll s = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = s + vec[i]; j >= 0; j--) {
			ll ans = INF;
			if (j <= s) ans = min(ans, dp[j] + (s - j) * (n - s + j));	
			if (j >= vec[i]) ans = min(ans, dp[j - vec[i]] + 1ll * j * (n - j));
			
			dp[j] = ans;
		} 

		s += vec[i];
	}

	cout << *min_element(dp, dp + MAXN) + 1ll * n * (n + 1) / 2 << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8132 KB Output is correct
2 Correct 8 ms 8144 KB Output is correct
3 Correct 7 ms 8148 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 6 ms 8148 KB Output is correct
7 Correct 7 ms 8148 KB Output is correct
8 Correct 9 ms 8164 KB Output is correct
9 Correct 6 ms 8148 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8176 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8140 KB Output is correct
4 Correct 82 ms 8680 KB Output is correct
5 Correct 358 ms 9412 KB Output is correct
6 Correct 827 ms 9956 KB Output is correct
7 Correct 836 ms 9876 KB Output is correct
8 Correct 839 ms 10020 KB Output is correct
9 Correct 790 ms 9884 KB Output is correct
10 Correct 823 ms 10056 KB Output is correct
11 Correct 823 ms 9972 KB Output is correct
12 Correct 845 ms 9996 KB Output is correct
13 Correct 856 ms 9960 KB Output is correct
14 Correct 783 ms 9928 KB Output is correct
15 Correct 876 ms 9928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8176 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8140 KB Output is correct
4 Correct 82 ms 8680 KB Output is correct
5 Correct 358 ms 9412 KB Output is correct
6 Correct 827 ms 9956 KB Output is correct
7 Correct 836 ms 9876 KB Output is correct
8 Correct 839 ms 10020 KB Output is correct
9 Correct 790 ms 9884 KB Output is correct
10 Correct 823 ms 10056 KB Output is correct
11 Correct 823 ms 9972 KB Output is correct
12 Correct 845 ms 9996 KB Output is correct
13 Correct 856 ms 9960 KB Output is correct
14 Correct 783 ms 9928 KB Output is correct
15 Correct 876 ms 9928 KB Output is correct
16 Correct 6 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 6 ms 8176 KB Output is correct
19 Correct 89 ms 8696 KB Output is correct
20 Correct 362 ms 9388 KB Output is correct
21 Correct 828 ms 10104 KB Output is correct
22 Correct 857 ms 10092 KB Output is correct
23 Correct 868 ms 10060 KB Output is correct
24 Correct 801 ms 10072 KB Output is correct
25 Correct 822 ms 10068 KB Output is correct
26 Correct 810 ms 10164 KB Output is correct
27 Correct 775 ms 10064 KB Output is correct
28 Correct 871 ms 9988 KB Output is correct
29 Correct 834 ms 9984 KB Output is correct
30 Correct 840 ms 10100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8176 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8140 KB Output is correct
4 Correct 82 ms 8680 KB Output is correct
5 Correct 358 ms 9412 KB Output is correct
6 Correct 827 ms 9956 KB Output is correct
7 Correct 836 ms 9876 KB Output is correct
8 Correct 839 ms 10020 KB Output is correct
9 Correct 790 ms 9884 KB Output is correct
10 Correct 823 ms 10056 KB Output is correct
11 Correct 823 ms 9972 KB Output is correct
12 Correct 845 ms 9996 KB Output is correct
13 Correct 856 ms 9960 KB Output is correct
14 Correct 783 ms 9928 KB Output is correct
15 Correct 876 ms 9928 KB Output is correct
16 Correct 6 ms 8148 KB Output is correct
17 Correct 5 ms 8148 KB Output is correct
18 Correct 6 ms 8176 KB Output is correct
19 Correct 89 ms 8696 KB Output is correct
20 Correct 362 ms 9388 KB Output is correct
21 Correct 828 ms 10104 KB Output is correct
22 Correct 857 ms 10092 KB Output is correct
23 Correct 868 ms 10060 KB Output is correct
24 Correct 801 ms 10072 KB Output is correct
25 Correct 822 ms 10068 KB Output is correct
26 Correct 810 ms 10164 KB Output is correct
27 Correct 775 ms 10064 KB Output is correct
28 Correct 871 ms 9988 KB Output is correct
29 Correct 834 ms 9984 KB Output is correct
30 Correct 840 ms 10100 KB Output is correct
31 Correct 6 ms 8148 KB Output is correct
32 Correct 7 ms 8100 KB Output is correct
33 Correct 8 ms 8136 KB Output is correct
34 Correct 7 ms 8148 KB Output is correct
35 Correct 8 ms 8148 KB Output is correct
36 Correct 14 ms 8260 KB Output is correct
37 Correct 36 ms 8532 KB Output is correct
38 Correct 51 ms 8528 KB Output is correct
39 Correct 139 ms 8864 KB Output is correct
40 Correct 461 ms 9700 KB Output is correct
41 Correct 971 ms 10476 KB Output is correct
42 Correct 974 ms 10552 KB Output is correct
43 Correct 999 ms 10472 KB Output is correct
44 Correct 933 ms 10488 KB Output is correct
45 Correct 996 ms 10476 KB Output is correct
46 Correct 1016 ms 10604 KB Output is correct
47 Correct 971 ms 10480 KB Output is correct
48 Correct 995 ms 10444 KB Output is correct
49 Correct 976 ms 10548 KB Output is correct
50 Correct 983 ms 10532 KB Output is correct
51 Correct 990 ms 10468 KB Output is correct
52 Correct 971 ms 10476 KB Output is correct
53 Correct 974 ms 10472 KB Output is correct
54 Correct 940 ms 10636 KB Output is correct
55 Correct 1000 ms 10564 KB Output is correct
56 Correct 985 ms 10580 KB Output is correct
57 Correct 987 ms 10668 KB Output is correct
58 Correct 977 ms 10484 KB Output is correct
59 Correct 960 ms 10600 KB Output is correct
60 Correct 951 ms 10572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8132 KB Output is correct
2 Correct 8 ms 8144 KB Output is correct
3 Correct 7 ms 8148 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 6 ms 8148 KB Output is correct
7 Correct 7 ms 8148 KB Output is correct
8 Correct 9 ms 8164 KB Output is correct
9 Correct 6 ms 8148 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8176 KB Output is correct
12 Correct 8 ms 8148 KB Output is correct
13 Correct 8 ms 8140 KB Output is correct
14 Correct 82 ms 8680 KB Output is correct
15 Correct 358 ms 9412 KB Output is correct
16 Correct 827 ms 9956 KB Output is correct
17 Correct 836 ms 9876 KB Output is correct
18 Correct 839 ms 10020 KB Output is correct
19 Correct 790 ms 9884 KB Output is correct
20 Correct 823 ms 10056 KB Output is correct
21 Correct 823 ms 9972 KB Output is correct
22 Correct 845 ms 9996 KB Output is correct
23 Correct 856 ms 9960 KB Output is correct
24 Correct 783 ms 9928 KB Output is correct
25 Correct 876 ms 9928 KB Output is correct
26 Correct 6 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8176 KB Output is correct
29 Correct 89 ms 8696 KB Output is correct
30 Correct 362 ms 9388 KB Output is correct
31 Correct 828 ms 10104 KB Output is correct
32 Correct 857 ms 10092 KB Output is correct
33 Correct 868 ms 10060 KB Output is correct
34 Correct 801 ms 10072 KB Output is correct
35 Correct 822 ms 10068 KB Output is correct
36 Correct 810 ms 10164 KB Output is correct
37 Correct 775 ms 10064 KB Output is correct
38 Correct 871 ms 9988 KB Output is correct
39 Correct 834 ms 9984 KB Output is correct
40 Correct 840 ms 10100 KB Output is correct
41 Correct 6 ms 8148 KB Output is correct
42 Correct 7 ms 8100 KB Output is correct
43 Correct 8 ms 8136 KB Output is correct
44 Correct 7 ms 8148 KB Output is correct
45 Correct 8 ms 8148 KB Output is correct
46 Correct 14 ms 8260 KB Output is correct
47 Correct 36 ms 8532 KB Output is correct
48 Correct 51 ms 8528 KB Output is correct
49 Correct 139 ms 8864 KB Output is correct
50 Correct 461 ms 9700 KB Output is correct
51 Correct 971 ms 10476 KB Output is correct
52 Correct 974 ms 10552 KB Output is correct
53 Correct 999 ms 10472 KB Output is correct
54 Correct 933 ms 10488 KB Output is correct
55 Correct 996 ms 10476 KB Output is correct
56 Correct 1016 ms 10604 KB Output is correct
57 Correct 971 ms 10480 KB Output is correct
58 Correct 995 ms 10444 KB Output is correct
59 Correct 976 ms 10548 KB Output is correct
60 Correct 983 ms 10532 KB Output is correct
61 Correct 990 ms 10468 KB Output is correct
62 Correct 971 ms 10476 KB Output is correct
63 Correct 974 ms 10472 KB Output is correct
64 Correct 940 ms 10636 KB Output is correct
65 Correct 1000 ms 10564 KB Output is correct
66 Correct 985 ms 10580 KB Output is correct
67 Correct 987 ms 10668 KB Output is correct
68 Correct 977 ms 10484 KB Output is correct
69 Correct 960 ms 10600 KB Output is correct
70 Correct 951 ms 10572 KB Output is correct
71 Correct 84 ms 8584 KB Output is correct
72 Correct 77 ms 8580 KB Output is correct
73 Correct 79 ms 8544 KB Output is correct
74 Correct 77 ms 8660 KB Output is correct
75 Correct 82 ms 8652 KB Output is correct
76 Correct 357 ms 9084 KB Output is correct
77 Correct 366 ms 9080 KB Output is correct
78 Correct 352 ms 9068 KB Output is correct
79 Correct 378 ms 9072 KB Output is correct
80 Correct 360 ms 8996 KB Output is correct
81 Correct 1422 ms 10028 KB Output is correct
82 Correct 1438 ms 10064 KB Output is correct
83 Correct 1470 ms 10112 KB Output is correct
84 Correct 1458 ms 10060 KB Output is correct
85 Correct 1479 ms 10032 KB Output is correct
86 Correct 2646 ms 10316 KB Output is correct
87 Correct 2628 ms 10284 KB Output is correct
88 Correct 2601 ms 10284 KB Output is correct
89 Correct 2570 ms 10292 KB Output is correct
90 Correct 2584 ms 10380 KB Output is correct
91 Execution timed out 7032 ms 11892 KB Time limit exceeded
92 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8132 KB Output is correct
2 Correct 8 ms 8144 KB Output is correct
3 Correct 7 ms 8148 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 6 ms 8148 KB Output is correct
7 Correct 7 ms 8148 KB Output is correct
8 Correct 9 ms 8164 KB Output is correct
9 Correct 6 ms 8148 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8176 KB Output is correct
12 Correct 8 ms 8148 KB Output is correct
13 Correct 8 ms 8140 KB Output is correct
14 Correct 82 ms 8680 KB Output is correct
15 Correct 358 ms 9412 KB Output is correct
16 Correct 827 ms 9956 KB Output is correct
17 Correct 836 ms 9876 KB Output is correct
18 Correct 839 ms 10020 KB Output is correct
19 Correct 790 ms 9884 KB Output is correct
20 Correct 823 ms 10056 KB Output is correct
21 Correct 823 ms 9972 KB Output is correct
22 Correct 845 ms 9996 KB Output is correct
23 Correct 856 ms 9960 KB Output is correct
24 Correct 783 ms 9928 KB Output is correct
25 Correct 876 ms 9928 KB Output is correct
26 Correct 6 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8176 KB Output is correct
29 Correct 89 ms 8696 KB Output is correct
30 Correct 362 ms 9388 KB Output is correct
31 Correct 828 ms 10104 KB Output is correct
32 Correct 857 ms 10092 KB Output is correct
33 Correct 868 ms 10060 KB Output is correct
34 Correct 801 ms 10072 KB Output is correct
35 Correct 822 ms 10068 KB Output is correct
36 Correct 810 ms 10164 KB Output is correct
37 Correct 775 ms 10064 KB Output is correct
38 Correct 871 ms 9988 KB Output is correct
39 Correct 834 ms 9984 KB Output is correct
40 Correct 840 ms 10100 KB Output is correct
41 Correct 6 ms 8148 KB Output is correct
42 Correct 7 ms 8100 KB Output is correct
43 Correct 8 ms 8136 KB Output is correct
44 Correct 7 ms 8148 KB Output is correct
45 Correct 8 ms 8148 KB Output is correct
46 Correct 14 ms 8260 KB Output is correct
47 Correct 36 ms 8532 KB Output is correct
48 Correct 51 ms 8528 KB Output is correct
49 Correct 139 ms 8864 KB Output is correct
50 Correct 461 ms 9700 KB Output is correct
51 Correct 971 ms 10476 KB Output is correct
52 Correct 974 ms 10552 KB Output is correct
53 Correct 999 ms 10472 KB Output is correct
54 Correct 933 ms 10488 KB Output is correct
55 Correct 996 ms 10476 KB Output is correct
56 Correct 1016 ms 10604 KB Output is correct
57 Correct 971 ms 10480 KB Output is correct
58 Correct 995 ms 10444 KB Output is correct
59 Correct 976 ms 10548 KB Output is correct
60 Correct 983 ms 10532 KB Output is correct
61 Correct 990 ms 10468 KB Output is correct
62 Correct 971 ms 10476 KB Output is correct
63 Correct 974 ms 10472 KB Output is correct
64 Correct 940 ms 10636 KB Output is correct
65 Correct 1000 ms 10564 KB Output is correct
66 Correct 985 ms 10580 KB Output is correct
67 Correct 987 ms 10668 KB Output is correct
68 Correct 977 ms 10484 KB Output is correct
69 Correct 960 ms 10600 KB Output is correct
70 Correct 951 ms 10572 KB Output is correct
71 Correct 84 ms 8584 KB Output is correct
72 Correct 77 ms 8580 KB Output is correct
73 Correct 79 ms 8544 KB Output is correct
74 Correct 77 ms 8660 KB Output is correct
75 Correct 82 ms 8652 KB Output is correct
76 Correct 357 ms 9084 KB Output is correct
77 Correct 366 ms 9080 KB Output is correct
78 Correct 352 ms 9068 KB Output is correct
79 Correct 378 ms 9072 KB Output is correct
80 Correct 360 ms 8996 KB Output is correct
81 Correct 1422 ms 10028 KB Output is correct
82 Correct 1438 ms 10064 KB Output is correct
83 Correct 1470 ms 10112 KB Output is correct
84 Correct 1458 ms 10060 KB Output is correct
85 Correct 1479 ms 10032 KB Output is correct
86 Correct 2646 ms 10316 KB Output is correct
87 Correct 2628 ms 10284 KB Output is correct
88 Correct 2601 ms 10284 KB Output is correct
89 Correct 2570 ms 10292 KB Output is correct
90 Correct 2584 ms 10380 KB Output is correct
91 Execution timed out 7032 ms 11892 KB Time limit exceeded
92 Halted 0 ms 0 KB -