This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: NotLinux
* created: 09.09.2022 ~ 13:22:10
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include "/home/notlinux/debug.h"
#else
#define debug(x...) void(37)
#endif
vector < int > procces2(string str){
vector < int > result2(26,0LL);
int kat = 1;
if(str[0]>='2' and str[0]<='9')kat = str[0]-'0';
for(int i = 0;i<(int)str.size();i++){
if(str[i]>='A' and str[i]<='Z'){
int kat2 = 1;
if(i!=((int)str.size()-1) and (str[i+1]>='1' and str[i+1]<='9')){
kat2 = str[i+1]-'0';
}
result2[str[i]-'A'] += kat2;
}
}
for(int i = 0;i<26;i++)result2[i]*=kat;
return result2;
}
vector < int > procces(string str){
str += '+';
vector < int > result(26,0LL);
int left = 0;
for(int i = 0;i<(int)str.size();i++){
if(str[i] == '+'){
vector < int > locresult = procces2(string(str.begin()+left,str.begin()+i));
for(int i = 0;i<26;i++){
result[i] += locresult[i];
}
left = i+1;
}
}
return result;
}
void solve(){
string eq;cin >> eq;
int ind = 0;
for(int i = 0;i<(int)eq.size();i++){
if(eq[i] == '-'){
ind = i;
break;
}
}
vector < int > left = procces(string(eq.begin() , eq.begin()+ind));
vector < int > right = procces(string(eq.begin()+ind+2 , eq.end()));
cout << (left == right ? "DA" : "NE") << endl;
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
int tt=1;
cin >> tt;
while(tt--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |