답안 #602968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602968 2022-07-23T13:32:59 Z cadmiumsky Diversity (CEOI21_diversity) C++14
64 / 100
102 ms 6492 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int nmax = 3e5 + 5;
int freq[nmax];

static ll solve(vector<int> val) {
  ll total = 0;
  for(auto x : val)
    total += (ll)x * (x + 1) / 2;
  ll sum = 0, int1 = 0; 
  for(auto x : val) {
    int1 += sum;
    total += (ll)x * (int1 + sum);
    sum += x;
  }
  return total;
}

int main() {
  int n, q;
  cin >> n >> q;
  for(int i = 0, x; i < n; i++) {
    cin >> x;
    freq[x]++;
  }
  vector<int> val;
  for(auto x : freq)  
    if(x != 0)
      val.push_back(x);
  sort(val.begin(), val.end());
  vector<int> l, r;
  for(int i = 0; i < val.size(); i++)
    (i % 2? r : l).push_back(val[i]);
  reverse(r.begin(), r.end());
  copy(r.begin(), r.end(), back_inserter(l));
  val = move(l);
  ll cst = solve(val);
  //for(int i = 1; i < n; i++) {
    //reverse(val.end() - i, val.end());
    //cst = min(cst, solve(val));
    //reverse(val.end() - i, val.end());
  //}
  cout << cst << '\n';
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0; i < val.size(); i++)
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 17 ms 444 KB Output is correct
5 Correct 31 ms 660 KB Output is correct
6 Correct 51 ms 908 KB Output is correct
7 Correct 40 ms 788 KB Output is correct
8 Correct 43 ms 904 KB Output is correct
9 Correct 44 ms 788 KB Output is correct
10 Correct 53 ms 924 KB Output is correct
11 Correct 58 ms 844 KB Output is correct
12 Correct 46 ms 948 KB Output is correct
13 Correct 44 ms 844 KB Output is correct
14 Correct 57 ms 916 KB Output is correct
15 Correct 49 ms 912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 17 ms 444 KB Output is correct
5 Correct 31 ms 660 KB Output is correct
6 Correct 51 ms 908 KB Output is correct
7 Correct 40 ms 788 KB Output is correct
8 Correct 43 ms 904 KB Output is correct
9 Correct 44 ms 788 KB Output is correct
10 Correct 53 ms 924 KB Output is correct
11 Correct 58 ms 844 KB Output is correct
12 Correct 46 ms 948 KB Output is correct
13 Correct 44 ms 844 KB Output is correct
14 Correct 57 ms 916 KB Output is correct
15 Correct 49 ms 912 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 4 ms 212 KB Output is correct
19 Correct 17 ms 548 KB Output is correct
20 Correct 36 ms 820 KB Output is correct
21 Correct 56 ms 1108 KB Output is correct
22 Correct 51 ms 964 KB Output is correct
23 Correct 59 ms 1040 KB Output is correct
24 Correct 62 ms 1032 KB Output is correct
25 Correct 62 ms 1032 KB Output is correct
26 Correct 59 ms 1036 KB Output is correct
27 Correct 58 ms 1036 KB Output is correct
28 Correct 47 ms 980 KB Output is correct
29 Correct 48 ms 1024 KB Output is correct
30 Correct 46 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 17 ms 444 KB Output is correct
5 Correct 31 ms 660 KB Output is correct
6 Correct 51 ms 908 KB Output is correct
7 Correct 40 ms 788 KB Output is correct
8 Correct 43 ms 904 KB Output is correct
9 Correct 44 ms 788 KB Output is correct
10 Correct 53 ms 924 KB Output is correct
11 Correct 58 ms 844 KB Output is correct
12 Correct 46 ms 948 KB Output is correct
13 Correct 44 ms 844 KB Output is correct
14 Correct 57 ms 916 KB Output is correct
15 Correct 49 ms 912 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 4 ms 212 KB Output is correct
19 Correct 17 ms 548 KB Output is correct
20 Correct 36 ms 820 KB Output is correct
21 Correct 56 ms 1108 KB Output is correct
22 Correct 51 ms 964 KB Output is correct
23 Correct 59 ms 1040 KB Output is correct
24 Correct 62 ms 1032 KB Output is correct
25 Correct 62 ms 1032 KB Output is correct
26 Correct 59 ms 1036 KB Output is correct
27 Correct 58 ms 1036 KB Output is correct
28 Correct 47 ms 980 KB Output is correct
29 Correct 48 ms 1024 KB Output is correct
30 Correct 46 ms 1044 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 424 KB Output is correct
37 Correct 15 ms 468 KB Output is correct
38 Correct 12 ms 468 KB Output is correct
39 Correct 20 ms 692 KB Output is correct
40 Correct 59 ms 972 KB Output is correct
41 Correct 58 ms 1420 KB Output is correct
42 Correct 61 ms 1424 KB Output is correct
43 Correct 62 ms 1432 KB Output is correct
44 Correct 63 ms 1356 KB Output is correct
45 Correct 62 ms 1420 KB Output is correct
46 Correct 97 ms 1432 KB Output is correct
47 Correct 63 ms 1432 KB Output is correct
48 Correct 69 ms 1432 KB Output is correct
49 Correct 67 ms 1488 KB Output is correct
50 Correct 60 ms 1424 KB Output is correct
51 Correct 59 ms 1428 KB Output is correct
52 Correct 63 ms 1336 KB Output is correct
53 Correct 68 ms 1420 KB Output is correct
54 Correct 77 ms 1356 KB Output is correct
55 Correct 83 ms 1420 KB Output is correct
56 Correct 63 ms 1432 KB Output is correct
57 Correct 61 ms 1420 KB Output is correct
58 Correct 59 ms 1428 KB Output is correct
59 Correct 75 ms 1436 KB Output is correct
60 Correct 76 ms 1424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 17 ms 444 KB Output is correct
15 Correct 31 ms 660 KB Output is correct
16 Correct 51 ms 908 KB Output is correct
17 Correct 40 ms 788 KB Output is correct
18 Correct 43 ms 904 KB Output is correct
19 Correct 44 ms 788 KB Output is correct
20 Correct 53 ms 924 KB Output is correct
21 Correct 58 ms 844 KB Output is correct
22 Correct 46 ms 948 KB Output is correct
23 Correct 44 ms 844 KB Output is correct
24 Correct 57 ms 916 KB Output is correct
25 Correct 49 ms 912 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 4 ms 212 KB Output is correct
29 Correct 17 ms 548 KB Output is correct
30 Correct 36 ms 820 KB Output is correct
31 Correct 56 ms 1108 KB Output is correct
32 Correct 51 ms 964 KB Output is correct
33 Correct 59 ms 1040 KB Output is correct
34 Correct 62 ms 1032 KB Output is correct
35 Correct 62 ms 1032 KB Output is correct
36 Correct 59 ms 1036 KB Output is correct
37 Correct 58 ms 1036 KB Output is correct
38 Correct 47 ms 980 KB Output is correct
39 Correct 48 ms 1024 KB Output is correct
40 Correct 46 ms 1044 KB Output is correct
41 Correct 2 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 336 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 4 ms 424 KB Output is correct
47 Correct 15 ms 468 KB Output is correct
48 Correct 12 ms 468 KB Output is correct
49 Correct 20 ms 692 KB Output is correct
50 Correct 59 ms 972 KB Output is correct
51 Correct 58 ms 1420 KB Output is correct
52 Correct 61 ms 1424 KB Output is correct
53 Correct 62 ms 1432 KB Output is correct
54 Correct 63 ms 1356 KB Output is correct
55 Correct 62 ms 1420 KB Output is correct
56 Correct 97 ms 1432 KB Output is correct
57 Correct 63 ms 1432 KB Output is correct
58 Correct 69 ms 1432 KB Output is correct
59 Correct 67 ms 1488 KB Output is correct
60 Correct 60 ms 1424 KB Output is correct
61 Correct 59 ms 1428 KB Output is correct
62 Correct 63 ms 1336 KB Output is correct
63 Correct 68 ms 1420 KB Output is correct
64 Correct 77 ms 1356 KB Output is correct
65 Correct 83 ms 1420 KB Output is correct
66 Correct 63 ms 1432 KB Output is correct
67 Correct 61 ms 1420 KB Output is correct
68 Correct 59 ms 1428 KB Output is correct
69 Correct 75 ms 1436 KB Output is correct
70 Correct 76 ms 1424 KB Output is correct
71 Correct 17 ms 524 KB Output is correct
72 Correct 16 ms 528 KB Output is correct
73 Correct 13 ms 448 KB Output is correct
74 Correct 13 ms 528 KB Output is correct
75 Correct 13 ms 444 KB Output is correct
76 Correct 28 ms 812 KB Output is correct
77 Correct 33 ms 772 KB Output is correct
78 Correct 29 ms 768 KB Output is correct
79 Correct 33 ms 812 KB Output is correct
80 Correct 24 ms 784 KB Output is correct
81 Correct 46 ms 1388 KB Output is correct
82 Correct 45 ms 1404 KB Output is correct
83 Correct 45 ms 1408 KB Output is correct
84 Correct 61 ms 1456 KB Output is correct
85 Correct 48 ms 1472 KB Output is correct
86 Correct 53 ms 1756 KB Output is correct
87 Correct 49 ms 1740 KB Output is correct
88 Correct 51 ms 1764 KB Output is correct
89 Correct 48 ms 1680 KB Output is correct
90 Correct 49 ms 1760 KB Output is correct
91 Correct 79 ms 3984 KB Output is correct
92 Correct 82 ms 3976 KB Output is correct
93 Correct 87 ms 3988 KB Output is correct
94 Correct 81 ms 3992 KB Output is correct
95 Correct 95 ms 3976 KB Output is correct
96 Correct 84 ms 5900 KB Output is correct
97 Correct 101 ms 5900 KB Output is correct
98 Correct 97 ms 5916 KB Output is correct
99 Correct 89 ms 5824 KB Output is correct
100 Correct 89 ms 5792 KB Output is correct
101 Correct 87 ms 5912 KB Output is correct
102 Correct 91 ms 5896 KB Output is correct
103 Correct 89 ms 5904 KB Output is correct
104 Correct 83 ms 5896 KB Output is correct
105 Correct 86 ms 5888 KB Output is correct
106 Correct 93 ms 6484 KB Output is correct
107 Correct 88 ms 6464 KB Output is correct
108 Correct 91 ms 6488 KB Output is correct
109 Correct 87 ms 6488 KB Output is correct
110 Correct 93 ms 6488 KB Output is correct
111 Correct 91 ms 6480 KB Output is correct
112 Correct 90 ms 6488 KB Output is correct
113 Correct 91 ms 6484 KB Output is correct
114 Correct 102 ms 6492 KB Output is correct
115 Correct 92 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 17 ms 444 KB Output is correct
15 Correct 31 ms 660 KB Output is correct
16 Correct 51 ms 908 KB Output is correct
17 Correct 40 ms 788 KB Output is correct
18 Correct 43 ms 904 KB Output is correct
19 Correct 44 ms 788 KB Output is correct
20 Correct 53 ms 924 KB Output is correct
21 Correct 58 ms 844 KB Output is correct
22 Correct 46 ms 948 KB Output is correct
23 Correct 44 ms 844 KB Output is correct
24 Correct 57 ms 916 KB Output is correct
25 Correct 49 ms 912 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 4 ms 212 KB Output is correct
29 Correct 17 ms 548 KB Output is correct
30 Correct 36 ms 820 KB Output is correct
31 Correct 56 ms 1108 KB Output is correct
32 Correct 51 ms 964 KB Output is correct
33 Correct 59 ms 1040 KB Output is correct
34 Correct 62 ms 1032 KB Output is correct
35 Correct 62 ms 1032 KB Output is correct
36 Correct 59 ms 1036 KB Output is correct
37 Correct 58 ms 1036 KB Output is correct
38 Correct 47 ms 980 KB Output is correct
39 Correct 48 ms 1024 KB Output is correct
40 Correct 46 ms 1044 KB Output is correct
41 Correct 2 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 336 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 4 ms 424 KB Output is correct
47 Correct 15 ms 468 KB Output is correct
48 Correct 12 ms 468 KB Output is correct
49 Correct 20 ms 692 KB Output is correct
50 Correct 59 ms 972 KB Output is correct
51 Correct 58 ms 1420 KB Output is correct
52 Correct 61 ms 1424 KB Output is correct
53 Correct 62 ms 1432 KB Output is correct
54 Correct 63 ms 1356 KB Output is correct
55 Correct 62 ms 1420 KB Output is correct
56 Correct 97 ms 1432 KB Output is correct
57 Correct 63 ms 1432 KB Output is correct
58 Correct 69 ms 1432 KB Output is correct
59 Correct 67 ms 1488 KB Output is correct
60 Correct 60 ms 1424 KB Output is correct
61 Correct 59 ms 1428 KB Output is correct
62 Correct 63 ms 1336 KB Output is correct
63 Correct 68 ms 1420 KB Output is correct
64 Correct 77 ms 1356 KB Output is correct
65 Correct 83 ms 1420 KB Output is correct
66 Correct 63 ms 1432 KB Output is correct
67 Correct 61 ms 1420 KB Output is correct
68 Correct 59 ms 1428 KB Output is correct
69 Correct 75 ms 1436 KB Output is correct
70 Correct 76 ms 1424 KB Output is correct
71 Correct 17 ms 524 KB Output is correct
72 Correct 16 ms 528 KB Output is correct
73 Correct 13 ms 448 KB Output is correct
74 Correct 13 ms 528 KB Output is correct
75 Correct 13 ms 444 KB Output is correct
76 Correct 28 ms 812 KB Output is correct
77 Correct 33 ms 772 KB Output is correct
78 Correct 29 ms 768 KB Output is correct
79 Correct 33 ms 812 KB Output is correct
80 Correct 24 ms 784 KB Output is correct
81 Correct 46 ms 1388 KB Output is correct
82 Correct 45 ms 1404 KB Output is correct
83 Correct 45 ms 1408 KB Output is correct
84 Correct 61 ms 1456 KB Output is correct
85 Correct 48 ms 1472 KB Output is correct
86 Correct 53 ms 1756 KB Output is correct
87 Correct 49 ms 1740 KB Output is correct
88 Correct 51 ms 1764 KB Output is correct
89 Correct 48 ms 1680 KB Output is correct
90 Correct 49 ms 1760 KB Output is correct
91 Correct 79 ms 3984 KB Output is correct
92 Correct 82 ms 3976 KB Output is correct
93 Correct 87 ms 3988 KB Output is correct
94 Correct 81 ms 3992 KB Output is correct
95 Correct 95 ms 3976 KB Output is correct
96 Correct 84 ms 5900 KB Output is correct
97 Correct 101 ms 5900 KB Output is correct
98 Correct 97 ms 5916 KB Output is correct
99 Correct 89 ms 5824 KB Output is correct
100 Correct 89 ms 5792 KB Output is correct
101 Correct 87 ms 5912 KB Output is correct
102 Correct 91 ms 5896 KB Output is correct
103 Correct 89 ms 5904 KB Output is correct
104 Correct 83 ms 5896 KB Output is correct
105 Correct 86 ms 5888 KB Output is correct
106 Correct 93 ms 6484 KB Output is correct
107 Correct 88 ms 6464 KB Output is correct
108 Correct 91 ms 6488 KB Output is correct
109 Correct 87 ms 6488 KB Output is correct
110 Correct 93 ms 6488 KB Output is correct
111 Correct 91 ms 6480 KB Output is correct
112 Correct 90 ms 6488 KB Output is correct
113 Correct 91 ms 6484 KB Output is correct
114 Correct 102 ms 6492 KB Output is correct
115 Correct 92 ms 6484 KB Output is correct
116 Incorrect 3 ms 320 KB Output isn't correct
117 Halted 0 ms 0 KB -