Submission #31717020


Source Code Expand

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

int n;
char s[200005];
vector<int> a;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>s;
    int o=0;
    multiset<int> t;
    for(int i=0;i<n;i++)if(s[i]=='R'){
        int c=0;
        while(i-c-1>=0&&s[i-c-1]=='A'&&i+c+1<n&&s[i+c+1]=='C')c++;
        if(c==1)o++;
        if(c>1)t.emplace(c);
    }
    int ans=0;
    while(true){
        if(ans&1){
            if(o){
                o--;
                ans++;
            }else if(!t.empty()){
                t.erase(t.begin());
                ans++;
            }else break;
        }else{
            if(!t.empty()){
                int c=*t.begin();
                t.erase(t.begin());
                c--;
                ans++;
                if(c==1)o++;
                else t.emplace(c);
            }else if(o){
                o--;
                ans++;
            }else break;
        }
    }
    cout<<ans<<'\n';

    return 0;
}

Submission Info

Submission Time
Task B - Shorten ARC
User Kizuna_AI
Language C++ (GCC 9.2.1)
Score 400
Code Size 1042 Byte
Status AC
Exec Time 13 ms
Memory 4996 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 28
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt, 02_handmade_15.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 5 ms 3464 KiB
00_sample_02.txt AC 3 ms 3460 KiB
00_sample_03.txt AC 2 ms 3424 KiB
01_random_01.txt AC 5 ms 3792 KiB
01_random_02.txt AC 5 ms 3808 KiB
01_random_03.txt AC 7 ms 3760 KiB
01_random_04.txt AC 5 ms 3792 KiB
01_random_05.txt AC 8 ms 3604 KiB
01_random_06.txt AC 5 ms 3696 KiB
01_random_07.txt AC 8 ms 3724 KiB
01_random_08.txt AC 7 ms 3660 KiB
01_random_09.txt AC 7 ms 3748 KiB
01_random_10.txt AC 6 ms 3728 KiB
02_handmade_01.txt AC 3 ms 3616 KiB
02_handmade_02.txt AC 4 ms 3692 KiB
02_handmade_03.txt AC 13 ms 4828 KiB
02_handmade_04.txt AC 12 ms 4932 KiB
02_handmade_05.txt AC 9 ms 4932 KiB
02_handmade_06.txt AC 9 ms 4984 KiB
02_handmade_07.txt AC 9 ms 4964 KiB
02_handmade_08.txt AC 13 ms 4996 KiB
02_handmade_09.txt AC 9 ms 4932 KiB
02_handmade_10.txt AC 11 ms 4812 KiB
02_handmade_11.txt AC 9 ms 4968 KiB
02_handmade_12.txt AC 9 ms 4856 KiB
02_handmade_13.txt AC 9 ms 4808 KiB
02_handmade_14.txt AC 11 ms 4684 KiB
02_handmade_15.txt AC 11 ms 4588 KiB