# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666262 | Chal1shkan | Kemija (COCI22_kemija) | C++17 | 1 ms | 328 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 pb push_back
# define ff first
# define ss second
# define nl "\n"
# define pii pair <int, int>
# define pll pair <ll, ll>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 2e6 + 125;
const ll maxl = 20 + 0;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
using namespace std;
void ma1n ()
{
set <char> st;
map <char, int> mp1, mp2;
string s;
cin >> s;
int pos = s.find('-');
string x = "";
for (int i = 0; i <= pos; ++i)
{
if (s[i] == '+' || i == pos)
{
int c = 1;
if (x[0] >= '2' && x[0] <= '9')
{
c = (x[0] - '0');
}
for (int i = 1; i < x.size(); ++i)
{
if (x[i] >= 'A' && x[i] <= 'Z')
{
st.insert(x[i]);
int val = 1;
if (i + 1 < x.size() && (x[i + 1] >= '2' && x[i + 1] <= '9'))
{
val = (x[i + 1] - '0');
}
mp1[x[i]] += (val * c);
}
}
x.clear();
}
else
{
x += s[i];
}
}
pos += 2;
for (int i = pos; i <= s.size(); ++i)
{
if (s[i] == '+' || i == s.size())
{
int c = 1;
if (x[0] >= '2' && x[0] <= '9')
{
c = (x[0] - '0');
}
for (int i = 1; i < x.size(); ++i)
{
if (x[i] >= 'A' && x[i] <= 'Z')
{
st.insert(x[i]);
int val = 1;
if (i + 1 < x.size() && (x[i + 1] >= '2' && x[i + 1] <= '9'))
{
val = (x[i + 1] - '0');
}
mp2[x[i]] += (val * c);
}
}
x.clear();
}
else
{
x += s[i];
}
}
for (char c : st)
{
// cout << "vot " << c << nl;
if (mp1[c] != mp2[c])
{
cout << "NE" << nl;
return;
}
}
cout << "DA" << nl;
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int ttt = 1;
cin >> ttt;
for (int test = 1; test <= ttt; test++)
{
// cout << "Case " << test << ":" << nl;
ma1n();
}
return 0;
}
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... |