Submission #704442

#TimeUsernameProblemLanguageResultExecution timeMemory
704442BrineTwKemija (COCI22_kemija)C++14
50 / 50
1 ms308 KiB
#include <bits/stdc++.h>

using namespace std;



bool evaluate(string& s) {
    s += '+';
    vector<int> count(26);
    
    string compound;
    int lr = 1;
    int allmul = 0;
    char last;
    vector<int> current(26);
    for (auto& c: s) {
        if (c == '+' || c == '-') {
            for (int i = 0; i < 26; i++) {
                count[i] += lr * allmul * current[i];
            }
            allmul = 0;
            current.assign(26, 0);
        } else if (c == '>') {
            lr = -1;
        } else if ('0' <= c && c <= '9') {
            if (allmul == 0) {
                allmul = c - '0';
            } else {
                current[last] += c - '1';
            }
        } else {
            if (allmul == 0) allmul = 1;
            current[c - 'A']++;
        }

        last = c - 'A';
    }
    for (int i = 0; i < 26; i++) {
        count[i] += lr * allmul * current[i];
    }


    for (auto& n: count) if (n) return 0;
    return 1;
}

int main() {
    int testdata;
    cin >> testdata;

    string s;
    while (testdata--) {
        cin >> s;

        cout << (evaluate(s) ? "DA\n" : "NE\n");
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...