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>
using namespace std;
#define N (int)100 + 2
#define all(x) x.begin(), x.end()
bool isNum(string x) {
bool ok = true;
for (char c : x) {
int code = int(c - '0');
ok &= (0 <= code && code <= 9);
}
return ok;
}
int strToNum(string x) {
int res = 0 , base = 1;
reverse(all(x));
for (char c : x) {
int dig = int(c - '0');
res += (dig * base);
base *= 10;
}
return res;
}
int main() {
#ifdef judge
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif // judge
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int n;
cin >> n;
unordered_map<string , int> vars;
vector<string> a(n) , b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!isNum(a[i])) {
vars[a[i]] = -1;
}
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (!isNum(b[i])) {
vars[b[i]] = -1;
}
}
vector<int> bad;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) {
continue;
}
bool isNumA = isNum(a[i]) , isNumB = isNum(b[i]);
if (isNumA && isNumB) {
cout << "NE" << '\n';
return 0;
}
if (!isNumA && !isNumB) {
bad.push_back(i);
continue;
}
if (isNumA && !isNumB) {
if (vars[b[i]] == -1) {
vars[b[i]] = strToNum(a[i]);
} else {
if (strToNum(a[i]) != vars[b[i]]) {
cout << "NE" << '\n';
return 0;
}
}
}
if (!isNumA && isNumB) {
if (vars[a[i]] == -1) {
vars[a[i]] = strToNum(b[i]);
} else {
if (strToNum(b[i]) != vars[a[i]]) {
cout << "NE" << '\n';
return 0;
}
}
}
}
for (int pos : bad) {
if (vars[a[pos]] == -1 && vars[b[pos]] != -1) {
vars[a[pos]] = vars[b[pos]];
continue;
}
if (vars[a[pos]] != 1 && vars[b[pos]] == -1) {
vars[b[pos]] = vars[a[pos]];
continue;
}
if (vars[a[pos]] != vars[b[pos]]) {
cout << "NE" << '\n';
return 0;
}
}
cout << "DA" << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |