/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 1ms 420.0 KiB
#3 Wrong Answer 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    string m = "SERIOUSOJ";
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();
        map<char, int> mp;
        for (int i = 0; i < n; i++)
        {
            mp[s[i]]++;
        }
        int ans = 0;
        for (auto x : m)
        {
            if (mp[x])
            {
                mp[x]--;
            }
            else
            {
                for (int i = 1; i <= 26; i++)
                {
                    char next;
                    if ((x - 'A') + i == 25)
                        next = 'Z';
                    else if ((x - 'A') + 1 > 25)
                    {
                        int y = ((x - 'A') + i) % 26;
                        next = char('A' + y);
                    }
                    else
                    {
                        next = x + i;
                    }
                    if (mp[next])
                    {
                        mp[next]--;
                        ans += i;
                        break;
                    }
                    char before;
                    if ((x - 'A') - i == 0)
                        before = 'A';
                    else if ((x - 'A') - 1 < 0)
                    {
                        int y = ((x - 'A') - i) % 26;
                        before = char('Z' + y);
                    }
                    else
                    {
                        before = x - i;
                    }
                    if (mp[before])
                    {
                        mp[before]--;
                        ans += i;
                        break;
                    }
                }
            }
        }
        cout << ans << '\n';
    }
}

Information

Submit By
Type
Submission
Problem
P1188 The Mysty Lock
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 17:57:26
Judged At
2025-04-06 17:57:26
Judged By
Score
5
Total Time
1ms
Peak Memory
532.0 KiB