Submission #5762020


Source Code Expand

Copy
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)














int main(){
    string s;
    cin >> s;
    ll ans = 0, abc = 0, a = 0, p = 0;
    bool f = true;
    for(ll i = 0; i < s.size(); i++){
        if(f){
            if(s[i] == 'A'){
                a++;
            }
            else if(s[i] == 'B'){
                if(a > 0){
                    f = false;
                    a--;
                    p = 2;
                }
            }
            else{
                a = 0;
            }
        }
        else{
            if(p == 2){
                if(s[i] == 'C'){
                    abc++;
                    p = 0;
                }
                else{
                    if(abc > 0){
                        ans += abc * (abc + 1) / 2;
                        ans += a;
                    }
                    a = 0;
                    if(s[i] == 'A') a = 1;
                    abc = 0;
                    f = true;
                }
            }
            else if(p == 1){
                if(s[i] == 'B'){
                    p = 2;
                }
                else{
                    if(abc > 0){
                        ans += abc * (abc + 1) / 2;
                        ans += a;
                    }
                    if(s[i] == 'A'){
                        a = a + abc + 2;
                    }
                    else{
                        a = 0;
                    }
                    abc = 0;
                    f = true;
                }
            }
            else{
                if(s[i] == 'A'){
                    p = 1;
                }
                else{
                    if(abc > 0){
                        ans += abc * (abc + 1) / 2;
                        ans += a;
                    }
                    if(s[i] == 'B'){
                        p = 2;
                        a = abc - 1 + a;
                    }
                    else{
                        f = true;
                        a = 0;
                    }
                    abc = 0;
                }
            }
        }
        // cerr << i << " " << a << " " << abc << " " << ans << endl;
    }
    if(abc > 0){
        ans += abc * (abc + 1) / 2;
        ans += a;
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task B - ABC
User chocobo
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2910 Byte
Status
Exec Time 9 ms
Memory 640 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_000.txt, 0_001.txt, 0_002.txt
All 0 / 600 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt
Case Name Status Exec Time Memory
0_000.txt 1 ms 256 KB
0_001.txt 1 ms 256 KB
0_002.txt 1 ms 256 KB
1_003.txt 1 ms 256 KB
1_004.txt 1 ms 256 KB
1_005.txt 1 ms 256 KB
1_006.txt 9 ms 640 KB
1_007.txt 9 ms 640 KB
1_008.txt 9 ms 640 KB
1_009.txt 9 ms 640 KB
1_010.txt 9 ms 640 KB
1_011.txt 8 ms 640 KB
1_012.txt 8 ms 640 KB
1_013.txt 8 ms 640 KB
1_014.txt 8 ms 640 KB
1_015.txt 8 ms 640 KB
1_016.txt 8 ms 640 KB
1_017.txt 8 ms 640 KB
1_018.txt 8 ms 640 KB
1_019.txt 8 ms 640 KB
1_020.txt 8 ms 640 KB
1_021.txt 8 ms 640 KB
1_022.txt 9 ms 640 KB
1_023.txt 9 ms 640 KB
1_024.txt 9 ms 640 KB
1_025.txt 9 ms 640 KB
1_026.txt 9 ms 640 KB