제출 #1083021

#제출 시각아이디문제언어결과실행 시간메모리
1083021weakweakweakHomework (CEOI22_homework)C++17
53 / 100
1018 ms14168 KiB
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define fs first 
#define sc second

string s;
int meow = 0;
pii f(int st, int ed) {
    if (st == ed) {
        meow++;
        return {0,0};
    }
    int complace = st, now = 0;
    for (int i = st; i < ed; i++) {
        if (s[i] == '(') now++;
        if (s[i] == ')') now--;
        if (s[i] == ',' and now==1) complace = i;
    }
    pii p1 = f(st+4, complace-1);
    pii p2 = f(complace+1, ed-1);
    if (s[st + 1]=='a') return {p1.fs+p2.fs+1, min(p1.sc,p2.sc)};
    else return {min(p1.fs,p2.fs), p1.sc+p2.sc+1};
}

int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> s;
    pii p = f(0, s.size()-1);
    cout << meow - p.fs - p.sc << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...