답안 #698617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698617 2023-02-14T05:27:25 Z Cyanmond Diversity (CEOI21_diversity) C++17
4 / 100
7000 ms 340 KB
#include <bits/stdc++.h>

using i64 = long long;
constexpr i64 inf64 = 1ll << 60;

struct Query {
    int l;
    int r;
};

int naive(std::vector<int> A) {
    const int N = (int)A.size();
    std::map<int, int> countS;
    for (const auto e : A) {
        ++countS[e];
    }
    A.clear();
    for (auto &[key, val] : countS) {
        A.push_back(val);
    }
    std::sort(A.begin(), A.end());
    std::vector<int> B(A.size());
    for (int i = 0; i < (int)A.size(); ++i) {
        if (i % 2 == 0) {
            B[i / 2] = A[i];
        } else {
            B[(int)A.size() - (i / 2) - 1] = A[i];
        }
    }
    A.clear();
    for (int i = 0; i < (int)B.size(); ++i) {
        for (int j = 0; j < (int)B[i]; ++j) {
            A.push_back(i);
        }
    }
    i64 ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= N; ++j) {
            std::set<int> s;
            for (int k = i; k < j; ++k) {
                s.insert(A[k]);
            }
            ans += (int)s.size();
        }
    }
    return ans;
    /*
    
    i64 mi = inf64;
    std::vector<int> v;
    do {
        std::vector<int> B;
        for (int i = 0; i < (int)A.size(); ++i) {
            for (int j = 0; j < (int)A[i]; ++j) {
                B.push_back(i);
            }
        }
        i64 ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 1; j <= N; ++j) {
                std::set<int> s;
                for (int k = i; k < j; ++k) {
                    s.insert(B[k]);
                }
                ans += (int)s.size();
            }
        }
        if (mi > ans) {
            mi = ans;
            v = A;
        }
    } while (std::next_permutation(A.begin(), A.end()));
    for (const auto e : v) {
        std::cout << e << ' ';
    }
    std::cout << std::endl;
    */
}

int main() {
    int N, Q;
    std::cin >> N >> Q;
    std::vector<int> A(N);
    for (auto &e : A) {
        std::cin >> e;
    }
    std::vector<Query> queries(Q);
    for (auto &[l, r] : queries) {
        std::cin >> l >> r;
        --l;
    }

    for (int i = 0; i < Q; ++i) {
        std::vector<int> vec;
        std::copy(A.begin() + queries[i].l, A.begin() + queries[i].r, std::back_inserter(vec));
        std::cout << naive(vec) << std::endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 444 ms 296 KB Output is correct
3 Execution timed out 7040 ms 340 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 444 ms 296 KB Output is correct
3 Execution timed out 7040 ms 340 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 444 ms 296 KB Output is correct
3 Execution timed out 7040 ms 340 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 444 ms 296 KB Output is correct
13 Execution timed out 7040 ms 340 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 444 ms 296 KB Output is correct
13 Execution timed out 7040 ms 340 KB Time limit exceeded
14 Halted 0 ms 0 KB -