# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159685 | socho | Zamjena (COCI18_zamjena) | C++14 | 0 ms | 0 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"
using namespace std;
bool isn(string s) {
char x = s[0];
if (x >= '0' && x <= '9') return true;
return false;
}
int main(){
int n;
cin >> n;
string a1[n], a2[n];
for (int i=0; i<n; i++) cin >> a1[i];
for (int i=0; i<n; i++) cin >> a2[i];
map<string, bool> locked;
map<string, string> lockto;
vector<pair<string, string> > eq;
for (int i=0; i<n; i++) {
string a=a1[i], b=a2[i];
if (a == b) continue;
if (isn(a) && isn(b)) {5
if (a == b) continue;
cout << "NE" << endl;
exit(0);
}
else if (isn(a)) {
if (locked[b]) {
if (lockto[b] != a) {
cout << "NE" << endl;
exit(0);
}
}
else {
locked[b] = true;
lockto[b] = a;
}
}
else if (isn(b)) {
if (locked[a]) {
if (lockto[a] != b) {
cout << "NE" << endl;
exit(0);
}
}
else {
locked[a] = true;
lockto[a] = b;
}
}
else {
if (locked[a]) {
locked[b] = true;
lockto[b] = lockto[a];
}
else if (locked[b]) {
locked[a] = true;
lockto[a] = lockto[b];
}
else {
eq.push_back(make_pair(a, b));
}
}
}
for (int i=0; i<eq.size(); i++) {
string a = eq[i].first, b = eq[i].second;
if (locked[a] && locked[b]) {
if (lockto[a] != lockto[b]) {
cout << "NE" << endl;
exit(0);
}
}
}
cout << "DA" << endl;
}