답안 #972171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972171 2024-04-30T08:07:11 Z Circling Ekoeko (COCI21_ekoeko) C++17
110 / 110
19 ms 4240 KB
/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;


int64_t invcount(int *arr, int n){
    if (n < 2) return 0;
    int arr1[n / 2];
    for (int i = 0; i < n / 2; i++) arr1[i] = arr[i];
    int arr2[n - n / 2];
    for (int i = n / 2; i < n; i++) arr2[i - n / 2] = arr[i];
    int64_t ans = invcount(arr1, n / 2) + invcount(arr2, n  - n / 2);
    int p1 = 0, p2 = 0;
    while (p1 + p2 < n){
        if (p2 == n - n / 2){
            arr[p1 + p2] = arr1[p1];
            p1++;
        } else if (p1 == n / 2){
            arr[p1 + p2] = arr2[p2];
            p2++;
        } else if (arr1[p1] < arr2[p2]){
            arr[p1 + p2] = arr1[p1];
            p1++;
        } else {
            arr[p1 + p2] = arr2[p2];
            ans += n / 2 - p1;
            p2++;
        }
    }
    return ans;
}


int otherend[200000], rightend[100000];
pair<int, int> pairarr[100000];


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int64_t n, cntr = 0, ans, closedcount = 0;
    char c;
    cin >> n;
    vector<vector<int>> appr;
    appr.resize(26);
    for (int i = 0; i < 2 * n; i++){
        cin >> c;
        appr[c - 'a'].push_back(i);
    }
    for (int i = 0; i < 26; i++){
        for (uint32_t j = 0; j < appr[i].size() / 2; j++){
            otherend[appr[i][j]] = appr[i][j + appr[i].size() / 2];
            otherend[appr[i][j + appr[i].size() / 2]] = appr[i][j];
            pairarr[cntr] = {appr[i][j], appr[i][j + appr[i].size() / 2]};
            cntr++;
        }
    }
    sort(pairarr, pairarr + n);
    for (int i = 0; i < n; i++) rightend[i] = pairarr[i].second;
    ans = invcount(rightend, n);
    for (int i = 0; i < 2 * n; i++){
        if (i < otherend[i]) ans += closedcount;
        else closedcount++;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1624 KB Output is correct
3 Correct 7 ms 2964 KB Output is correct
4 Correct 11 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1624 KB Output is correct
3 Correct 7 ms 2964 KB Output is correct
4 Correct 11 ms 3932 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1624 KB Output is correct
3 Correct 7 ms 2964 KB Output is correct
4 Correct 11 ms 3932 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 17 ms 4184 KB Output is correct
7 Correct 17 ms 4188 KB Output is correct
8 Correct 17 ms 4188 KB Output is correct
9 Correct 16 ms 4188 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 16 ms 3932 KB Output is correct
12 Correct 16 ms 4188 KB Output is correct
13 Correct 16 ms 3932 KB Output is correct
14 Correct 15 ms 4056 KB Output is correct
15 Correct 15 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1624 KB Output is correct
3 Correct 7 ms 2964 KB Output is correct
4 Correct 11 ms 3932 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 17 ms 4184 KB Output is correct
11 Correct 17 ms 4188 KB Output is correct
12 Correct 17 ms 4188 KB Output is correct
13 Correct 16 ms 4188 KB Output is correct
14 Correct 16 ms 4184 KB Output is correct
15 Correct 16 ms 3932 KB Output is correct
16 Correct 16 ms 4188 KB Output is correct
17 Correct 16 ms 3932 KB Output is correct
18 Correct 15 ms 4056 KB Output is correct
19 Correct 15 ms 3932 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 17 ms 4188 KB Output is correct
33 Correct 17 ms 4188 KB Output is correct
34 Correct 17 ms 4188 KB Output is correct
35 Correct 19 ms 4240 KB Output is correct
36 Correct 17 ms 4180 KB Output is correct
37 Correct 16 ms 4188 KB Output is correct
38 Correct 16 ms 4108 KB Output is correct
39 Correct 16 ms 3932 KB Output is correct
40 Correct 16 ms 3932 KB Output is correct
41 Correct 16 ms 3932 KB Output is correct