#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string a[n], b[n];
for (int i=0;i<n;i++)
cin >> a[i];
for (int i=0;i<n;i++)
cin >> b[i];
map<string, int> vrednost;
int aa[n], bb[n];
memset(aa, -1, sizeof(aa));
memset(bb, -1, sizeof(bb));
for (int i=0;i<n;i++) {
int br1=-1, br2=-1;
if (a[i][0]-'0'<=9) br1=stoi(a[i]);
if (b[i][0]-'0'<=9) br2=stoi(b[i]);
if (br1!=-1&&br2!=-1) {
if (br1!=br2) {
cout << "NE";
return 0;
}
aa[i]=br1, bb[i]=br2;
}
else if (br1!=-1) {
int v=vrednost[b[i]];
if (v==0) vrednost[b[i]]=br1;
else if (v!=br1) {
cout << "NE";
return 0;
}
aa[i]=br1, bb[i]=br1;
}
else if (br2!=-1) {
int v=vrednost[a[i]];
if (v==0) vrednost[a[i]]=br2;
else if (v!=br2) {
cout << "NE";
return 0;
}
aa[i]=br2, bb[i]=br2;
}
}
for (int i=0;i<n;i++) {
if (aa[i]!=-1&&bb[i]!=-1) {
if (aa[i]!=bb[i]) {
cout << "NE";
return 0;
}
}
else if (aa[i]!=-1) {
int v=vrednost[b[i]];
if (v==0) vrednost[b[i]]=aa[i];
else if (v!=aa[i]) {
cout << "NE";
return 0;
}
bb[i]=aa[i];
}
else if (bb[i]!=-1) {
int v=vrednost[a[i]];
if (v==0) vrednost[a[i]]=bb[i];
else if (v!=bb[i]) {
cout << "NE";
return 0;
}
aa[i]=bb[i];
}
}
cout << "DA";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |