#include <iostream>
#include <map>
using namespace std;
int N,M[500000][2],l,e,C,K;
string A[50000],B[50000];
map <string,int> Hola;
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N;
for (int i=0;i<N;i++) cin>>A[i];
for (int i=0;i<N;i++) cin>>B[i];
for (int i=0;i<N;i++) {
if (A[i][0]>='0' && A[i][0]<='9') {
l=A[i].size(); e=1;
for (int j=l-1;j>=0;j--) {
M[i][0]+=e*(A[i][j]-'0');
e*=10;
}
C++;
} else {
M[i][0]=-1;
}
if (B[i][0]>='0' && B[i][0]<='9') {
l=B[i].size(); e=1;
for (int j=l-1;j>=0;j--) {
M[i][1]+=e*(B[i][j]-'0');
e*=10;
}
C++;
} else {
M[i][1]=-1;
}
}
for (int i=0;i<N;i++) {
if (M[i][0]==-1) Hola[A[i]]=-1;
if (M[i][1]==-1) Hola[B[i]]=-1;
}
while (C<2*N) {
K=C;
for (int i=0;i<N;i++) {
if (M[i][0]>-1 && M[i][1]>-1) {
if (M[i][0]!=M[i][1]) {
cout<<"NE";
return 0;
}
} else {
if (M[i][0]>-1 || M[i][1]>-1) {
if (M[i][0]==-1) {
if (Hola[A[i]]==-1) {
Hola[A[i]]=M[i][1];
M[i][0]=M[i][1];
C++;
} else {
if (Hola[A[i]]!=M[i][1]) {
cout<<"NE";
return 0;
}
}
} else {
if (Hola[B[i]]==-1) {
Hola[B[i]]=M[i][0];
M[i][1]=M[i][0];
C++;
} else {
if (Hola[B[i]]!=M[i][0]) {
cout<<"NE";
return 0;
}
}
}
}
}
if (M[i][0]==-1 && M[i][1]==-1) {
if (Hola[A[i]]!=-1) {
M[i][1]=Hola[A[i]];
C++;
}
if (Hola[B[i]]!=1) {
M[i][0]=Hola[B[i]];
C++;
}
}
}
if (K==C) {
cout<<"DA";
return 0;
}
}
cout<<"DA";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
4 ms |
3584 KB |
Output is correct |
3 |
Correct |
4 ms |
3644 KB |
Output is correct |
4 |
Correct |
4 ms |
3644 KB |
Output is correct |
5 |
Correct |
4 ms |
3644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3644 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3644 KB |
Output is correct |
2 |
Correct |
5 ms |
3644 KB |
Output is correct |
3 |
Correct |
4 ms |
3644 KB |
Output is correct |
4 |
Correct |
5 ms |
3724 KB |
Output is correct |
5 |
Correct |
5 ms |
3780 KB |
Output is correct |
6 |
Incorrect |
5 ms |
3812 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3832 KB |
Output is correct |
2 |
Correct |
6 ms |
3840 KB |
Output is correct |
3 |
Incorrect |
12 ms |
3976 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
4384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |