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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define sp << " " <<
#define F(i, s, e) for(int i = s; i < e; i++)
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define vb vector<bool>
#define Tree tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
string st[2][n];
F(i, 0, 2) {
F(j, 0, n) cin >> st[i][j];
}
map<string, string> var;
F(i, 0, n) {
bool x1 = (st[i][0][0] - '0') < 10;
bool x2 = (st[i][0][1] - '0') < 10;
if(x1 && x2) {
if(st[0][i] != st[1][i]) {
cout << "NE" << endl;
return;
}
}
}
F(i, 0, n) {
bool x1 = (st[0][i][0] - '0') < 10;
bool x2 = (st[1][i][0] - '0') < 10;
if(x1 && !x2) {
if(var[st[i][1]].length() && var[st[1][i]] != st[0][i]) {
cout << "NE" << endl;
return;
} else var[st[1][i]] = st[0][i];
}
if(!x1 && x2) {
if(var[st[0][i]].length() && var[st[0][i]] != st[1][i]) {
cout << "NE" << endl;
return;
} else var[st[0][i]] = st[1][i];
}
}
F(repeat, 0, 2) {
F(i, 0, n) {
bool x1 = (st[0][i][0] - '0') < 10;
bool x2 = (st[0][i][0] - '0') < 10;
if(!x1 && !x2) {
bool e1 = var[st[0][i]].length();
bool e2 = var[st[1][i]].length();
if(e1 && e2) {
if(var[st[0][i]] != var[st[1][i]]) {
cout << "NE" << endl;
return;
}
} else if(e1 && !e2) {
var[st[1][i]] = var[st[0][i]];
} else if(!e1 && e2) {
var[st[0][i]] = var[st[1][i]];
}
}
}
}
cout << "DA" << endl;
}
int32_t main() {
cin.tie(0); ios_base::sync_with_stdio(0);
#ifdef Local
freopen("io.in", "r", stdin);
freopen("io.out", "w", stdout);
#endif
int t = 1;
//cin >> t;
while(t--) solve();
}
# | 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... |