Submission #693886

# Submission time Handle Problem Language Result Execution time Memory
693886 2023-02-03T11:10:48 Z delrey Kemija (COCI22_kemija) C++14
50 / 50
1 ms 304 KB
#include <bits/stdc++.h>

using namespace std;

int n;
string equation;

int Digit(int i)
{
    if(i < n && equation[i] >= '2' && equation[i] <= '9')
        return equation[i] - '0';
    return 1;
}

int main()
{
    int tn, atomsLeft[26], atomsRight[26];
    cin>>tn;
    while(tn--)
    {
        for(int i = 0; i < 26; i++)
        {
            atomsLeft[i] = 0;
            atomsRight[i] = 0;
        }
        cin>>equation;
        n = equation.size();
        int arrow = 0;
        while(equation[arrow] != '-')
            arrow++;
        int mul = 1, i = -1;
        while(i < arrow - 1)
        {
            i++;
            if(equation[i] == '+')
            {
                mul = 1;
                continue;
            }
            if(equation[i] >= '2' && equation[i] <= '9')
            {
                mul = equation[i] - '0';
                continue;
            }
            atomsLeft[equation[i] - 'A'] += mul * Digit(i + 1);
            if(Digit(i + 1) > 1)
                i++;
        }
        mul = 1;
        i = arrow + 1;
        while(i < n - 1)
        {
            i++;
            if(equation[i] == '+')
            {
                mul = 1;
                continue;
            }
            if(equation[i] >= '2' && equation[i] <= '9')
            {
                mul = equation[i] - '0';
                continue;
            }
            atomsRight[equation[i] - 'A'] += mul * Digit(i + 1);
            if(Digit(i + 1) > 1)
                i++;
        }
        bool notEqual = false;
        for(int i = 0; i < 26; i++)
            if(atomsLeft[i] != atomsRight[i])
            {
                notEqual = true;
                break;
            }
        /*
        for(int i = 0; i < 26; i++)
            cout<<atomsLeft[i]<<" ";
        cout<<endl;
        for(int i = 0; i < 26; i++)
            cout<<atomsRight[i]<<" ";
        cout<<endl;
        */
        if(notEqual)
            cout<<"NE"<<endl;
        else
            cout<<"DA"<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 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 304 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 300 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 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 0 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 304 KB Output is correct