Submission #727345

# Submission time Handle Problem Language Result Execution time Memory
727345 2023-04-20T12:32:54 Z mdn2002 Ekoeko (COCI21_ekoeko) C++14
110 / 110
238 ms 2732 KB
#include <bits/stdc++.h>
using namespace std;
long long n , is [200005] , ans , numm [31] , aa , bb;
vector < int > l [31] , r [31];
string s , a , b;
int main()
{
    cin >> n >> s;
    for ( int i = 0 ; i < 2 * n ; i ++ )
    {
        int c = s [i] - 'a';
        numm [c] ++;
    }
    for ( int i = 0 ; i < 2 * n ; i ++ )
    {
        int c = s [i] - 'a';
        if ( l [c] . size () != numm [c] / 2 ) l [c] . push_back ( i );
        else
        {
            r [c] . push_back ( i );
            is [i] = 1;
        }
    }
    int num = 0;
    for ( int i = n - 1 ; i >= 0 ; i -- )
    {
        if ( is [i] == 0 )
        {
            num ++;
            a . push_back ( s [i] );
        }
        else
        {
            ans += num;
            bb ++;
            b . push_back ( s [i] );
        }

    }
    reverse ( a . begin () , a . end () );
    reverse ( b . begin () , b . end () );
    num = 0;
    for ( int i = n ; i < 2 * n ; i ++ )
    {
        if ( is [i] == 1 )
        {
            num ++;
            b . push_back ( s [i] );
        }
        else
        {
            ans += num;
            aa ++;
            a . push_back ( s [i] );
        }
    }
    ans += aa * bb;
    for ( int i = 0 ; i < n ; i ++ )
    {
        for ( int j = i ; j < n ; j ++ )
        {
            if ( a [i] == b [j] )
            {
                for ( int k = j ; k > i ; k -- )
                {
                    ans ++;
                    swap ( b [k] , b [ k - 1 ] );
                }
                break;
            }
        }
    }
    cout << ans;
}













Compilation message

Main.cpp: In function 'int main()':
Main.cpp:17:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   17 |         if ( l [c] . size () != numm [c] / 2 ) l [c] . push_back ( i );
      |              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 7 ms 1900 KB Output is correct
4 Correct 9 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 7 ms 1900 KB Output is correct
4 Correct 9 ms 2668 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 7 ms 1900 KB Output is correct
4 Correct 9 ms 2668 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 202 ms 2708 KB Output is correct
7 Correct 182 ms 2724 KB Output is correct
8 Correct 153 ms 2660 KB Output is correct
9 Correct 161 ms 2696 KB Output is correct
10 Correct 195 ms 2668 KB Output is correct
11 Correct 189 ms 2660 KB Output is correct
12 Correct 159 ms 2660 KB Output is correct
13 Correct 165 ms 2640 KB Output is correct
14 Correct 144 ms 2532 KB Output is correct
15 Correct 164 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 7 ms 1900 KB Output is correct
4 Correct 9 ms 2668 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 202 ms 2708 KB Output is correct
11 Correct 182 ms 2724 KB Output is correct
12 Correct 153 ms 2660 KB Output is correct
13 Correct 161 ms 2696 KB Output is correct
14 Correct 195 ms 2668 KB Output is correct
15 Correct 189 ms 2660 KB Output is correct
16 Correct 159 ms 2660 KB Output is correct
17 Correct 165 ms 2640 KB Output is correct
18 Correct 144 ms 2532 KB Output is correct
19 Correct 164 ms 2584 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 238 ms 2732 KB Output is correct
33 Correct 228 ms 2720 KB Output is correct
34 Correct 228 ms 2708 KB Output is correct
35 Correct 216 ms 2696 KB Output is correct
36 Correct 200 ms 2576 KB Output is correct
37 Correct 190 ms 2688 KB Output is correct
38 Correct 213 ms 2668 KB Output is correct
39 Correct 236 ms 2668 KB Output is correct
40 Correct 214 ms 2612 KB Output is correct
41 Correct 223 ms 2604 KB Output is correct