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 <iostream>
#include <string>
#include <map>
using namespace std;
int isint(string s){
if(s[0]-'0' >=0 &&s[0] <=9){
return stoi(s);
}
return 0;
}
int main(){
int n; cin >>n;
string fir[n];
string sec[n];
for(int i = 0; i <n;i++){
cin >> fir[i];
}
for(int i =0; i <n;i++){
cin >> sec[i];
}
map<string, int> ms;
int final1[n];
int final2[n];
for(int i =0 ; i <n;i++){
int man = 0;
int temp1 = 0;
int temp2 = 0;
temp1 = isint(fir[i]);
temp2 = isint(sec[i]);
if(temp1!=0&&temp2!=0){
if(temp1!=temp2){
cout <<"NE";
return 0;
}
}
if(temp1!=0){
//fir
if(ms[sec[i]]==0){
ms[sec[i]]=temp1;
}else if(ms[sec[i]]!=temp1){
cout <<"NE";
return 0;
}
man = temp1;
}
if(temp2 !=0){
//sec
if(ms[fir[i]]==0){
ms[fir[i]]=temp2;
}else if(ms[fir[i]]!=temp2){
cout <<"NE";
return 0;
}
man = temp2;
}
final1[i] = final2[i] = man;
}
for(int i =0 ; i <n;i++){
if(final1[i]==0){
if(ms[fir[i]]!=0){
final1[i] = ms[fir[i]];
}
}
if(final2[i]==0){
if(ms[sec[i]]!=0){
final2[i] = ms[sec[i]];
}
}
}
for(int i = 0; i <n;i++){
if(final1[i]!=0 && final2[i]!=0){
if(final1[i]!=final2[i]){
cout <<"NE";
return 0;
}
}
if(final1[i]!=0){
if(ms[sec[i]]==0){
ms[sec[i]]=final1[i];
}
else if(ms[sec[i]]!=final1[i]){
cout <<"NE";
return 0;
}
final2[i] = final1[i];
}
if(final2[i]!=0){
if(ms[fir[i]]==0){
ms[fir[i]]=final2[i];
}else if(ms[fir[i]]!=final2[i]){
cout <<"NE";
return 0;
}
final1[i] = final2[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... |