답안 #865765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865765 2023-10-24T15:26:41 Z Rifal Diversity (CEOI21_diversity) C++14
4 / 100
7000 ms 4864 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 < 12; 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++) {
      |                              ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 59 ms 596 KB Output is correct
9 Correct 639 ms 348 KB Output is correct
10 Correct 6148 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 1445 ms 724 KB Output is correct
4 Execution timed out 7036 ms 4864 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 1445 ms 724 KB Output is correct
4 Execution timed out 7036 ms 4864 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 1445 ms 724 KB Output is correct
4 Execution timed out 7036 ms 4864 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 59 ms 596 KB Output is correct
9 Correct 639 ms 348 KB Output is correct
10 Correct 6148 ms 448 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 1445 ms 724 KB Output is correct
14 Execution timed out 7036 ms 4864 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 496 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 10 ms 348 KB Output is correct
8 Correct 59 ms 596 KB Output is correct
9 Correct 639 ms 348 KB Output is correct
10 Correct 6148 ms 448 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 19 ms 348 KB Output is correct
13 Correct 1445 ms 724 KB Output is correct
14 Execution timed out 7036 ms 4864 KB Time limit exceeded
15 Halted 0 ms 0 KB -