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;
typedef long long ll;
#define read freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define LESSGO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N=1e6+10,M=505,OO=1e16,mod=1e9+7;
int n,cur;
string s;
vector<int>a,b;
map<string,int>idx;
map<int,int>val;
bool isDigit(char c){
return c>='0'&&c<='9';
}
int main(){
cin>>n;
for(int i=0;i<n;++i){
cin>>s;
if(isDigit(s[0])) a.push_back(stoi(s));
else{
if(idx[s]) a.push_back(idx[s]);
else{
idx[s]=++cur;
idx[s]*=-1;
a.push_back(idx[s]);
}
}
}
for(int i=0;i<n;++i){
cin>>s;
if(isDigit(s[0])) b.push_back(stoi(s));
else{
if(idx[s]) b.push_back(idx[s]);
else{
idx[s]=++cur;
idx[s]*=-1;
b.push_back(idx[s]);
}
}
}
bool valid=1;
for(int i=0;i<n;++i){
if(a[i]>0&&b[i]>0){
if(a[i]!=b[i]){
valid=0;
break;
}
}
if(a[i]>0&&b[i]<0){
if(!(val[b[i]]==0||val[b[i]]==a[i])){
valid=0;
break;
}else val[b[i]]=a[i];
}
if(a[i]<0&&b[i]>0){
if(!(val[a[i]]==0||val[a[i]]==b[i])){
valid=0;
break;
}else val[a[i]]=b[i];
}
}
puts(valid?"DA":"NE");
}
# | 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... |