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>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n;
string a[50004],b[50004];
int toint(string s){
int ten=1;
int ret=0;
for(int i=s.size()-1;i>=0;i--){
ret+=(s[i]-'0')*ten;
ten*=10;
}
return ret;
}
map<string,int>val;
map<string,bool>existval;
int main()
{
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'){
if(b[i][0]>='0'&&b[i][0]<='9'){if(toint(a[i])!=toint(b[i])){cout<<"NE";return 0;}}
else {
if(!existval[b[i]])
{val[b[i]]=toint(a[i]),existval[b[i]]=1;}
else if(val[b[i]]!=toint(a[i])){cout<<"NE";return 0;}
}
}
else
{
if(b[i][0]>='0'&&b[i][0]<='9')
{
if(!existval[a[i]]){existval[a[i]]=1;val[a[i]]=toint(b[i]);}
else if(toint(b[i])!=val[a[i]]){cout<<"NE";return 0;}
}
else
{
if(existval[a[i]]){
if(existval[b[i]]){if(val[a[i]]!=val[b[i]]){cout<<"NE";return 0;}}
else
{
existval[b[i]]=1;
val[b[i]]=val[a[i]];
}
}
else
{
if(existval[b[i]]){
existval[a[i]]=1;
val[a[i]]=val[b[i]];
}
}
}
}
}
for(int i=0;i<n;i++){
if(a[i][0]<='z'&&a[i][0]>='a'&&b[i][0]<='z'&&b[i][0]>='a'){
if(existval[a[i]]){
if(existval[b[i]]){if(val[a[i]]!=val[b[i]]){cout<<"NE";return 0;}}
else
{
existval[b[i]]=1;
val[b[i]]=val[a[i]];
}
}
else
{
if(existval[b[i]]){
existval[a[i]]=1;
val[a[i]]=val[b[i]];
}
}
}
}
/*string s="1099";
cout<<toint(s);*/
cout<<"DA"<<endl;
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... |