#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) {
int v=vrednost[a[i]];
if (v>0) aa[i]=v;
}
if (bb[i]==-1) {
int v=vrednost[b[i]];
if (v>0) bb[i]=v;
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |