Submission #617621

# Submission time Handle Problem Language Result Execution time Memory
617621 2022-08-01T12:29:11 Z drdilyor Diversity (CEOI21_diversity) C++17
64 / 100
63 ms 12476 KB
#include <bits/stdc++.h>
#ifdef ONPC
#define cerr cout
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 3e5, LOGN = 17, MOD = 1e9+7;

ll brute(vector<int> arr) {
    int n = sz(arr);
    ll res = INFL;
    do {
        ll cur = 0;
        for (int i = 0; i < n; i++) {
            set<int> values;
            for (int j = i; j < n; j++) {
                values.insert(arr[j]);
                cur += sz(values);
            }
        }
        if (cur < res) {
            res = cur;
            debug(cur, arr);
        }
    } while (next_permutation(arr.begin(), arr.end()));
    return res;
}
int solve() {
    int n, q;
    if (!(cin >> n >> q)) {
        return 1;
    }
    vector<int> arr(n);
    for (auto& i : arr) {cin >> i;}

    vector<int> count(N+1);
    for (int i : arr) count[i]++;

    vector<pair<int,int>> bycount;
    for (int i = 0; i <= N; i++) {
        if (count[i]) bycount.emplace_back(count[i], i);
    }
    sort(bycount.begin(), bycount.end());

    vector<int> brr;
    for (int i = 0; i < sz(bycount); i += 2) {
        brr.push_back(bycount[i].first);
    }
    for (int i = sz(bycount) - 1 - sz(bycount)%2; i >= 0; i-= 2){ 
        brr.push_back(bycount[i].first);
    }
    debug(brr);

    n = sz(brr);
    ll res = 0;
    vector<ll> sum(n+1);
    for (int i = n-1; i >= 1; i--) {
        sum[i-1] = sum[i] + brr[i];
    }

    vector<ll> multed(n);
    for (int i = 0; i < n; i++) {
        multed[i] = (i+1) * brr[i];
    }
    for (int i = n-1; i > 0; i--) {
        multed[i-1] += multed[i];
    }
    debug(brr, sum, multed);

    // 2x + 3y + 4z = x+y+z + 1x + 2y + 3z

    for (int i = 0; i < n;i++) {
        if (i < n-1)
            res += brr[i] * (multed[i+1] - sum[i] * i);
        res += (ll)brr[i] * (brr[i] + 1) / 2;
    }
    cout << res << '\n';
    
    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    #ifdef ONPC
    t = 10000;
    #endif
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}

/*
     █████               █████  ███  ████                               
    ▒▒███               ▒▒███  ▒▒▒  ▒▒███                               
  ███████  ████████   ███████  ████  ▒███  █████ ████  ██████  ████████ 
 ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███  ▒███ ▒▒███ ▒███  ███▒▒███▒▒███▒▒███
▒███ ▒███  ▒███ ▒▒▒ ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ 
▒███ ▒███  ▒███     ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███     
▒▒████████ █████    ▒▒████████ █████ █████ ▒▒███████ ▒▒██████  █████    
 ▒▒▒▒▒▒▒▒ ▒▒▒▒▒      ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒███  ▒▒▒▒▒▒  ▒▒▒▒▒     
                                            ███ ▒███                    
                                           ▒▒██████                     
                                            ▒▒▒▒▒▒
*/

Compilation message

diversity.cpp: In function 'll brute(std::vector<int>)':
diversity.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 |     #define debug(...) 42
      |                        ^~
diversity.cpp:32:13: note: in expansion of macro 'debug'
   32 |             debug(cur, arr);
      |             ^~~~~
diversity.cpp: In function 'int solve()':
diversity.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 |     #define debug(...) 42
      |                        ^~
diversity.cpp:61:5: note: in expansion of macro 'debug'
   61 |     debug(brr);
      |     ^~~~~
diversity.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 |     #define debug(...) 42
      |                        ^~
diversity.cpp:77:5: note: in expansion of macro 'debug'
   77 |     debug(brr, sum, multed);
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1480 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 2 ms 1472 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1476 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 6 ms 2076 KB Output is correct
5 Correct 11 ms 2644 KB Output is correct
6 Correct 24 ms 3328 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 16 ms 3284 KB Output is correct
9 Correct 16 ms 3284 KB Output is correct
10 Correct 18 ms 3272 KB Output is correct
11 Correct 17 ms 3288 KB Output is correct
12 Correct 16 ms 3332 KB Output is correct
13 Correct 16 ms 3288 KB Output is correct
14 Correct 16 ms 3284 KB Output is correct
15 Correct 17 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 6 ms 2076 KB Output is correct
5 Correct 11 ms 2644 KB Output is correct
6 Correct 24 ms 3328 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 16 ms 3284 KB Output is correct
9 Correct 16 ms 3284 KB Output is correct
10 Correct 18 ms 3272 KB Output is correct
11 Correct 17 ms 3288 KB Output is correct
12 Correct 16 ms 3332 KB Output is correct
13 Correct 16 ms 3288 KB Output is correct
14 Correct 16 ms 3284 KB Output is correct
15 Correct 17 ms 3284 KB Output is correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 3 ms 1492 KB Output is correct
19 Correct 7 ms 2132 KB Output is correct
20 Correct 12 ms 2800 KB Output is correct
21 Correct 17 ms 3376 KB Output is correct
22 Correct 18 ms 3408 KB Output is correct
23 Correct 20 ms 3412 KB Output is correct
24 Correct 18 ms 3388 KB Output is correct
25 Correct 19 ms 3420 KB Output is correct
26 Correct 17 ms 3420 KB Output is correct
27 Correct 17 ms 3408 KB Output is correct
28 Correct 17 ms 3284 KB Output is correct
29 Correct 22 ms 3400 KB Output is correct
30 Correct 17 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 6 ms 2076 KB Output is correct
5 Correct 11 ms 2644 KB Output is correct
6 Correct 24 ms 3328 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 16 ms 3284 KB Output is correct
9 Correct 16 ms 3284 KB Output is correct
10 Correct 18 ms 3272 KB Output is correct
11 Correct 17 ms 3288 KB Output is correct
12 Correct 16 ms 3332 KB Output is correct
13 Correct 16 ms 3288 KB Output is correct
14 Correct 16 ms 3284 KB Output is correct
15 Correct 17 ms 3284 KB Output is correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 3 ms 1492 KB Output is correct
19 Correct 7 ms 2132 KB Output is correct
20 Correct 12 ms 2800 KB Output is correct
21 Correct 17 ms 3376 KB Output is correct
22 Correct 18 ms 3408 KB Output is correct
23 Correct 20 ms 3412 KB Output is correct
24 Correct 18 ms 3388 KB Output is correct
25 Correct 19 ms 3420 KB Output is correct
26 Correct 17 ms 3420 KB Output is correct
27 Correct 17 ms 3408 KB Output is correct
28 Correct 17 ms 3284 KB Output is correct
29 Correct 22 ms 3400 KB Output is correct
30 Correct 17 ms 3412 KB Output is correct
31 Correct 1 ms 1472 KB Output is correct
32 Correct 1 ms 1492 KB Output is correct
33 Correct 1 ms 1476 KB Output is correct
34 Correct 2 ms 1492 KB Output is correct
35 Correct 2 ms 1492 KB Output is correct
36 Correct 2 ms 1620 KB Output is correct
37 Correct 4 ms 1876 KB Output is correct
38 Correct 5 ms 1876 KB Output is correct
39 Correct 7 ms 2260 KB Output is correct
40 Correct 14 ms 3040 KB Output is correct
41 Correct 26 ms 3784 KB Output is correct
42 Correct 19 ms 3784 KB Output is correct
43 Correct 23 ms 3816 KB Output is correct
44 Correct 19 ms 3816 KB Output is correct
45 Correct 19 ms 3792 KB Output is correct
46 Correct 19 ms 3796 KB Output is correct
47 Correct 19 ms 3804 KB Output is correct
48 Correct 19 ms 3820 KB Output is correct
49 Correct 27 ms 3792 KB Output is correct
50 Correct 22 ms 3796 KB Output is correct
51 Correct 25 ms 3800 KB Output is correct
52 Correct 19 ms 3800 KB Output is correct
53 Correct 19 ms 3788 KB Output is correct
54 Correct 19 ms 3796 KB Output is correct
55 Correct 20 ms 3784 KB Output is correct
56 Correct 23 ms 3800 KB Output is correct
57 Correct 21 ms 3804 KB Output is correct
58 Correct 22 ms 3796 KB Output is correct
59 Correct 20 ms 3800 KB Output is correct
60 Correct 24 ms 3792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1480 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 2 ms 1472 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1476 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 2 ms 1492 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 6 ms 2076 KB Output is correct
15 Correct 11 ms 2644 KB Output is correct
16 Correct 24 ms 3328 KB Output is correct
17 Correct 16 ms 3284 KB Output is correct
18 Correct 16 ms 3284 KB Output is correct
19 Correct 16 ms 3284 KB Output is correct
20 Correct 18 ms 3272 KB Output is correct
21 Correct 17 ms 3288 KB Output is correct
22 Correct 16 ms 3332 KB Output is correct
23 Correct 16 ms 3288 KB Output is correct
24 Correct 16 ms 3284 KB Output is correct
25 Correct 17 ms 3284 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 3 ms 1492 KB Output is correct
29 Correct 7 ms 2132 KB Output is correct
30 Correct 12 ms 2800 KB Output is correct
31 Correct 17 ms 3376 KB Output is correct
32 Correct 18 ms 3408 KB Output is correct
33 Correct 20 ms 3412 KB Output is correct
34 Correct 18 ms 3388 KB Output is correct
35 Correct 19 ms 3420 KB Output is correct
36 Correct 17 ms 3420 KB Output is correct
37 Correct 17 ms 3408 KB Output is correct
38 Correct 17 ms 3284 KB Output is correct
39 Correct 22 ms 3400 KB Output is correct
40 Correct 17 ms 3412 KB Output is correct
41 Correct 1 ms 1472 KB Output is correct
42 Correct 1 ms 1492 KB Output is correct
43 Correct 1 ms 1476 KB Output is correct
44 Correct 2 ms 1492 KB Output is correct
45 Correct 2 ms 1492 KB Output is correct
46 Correct 2 ms 1620 KB Output is correct
47 Correct 4 ms 1876 KB Output is correct
48 Correct 5 ms 1876 KB Output is correct
49 Correct 7 ms 2260 KB Output is correct
50 Correct 14 ms 3040 KB Output is correct
51 Correct 26 ms 3784 KB Output is correct
52 Correct 19 ms 3784 KB Output is correct
53 Correct 23 ms 3816 KB Output is correct
54 Correct 19 ms 3816 KB Output is correct
55 Correct 19 ms 3792 KB Output is correct
56 Correct 19 ms 3796 KB Output is correct
57 Correct 19 ms 3804 KB Output is correct
58 Correct 19 ms 3820 KB Output is correct
59 Correct 27 ms 3792 KB Output is correct
60 Correct 22 ms 3796 KB Output is correct
61 Correct 25 ms 3800 KB Output is correct
62 Correct 19 ms 3800 KB Output is correct
63 Correct 19 ms 3788 KB Output is correct
64 Correct 19 ms 3796 KB Output is correct
65 Correct 20 ms 3784 KB Output is correct
66 Correct 23 ms 3800 KB Output is correct
67 Correct 21 ms 3804 KB Output is correct
68 Correct 22 ms 3796 KB Output is correct
69 Correct 20 ms 3800 KB Output is correct
70 Correct 24 ms 3792 KB Output is correct
71 Correct 5 ms 1908 KB Output is correct
72 Correct 5 ms 1876 KB Output is correct
73 Correct 8 ms 1876 KB Output is correct
74 Correct 5 ms 1876 KB Output is correct
75 Correct 5 ms 1876 KB Output is correct
76 Correct 10 ms 2512 KB Output is correct
77 Correct 10 ms 2448 KB Output is correct
78 Correct 10 ms 2512 KB Output is correct
79 Correct 10 ms 2508 KB Output is correct
80 Correct 8 ms 2476 KB Output is correct
81 Correct 16 ms 3512 KB Output is correct
82 Correct 26 ms 3532 KB Output is correct
83 Correct 17 ms 3540 KB Output is correct
84 Correct 16 ms 3536 KB Output is correct
85 Correct 15 ms 3532 KB Output is correct
86 Correct 19 ms 3968 KB Output is correct
87 Correct 19 ms 3960 KB Output is correct
88 Correct 18 ms 3920 KB Output is correct
89 Correct 18 ms 3968 KB Output is correct
90 Correct 19 ms 4032 KB Output is correct
91 Correct 41 ms 7620 KB Output is correct
92 Correct 33 ms 7624 KB Output is correct
93 Correct 33 ms 7620 KB Output is correct
94 Correct 32 ms 7616 KB Output is correct
95 Correct 35 ms 7624 KB Output is correct
96 Correct 50 ms 11016 KB Output is correct
97 Correct 62 ms 10936 KB Output is correct
98 Correct 48 ms 10952 KB Output is correct
99 Correct 48 ms 10996 KB Output is correct
100 Correct 48 ms 10952 KB Output is correct
101 Correct 54 ms 10948 KB Output is correct
102 Correct 47 ms 10996 KB Output is correct
103 Correct 47 ms 11000 KB Output is correct
104 Correct 44 ms 10948 KB Output is correct
105 Correct 63 ms 11004 KB Output is correct
106 Correct 47 ms 12444 KB Output is correct
107 Correct 46 ms 12448 KB Output is correct
108 Correct 46 ms 12468 KB Output is correct
109 Correct 50 ms 12364 KB Output is correct
110 Correct 44 ms 12448 KB Output is correct
111 Correct 54 ms 12352 KB Output is correct
112 Correct 61 ms 12456 KB Output is correct
113 Correct 51 ms 12356 KB Output is correct
114 Correct 51 ms 12476 KB Output is correct
115 Correct 53 ms 12384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1480 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 2 ms 1472 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1476 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 2 ms 1492 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 6 ms 2076 KB Output is correct
15 Correct 11 ms 2644 KB Output is correct
16 Correct 24 ms 3328 KB Output is correct
17 Correct 16 ms 3284 KB Output is correct
18 Correct 16 ms 3284 KB Output is correct
19 Correct 16 ms 3284 KB Output is correct
20 Correct 18 ms 3272 KB Output is correct
21 Correct 17 ms 3288 KB Output is correct
22 Correct 16 ms 3332 KB Output is correct
23 Correct 16 ms 3288 KB Output is correct
24 Correct 16 ms 3284 KB Output is correct
25 Correct 17 ms 3284 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 3 ms 1492 KB Output is correct
29 Correct 7 ms 2132 KB Output is correct
30 Correct 12 ms 2800 KB Output is correct
31 Correct 17 ms 3376 KB Output is correct
32 Correct 18 ms 3408 KB Output is correct
33 Correct 20 ms 3412 KB Output is correct
34 Correct 18 ms 3388 KB Output is correct
35 Correct 19 ms 3420 KB Output is correct
36 Correct 17 ms 3420 KB Output is correct
37 Correct 17 ms 3408 KB Output is correct
38 Correct 17 ms 3284 KB Output is correct
39 Correct 22 ms 3400 KB Output is correct
40 Correct 17 ms 3412 KB Output is correct
41 Correct 1 ms 1472 KB Output is correct
42 Correct 1 ms 1492 KB Output is correct
43 Correct 1 ms 1476 KB Output is correct
44 Correct 2 ms 1492 KB Output is correct
45 Correct 2 ms 1492 KB Output is correct
46 Correct 2 ms 1620 KB Output is correct
47 Correct 4 ms 1876 KB Output is correct
48 Correct 5 ms 1876 KB Output is correct
49 Correct 7 ms 2260 KB Output is correct
50 Correct 14 ms 3040 KB Output is correct
51 Correct 26 ms 3784 KB Output is correct
52 Correct 19 ms 3784 KB Output is correct
53 Correct 23 ms 3816 KB Output is correct
54 Correct 19 ms 3816 KB Output is correct
55 Correct 19 ms 3792 KB Output is correct
56 Correct 19 ms 3796 KB Output is correct
57 Correct 19 ms 3804 KB Output is correct
58 Correct 19 ms 3820 KB Output is correct
59 Correct 27 ms 3792 KB Output is correct
60 Correct 22 ms 3796 KB Output is correct
61 Correct 25 ms 3800 KB Output is correct
62 Correct 19 ms 3800 KB Output is correct
63 Correct 19 ms 3788 KB Output is correct
64 Correct 19 ms 3796 KB Output is correct
65 Correct 20 ms 3784 KB Output is correct
66 Correct 23 ms 3800 KB Output is correct
67 Correct 21 ms 3804 KB Output is correct
68 Correct 22 ms 3796 KB Output is correct
69 Correct 20 ms 3800 KB Output is correct
70 Correct 24 ms 3792 KB Output is correct
71 Correct 5 ms 1908 KB Output is correct
72 Correct 5 ms 1876 KB Output is correct
73 Correct 8 ms 1876 KB Output is correct
74 Correct 5 ms 1876 KB Output is correct
75 Correct 5 ms 1876 KB Output is correct
76 Correct 10 ms 2512 KB Output is correct
77 Correct 10 ms 2448 KB Output is correct
78 Correct 10 ms 2512 KB Output is correct
79 Correct 10 ms 2508 KB Output is correct
80 Correct 8 ms 2476 KB Output is correct
81 Correct 16 ms 3512 KB Output is correct
82 Correct 26 ms 3532 KB Output is correct
83 Correct 17 ms 3540 KB Output is correct
84 Correct 16 ms 3536 KB Output is correct
85 Correct 15 ms 3532 KB Output is correct
86 Correct 19 ms 3968 KB Output is correct
87 Correct 19 ms 3960 KB Output is correct
88 Correct 18 ms 3920 KB Output is correct
89 Correct 18 ms 3968 KB Output is correct
90 Correct 19 ms 4032 KB Output is correct
91 Correct 41 ms 7620 KB Output is correct
92 Correct 33 ms 7624 KB Output is correct
93 Correct 33 ms 7620 KB Output is correct
94 Correct 32 ms 7616 KB Output is correct
95 Correct 35 ms 7624 KB Output is correct
96 Correct 50 ms 11016 KB Output is correct
97 Correct 62 ms 10936 KB Output is correct
98 Correct 48 ms 10952 KB Output is correct
99 Correct 48 ms 10996 KB Output is correct
100 Correct 48 ms 10952 KB Output is correct
101 Correct 54 ms 10948 KB Output is correct
102 Correct 47 ms 10996 KB Output is correct
103 Correct 47 ms 11000 KB Output is correct
104 Correct 44 ms 10948 KB Output is correct
105 Correct 63 ms 11004 KB Output is correct
106 Correct 47 ms 12444 KB Output is correct
107 Correct 46 ms 12448 KB Output is correct
108 Correct 46 ms 12468 KB Output is correct
109 Correct 50 ms 12364 KB Output is correct
110 Correct 44 ms 12448 KB Output is correct
111 Correct 54 ms 12352 KB Output is correct
112 Correct 61 ms 12456 KB Output is correct
113 Correct 51 ms 12356 KB Output is correct
114 Correct 51 ms 12476 KB Output is correct
115 Correct 53 ms 12384 KB Output is correct
116 Incorrect 3 ms 1620 KB Output isn't correct
117 Halted 0 ms 0 KB -