Submission #865768

# Submission time Handle Problem Language Result Execution time Memory
865768 2023-10-24T15:28:39 Z Rifal Diversity (CEOI21_diversity) C++14
4 / 100
7000 ms 4848 KB
#include <bits/stdc++.h>
#include <fstream>
//#define endl '\n'
#define mod 1000000007
#define INF 9000000000000000
using namespace std;
//ofstream fout("intel.out");
//ifstream fin("intel.in");
const int Max = 3e5 + 5;
int cnt[Max];
int who[12];
int order[12];
int now = 1;
int n, q;
long long ans = INF;
long long sum = 0; long long dp[Max] = {}; 
void sol(int siz) {
    if(siz == now) {
        vector<int> v; 
         for(int i = 1; i <= n; i++) dp[i] = 1;
        for(int i = 1; i < now; i++) {
            int x; x = cnt[who[order[i]]];
            while(x--) {
                v.push_back(i);
            }
        }
        long long sum = 0;
        sum += dp[1];
        for(long long i = 1; i < v.size(); i++) {
            if(v[i] != v[i-1]) {
                dp[i+1] += i;
            }
            dp[i+1] += dp[i];
            sum += dp[i+1];
        }
        ans = min(ans,sum);
    }
    for(int i = siz; i < now; i++) {
        swap(order[siz],order[i]);
        sol(siz+1);
        swap(order[siz],order[i]);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin >> n >> q;
    for(int i = 0; i < 12; i++) order[i] = i;
   long long arr[n];
    for(int i = 0; i < n; i++) {
         cin >> arr[i];
         cnt[arr[i]]++;
    }
    for(int i = 0; i < Max; i++) {
        if(cnt[i] != 0) {
            who[now] = i;
            now++;
        }
    }
    if(q == 1) {
        int l, r; cin >> l >> r;
    }
    sol(1);
    cout << ans << endl;
    return 0;
}

Compilation message

diversity.cpp: In function 'void sol(int)':
diversity.cpp:29:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(long long i = 1; i < v.size(); i++) {
      |                              ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 57 ms 348 KB Output is correct
9 Correct 563 ms 344 KB Output is correct
10 Correct 5943 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 1442 ms 704 KB Output is correct
4 Execution timed out 7027 ms 4848 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 1442 ms 704 KB Output is correct
4 Execution timed out 7027 ms 4848 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 1442 ms 704 KB Output is correct
4 Execution timed out 7027 ms 4848 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 57 ms 348 KB Output is correct
9 Correct 563 ms 344 KB Output is correct
10 Correct 5943 ms 440 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 1442 ms 704 KB Output is correct
14 Execution timed out 7027 ms 4848 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 57 ms 348 KB Output is correct
9 Correct 563 ms 344 KB Output is correct
10 Correct 5943 ms 440 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 1442 ms 704 KB Output is correct
14 Execution timed out 7027 ms 4848 KB Time limit exceeded
15 Halted 0 ms 0 KB -