답안 #704442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704442 2023-03-02T06:25:29 Z BrineTw Kemija (COCI22_kemija) C++14
50 / 50
1 ms 308 KB
#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");
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct