#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
7 ms |
768 KB |
Output is correct |
4 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1536 KB |
Output is correct |
2 |
Incorrect |
15 ms |
3072 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |