/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 532.0 KiB
#2 Wrong Answer 5ms 532.0 KiB
#3 Wrong Answer 28ms 680.0 KiB

Code

#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;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;
typedef vector<pld> vpld;
 
#define int ll
#define all(it) it.begin(),it.end()
#define ord_set(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> 


const string T = "SERIOUSOJ";

void work(){
    string s;
    cin >> s;
    vll v(26);
    for (auto &c : s) v[c-'A']++;

    auto shift = [](int a, int b) -> int {
        if (a > b) swap(a,b);
        return min(b-a, a + 25 - b);
    };

    vector<vll> best(27,vll((1 << 9),9*26+1));
    best[0][0] = 0;

    for (int i=0;i<26;i++){
        for (int j=0;j<(1 << 9);j++){
            int cnt = 0;
            int cost = 0;
            for (int b=0;b<9;b++) if ((1 << b) & j) cnt++, cost += shift(i,T[b]-'A');
            if (cnt > v[i]) continue;
            for (int k=0;k<(1 << 9);k++){
                int cur = k | j;
                best[i+1][cur] = min(best[i+1][cur],min(best[i][cur],best[i][k] + cost));
            }
        }
    }
    
    cout << best[26][(1<<9)-1] << '\n';
}


int32_t main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    while (n--) work();
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1188 The Mysty Lock
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-07 01:38:55
Judged At
2025-04-07 01:38:55
Judged By
Score
5
Total Time
28ms
Peak Memory
680.0 KiB