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>
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 |
---|
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... |