//Trương Minh Trí
#include <bits/stdc++.h>
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define FORN(i, x, y) for(int i = x; i >= y; --i)
#define Task "Zamjena"
#define maxn 50005
#define maxm
#define emlacongchuacuaanh 1302
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define reset(x) memset(x, 0, sizeof(x));
using namespace std;
int n;
string a[maxn], b[maxn];
bool ok(string x)
{
return (x[0] >= '0' && x[0] <= '9');
}
map<string, string> mm;
int save[maxn], cnt;
int save1[maxn], cnt1;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//freopen(Task".inp", "r", stdin);
//freopen(Task".out", "w", stdout);
cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> b[i];
FOR(i, 1, n)
{
if(!ok(a[i]) && !ok(b[i]))
{
save[++cnt] = i;
continue;
}
if(ok(a[i]) && ok(b[i]))
{
if(a[i] == b[i]) continue;
else return cout <<"NE", 0;
}
if(ok(a[i]) && !ok(b[i]))
{
if(mm[b[i]] =="") mm[b[i]] = a[i];
else if(mm[b[i]] != a[i]) return cout <<"NE", 0;
}
if(!ok(a[i]) && ok(b[i]))
{
if(mm[a[i]] == "") mm[a[i]] = b[i];
else if(mm[a[i]] != b[i]) return cout <<"NE", 0;
}
}
FOR(i, 1, cnt)
{
int pos = save[i];
if(mm[a[pos]] != "" && mm[b[pos]] != "")
{
if(mm[a[pos]] == mm[b[pos]]) continue;
else return cout <<"NE", 0;
}
else if(mm[a[pos]] =="" && mm[b[pos]] == "")
{
save1[++cnt1] = pos;
continue;
}
else if(mm[b[i]] != "" ) mm[a[i]] = mm[b[i]];
else mm[b[i]] = mm[a[i]];
}
FOR(i, 1, cnt1)
{
int pos = save1[i];
if(mm[a[pos]] != "" && mm[b[pos]] != "")
{
if(mm[a[pos]] == mm[b[pos]]) continue;
else return cout <<"NE", 0;
}
else if(mm[a[pos]] =="" && mm[b[pos]] == "")
{
mm[a[i]] = mm[b[i]] = "HVH";
}
else if(mm[b[i]] != "" ) mm[a[i]] = mm[b[i]];
else mm[b[i]] = mm[a[i]];
}
cout << "DA";
}
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3576 KB |
Output is correct |
3 |
Correct |
6 ms |
3576 KB |
Output is correct |
4 |
Correct |
5 ms |
3680 KB |
Output is correct |
5 |
Correct |
5 ms |
3680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3680 KB |
Output is correct |
2 |
Correct |
4 ms |
3680 KB |
Output is correct |
3 |
Correct |
4 ms |
3720 KB |
Output is correct |
4 |
Correct |
5 ms |
3740 KB |
Output is correct |
5 |
Correct |
5 ms |
3744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
3748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
3880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4528 KB |
Output is correct |
2 |
Incorrect |
33 ms |
5664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |