# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1020983 | vjudge1 | Kemija (COCI22_kemija) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
#define N 200005
using namespace std;
typedef array <int, 26> chem;
chem bos;
void print(chem huh) {
cout << "array:\n";
for(int i = 0; i < 2; i++) {
cout << huh[i] << " ";
}
cout << "\n";
};
chem freq(string s) {
chem ret = bos;
int times = (s[0] < 'A') ? s[0] - '0' : 1;
for(int i = (s[0] < 'A') ? 1 : 0; i < s.size(); i++) {
if(i + 1 < s.size() and s[i + 1] < 'A') {
ret[s[i] - 'A'] += times * (s[i + 1] - '0');
i++;
}
else {
ret[s[i] - 'A'] += times;
}
}
return ret;
}
chem sum(chem a, chem b) {
chem ret;
for(int i = 0; i < 26; i++) {
ret[i] = a[i] + b[i];
}
return ret;
}
void solve(){
string s;
cin >> s;
int prev = 0;
for(int i = 0; i < 26; i++) {
bos[i] = 0;
}
vector<chem> formula(2, bos);
bool side = 0;
s.push_back('+');
for(int i = 1; i < s.size(); i++) {
if(s[i] == '+' or s[i] == '-') {
string t = s.substr(prev, i - prev);
chem wtf = freq(t);
// print(wtf);
formula[side] = sum(formula[side], wtf);
prev = i + 1;
}
if(s[i] == '-') {
i++;
prev++;
side = 1;
}
}
bool yes = 1;
for(int i = 0; i < 26; i++) {
if(formula[0][i] != formula[1][i]) yes = 0;
}
if(yes) {
cout << "DA\n";
}
else {
cout << "NE\n";
}
}
int32_t main(){
fast
int t=1;
cin >> t;
while(t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |