Submission #599574

# Submission time Handle Problem Language Result Execution time Memory
599574 2022-07-19T15:57:41 Z fvogel499 Boarding Passes (BOI22_passes) C++17
30 / 100
2000 ms 3084 KB
/*
 * File created on 07/19/2022 at 15:24:35.
 * Link to problem: 
 * Description: 
 * Time complexity: O()
 * Space complexity: O()
 * Status: ---
 * Copyright: Ⓒ 2022 Francois Vogel
*/

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pii pair<int, int>
#define f first
#define s second

#define vi vector<int>
#define all(x) x.begin(), x.end()
#define size(x) (int)((x).size())
#define pb push_back
#define ins insert
#define cls clear

#define int ll
#define ll long long
#define ld long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    string b;
    cin >> b;
    const int n = size(b);
    int gK = 0;
    for (char i : b) if (i-'A'+1 > gK) gK = i-'A'+1;
    vi toPermute;
    for (int i = 0; i < gK; i++) toPermute.pb(i);
    ld offMin = n*n;
    do {
        for (int i = 0; i < n; i++) {
            b[i] = char('A'+toPermute[b[i]-'A']);
        }
        ld res = 0;
        for (int i = 0; i < gK; i++) {
            vi pos;
            for (int j = 0; j < n; j++) if (b[j]-'A' == i) {
                pos.pb(j);
            }
            if (pos.empty()) continue;
            int pref [n];
            for (int j = 0; j < n; j++) pref[j] = (b[j]-'A' < i);
            for (int j = 1; j < n; j++) pref[j] += pref[j-1];
            int suf [n];
            for (int j = 0; j < n; j++) suf[j] = (b[j]-'A' < i);
            for (int j = n-2; j >= 0; j--) suf[j] += suf[j+1];
            for (int j = 0; j < size(pos); j++) {
                ld dl = 0;
                if (pos[j]) dl = pref[pos[j]-1];
                ld dr = 0;
                if (pos[j]+1 < n) dr = suf[pos[j]+1];
                ld cl = j;
                ld cr = size(pos)-1-j;
                res += min(dl+cl/2, dr+cr/2);
            }
        }
        offMin = min(offMin, res);
        vi invToPermute(gK);
        for (int i = 0; i < gK; i++) invToPermute[toPermute[i]] = i;
        for (int i = 0; i < n; i++) {
            b[i] = char('A'+invToPermute[b[i]-'A']);
        }
    } while (next_permutation(all(toPermute)));
    cout.precision(20);
    cout << offMin;

    cout.flush();
    int d = 0;
    d++;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 4 ms 2572 KB Output is correct
7 Correct 4 ms 2948 KB Output is correct
8 Correct 5 ms 3084 KB Output is correct
9 Correct 5 ms 3076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 49 ms 332 KB Output is correct
4 Correct 46 ms 316 KB Output is correct
5 Correct 45 ms 304 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 41 ms 212 KB Output is correct
8 Correct 12 ms 212 KB Output is correct
9 Correct 17 ms 320 KB Output is correct
10 Correct 16 ms 320 KB Output is correct
11 Correct 13 ms 320 KB Output is correct
12 Correct 15 ms 212 KB Output is correct
13 Correct 14 ms 324 KB Output is correct
14 Correct 15 ms 212 KB Output is correct
15 Correct 18 ms 320 KB Output is correct
16 Correct 19 ms 320 KB Output is correct
17 Correct 14 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 49 ms 332 KB Output is correct
4 Correct 46 ms 316 KB Output is correct
5 Correct 45 ms 304 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 41 ms 212 KB Output is correct
8 Correct 12 ms 212 KB Output is correct
9 Correct 17 ms 320 KB Output is correct
10 Correct 16 ms 320 KB Output is correct
11 Correct 13 ms 320 KB Output is correct
12 Correct 15 ms 212 KB Output is correct
13 Correct 14 ms 324 KB Output is correct
14 Correct 15 ms 212 KB Output is correct
15 Correct 18 ms 320 KB Output is correct
16 Correct 19 ms 320 KB Output is correct
17 Correct 14 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 50 ms 304 KB Output is correct
21 Correct 45 ms 300 KB Output is correct
22 Correct 45 ms 304 KB Output is correct
23 Correct 6 ms 320 KB Output is correct
24 Correct 41 ms 296 KB Output is correct
25 Correct 14 ms 212 KB Output is correct
26 Correct 18 ms 312 KB Output is correct
27 Correct 14 ms 212 KB Output is correct
28 Correct 14 ms 316 KB Output is correct
29 Correct 15 ms 320 KB Output is correct
30 Correct 14 ms 320 KB Output is correct
31 Correct 14 ms 316 KB Output is correct
32 Correct 15 ms 324 KB Output is correct
33 Correct 14 ms 212 KB Output is correct
34 Correct 15 ms 320 KB Output is correct
35 Execution timed out 2085 ms 856 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 4 ms 2572 KB Output is correct
7 Correct 4 ms 2948 KB Output is correct
8 Correct 5 ms 3084 KB Output is correct
9 Correct 5 ms 3076 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 49 ms 332 KB Output is correct
13 Correct 46 ms 316 KB Output is correct
14 Correct 45 ms 304 KB Output is correct
15 Correct 5 ms 212 KB Output is correct
16 Correct 41 ms 212 KB Output is correct
17 Correct 12 ms 212 KB Output is correct
18 Correct 17 ms 320 KB Output is correct
19 Correct 16 ms 320 KB Output is correct
20 Correct 13 ms 320 KB Output is correct
21 Correct 15 ms 212 KB Output is correct
22 Correct 14 ms 324 KB Output is correct
23 Correct 15 ms 212 KB Output is correct
24 Correct 18 ms 320 KB Output is correct
25 Correct 19 ms 320 KB Output is correct
26 Correct 14 ms 312 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 50 ms 304 KB Output is correct
30 Correct 45 ms 300 KB Output is correct
31 Correct 45 ms 304 KB Output is correct
32 Correct 6 ms 320 KB Output is correct
33 Correct 41 ms 296 KB Output is correct
34 Correct 14 ms 212 KB Output is correct
35 Correct 18 ms 312 KB Output is correct
36 Correct 14 ms 212 KB Output is correct
37 Correct 14 ms 316 KB Output is correct
38 Correct 15 ms 320 KB Output is correct
39 Correct 14 ms 320 KB Output is correct
40 Correct 14 ms 316 KB Output is correct
41 Correct 15 ms 324 KB Output is correct
42 Correct 14 ms 212 KB Output is correct
43 Correct 15 ms 320 KB Output is correct
44 Execution timed out 2085 ms 856 KB Time limit exceeded
45 Halted 0 ms 0 KB -