Submission #1794272


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



struct Node {
    Node *lef, *rig;
    char c = '?';
};

string S;
map<char, int> win;
//---------------------------------------------------------------------------------------------------
int i = 0;
Node* parse() {
    Node *res = new Node();

    if (S[i] == '[') {
        i++;
        res->lef = parse();
        assert(S[i] == '-');
        i++;
        res->rig = parse();
        assert(S[i] == ']');
        i++;
    } else {
        char c = S[i]; i++;
        win[c] = 0;
        
        res->c = c;
        res->lef = res->rig = 0;
    }

    return res;
}
//---------------------------------------------------------------------------------------------------
string ans = "Yes";
char check(Node* n) {
    if (n->c != '?') return n->c;

    char a = check(n->lef);
    char b = check(n->rig);

    if (win[a] == 0 and 0 < win[b]) {
        win[b]--;
        return b;
    }

    if (win[b] == 0 and 0 < win[a]) {
        win[a]--;
        return a;
    }

    ans = "No";
    return a;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S; S += "#";
    auto root = parse();
    int N = win.size();
    rep(i, 0, N) {
        char c; int a;
        cin >> c >> a;
        win[c] = a;
    }
    char c = check(root);

    if (win[c] != 0) ans = "No";
    cout << ans << endl;
}

Submission Info

Submission Time
Task B - Tournament Chart
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2378 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 49
Set Name Test Cases
All 00_sample_00, 00_sample_01, 10_tiny_00, 10_tiny_01, 10_tiny_02, 10_tiny_03, 10_tiny_04, 10_tiny_05, 10_tiny_06, 10_tiny_07, 10_tiny_08, 10_tiny_09, 20_small_00, 20_small_01, 20_small_02, 20_small_03, 20_small_04, 20_small_05, 20_small_06, 20_small_07, 20_small_08, 20_small_09, 30_middle_00, 30_middle_01, 30_middle_02, 30_middle_03, 30_middle_04, 30_middle_05, 30_middle_06, 30_middle_07, 30_middle_08, 30_middle_09, 40_large_00, 40_large_01, 40_large_02, 40_large_03, 40_large_04, 40_large_05, 40_large_06, 40_large_07, 40_large_08, 40_large_09, 90_handmade_00, 90_handmade_01, 90_handmade_02, 90_handmade_03, 90_handmade_04, 90_handmade_05, 90_handmade_06
Case Name Status Exec Time Memory
00_sample_00 AC 1 ms 256 KB
00_sample_01 AC 1 ms 256 KB
10_tiny_00 AC 1 ms 256 KB
10_tiny_01 AC 1 ms 256 KB
10_tiny_02 AC 1 ms 256 KB
10_tiny_03 AC 1 ms 256 KB
10_tiny_04 AC 1 ms 256 KB
10_tiny_05 AC 1 ms 256 KB
10_tiny_06 AC 1 ms 256 KB
10_tiny_07 AC 1 ms 256 KB
10_tiny_08 AC 1 ms 256 KB
10_tiny_09 AC 1 ms 256 KB
20_small_00 AC 1 ms 256 KB
20_small_01 AC 1 ms 256 KB
20_small_02 AC 1 ms 256 KB
20_small_03 AC 1 ms 256 KB
20_small_04 AC 1 ms 256 KB
20_small_05 AC 1 ms 256 KB
20_small_06 AC 1 ms 256 KB
20_small_07 AC 1 ms 256 KB
20_small_08 AC 1 ms 256 KB
20_small_09 AC 1 ms 256 KB
30_middle_00 AC 1 ms 256 KB
30_middle_01 AC 1 ms 256 KB
30_middle_02 AC 1 ms 256 KB
30_middle_03 AC 1 ms 256 KB
30_middle_04 AC 1 ms 256 KB
30_middle_05 AC 1 ms 256 KB
30_middle_06 AC 1 ms 256 KB
30_middle_07 AC 1 ms 256 KB
30_middle_08 AC 1 ms 256 KB
30_middle_09 AC 1 ms 256 KB
40_large_00 AC 1 ms 256 KB
40_large_01 AC 1 ms 256 KB
40_large_02 AC 1 ms 256 KB
40_large_03 AC 1 ms 256 KB
40_large_04 AC 1 ms 256 KB
40_large_05 AC 1 ms 256 KB
40_large_06 AC 1 ms 256 KB
40_large_07 AC 1 ms 256 KB
40_large_08 AC 1 ms 256 KB
40_large_09 AC 1 ms 256 KB
90_handmade_00 AC 1 ms 256 KB
90_handmade_01 AC 1 ms 256 KB
90_handmade_02 AC 1 ms 256 KB
90_handmade_03 AC 1 ms 256 KB
90_handmade_04 AC 1 ms 256 KB
90_handmade_05 AC 1 ms 256 KB
90_handmade_06 AC 1 ms 256 KB