Submission #874961

# Submission time Handle Problem Language Result Execution time Memory
874961 2023-11-18T10:31:05 Z HossamHero7 Kemija (COCI22_kemija) C++14
50 / 50
1 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
vector<int> solveEq(string s){
    int coef = 1;
    int st = 0;
    if(isdigit(s[0])) coef = s[0] - '0' , st = 1;
    vector<int> frq(26);
    for(int i=st;i<s.size();i++){
        if(i+1<s.size() && isdigit(s[i+1])) frq[s[i]-'A'] += coef * (s[i+1]-48) , i++;
        else frq[s[i]-'A'] += coef;
    }
    return frq;
}
void solve(){
    string s;
    cin>>s;
    string s1 = "";
    string s2 = "";
    bool b = 0;
    for(auto i : s){
        if(i == '>') b = 1;
        if(i == '-' || i =='>') continue;
        if(!b) s1 += i;
        else s2 += i;
    }
    vector<int> frq1(26) , frq2(26);
    string tmp = "";
    for(auto i : s1){
        if(i == '+'){
            vector<int> f = solveEq(tmp);
            for(int j=0;j<26;j++) frq1[j] += f[j];
            tmp = "";
            continue;
        }
        tmp += i;
    }
    vector<int> f = solveEq(tmp);
    for(int j=0;j<26;j++) frq1[j] += f[j];
    tmp = "";
    for(auto i : s2){
        if(i == '+'){
            vector<int> f = solveEq(tmp);
            for(int j=0;j<26;j++) frq2[j] += f[j];
            tmp = "";
            continue;
        }
        tmp += i;
    }
    f = solveEq(tmp);
    for(int j=0;j<26;j++) frq2[j] += f[j];
    cout<<(frq1 == frq2 ? "DA" : "NE")<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

Main.cpp: In function 'std::vector<int> solveEq(std::string)':
Main.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=st;i<s.size();i++){
      |                  ~^~~~~~~~~
Main.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         if(i+1<s.size() && isdigit(s[i+1])) frq[s[i]-'A'] += coef * (s[i+1]-48) , i++;
      |            ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct