답안 #870924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870924 2023-11-09T13:17:11 Z hungnt Ekoeko (COCI21_ekoeko) C++14
110 / 110
8 ms 2188 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 200005;

int n;
string s;
queue<int> q[26];
int cnt[26], dem[26], BIT[N];

void update(int id)
{
    for(; id; id -= id & -id)
        BIT[id]++;
}

int get(int id)
{
    int ans = 0;
    for(; id <= n; id += id & -id)
        ans += BIT[id];
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> s;
    for(char &c : s)
    {
        c -= 'a';
        cnt[c]++;
    }
    int nn = n;
    s = ' ' + s;
    n <<= 1;
    int d = 0;
    long long ans = 0;
    int c;
    int x;
    for(int i = 1; i <= n; i++)
    {
        c = s[i];
        dem[c]++;
        if(dem[c] <= (cnt[c] >> 1))
        {
            x = ++d;
            q[c].push(d + nn);
        }
        else
        {
            x = q[c].front();
            q[c].pop();
        }
        ans += get(x);
        update(x);
    }
    cout << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:34:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   34 |         cnt[c]++;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 4 ms 1380 KB Output is correct
4 Correct 5 ms 1828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 4 ms 1380 KB Output is correct
4 Correct 5 ms 1828 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 4 ms 1380 KB Output is correct
4 Correct 5 ms 1828 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 2084 KB Output is correct
7 Correct 6 ms 2080 KB Output is correct
8 Correct 6 ms 1848 KB Output is correct
9 Correct 6 ms 1832 KB Output is correct
10 Correct 6 ms 1968 KB Output is correct
11 Correct 6 ms 1832 KB Output is correct
12 Correct 7 ms 1836 KB Output is correct
13 Correct 7 ms 1856 KB Output is correct
14 Correct 6 ms 1844 KB Output is correct
15 Correct 6 ms 1844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 484 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 4 ms 1380 KB Output is correct
4 Correct 5 ms 1828 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 8 ms 2084 KB Output is correct
11 Correct 6 ms 2080 KB Output is correct
12 Correct 6 ms 1848 KB Output is correct
13 Correct 6 ms 1832 KB Output is correct
14 Correct 6 ms 1968 KB Output is correct
15 Correct 6 ms 1832 KB Output is correct
16 Correct 7 ms 1836 KB Output is correct
17 Correct 7 ms 1856 KB Output is correct
18 Correct 6 ms 1844 KB Output is correct
19 Correct 6 ms 1844 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 484 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 484 KB Output is correct
32 Correct 7 ms 1972 KB Output is correct
33 Correct 7 ms 1960 KB Output is correct
34 Correct 7 ms 1880 KB Output is correct
35 Correct 6 ms 2188 KB Output is correct
36 Correct 6 ms 1832 KB Output is correct
37 Correct 6 ms 1836 KB Output is correct
38 Correct 6 ms 1840 KB Output is correct
39 Correct 6 ms 1812 KB Output is correct
40 Correct 7 ms 2096 KB Output is correct
41 Correct 6 ms 1840 KB Output is correct