#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define endl "\n"
#define int long long int
#define pb push_back
#define N 105
map<string,string> mp;
map<string,int> var;
signed main(){
lalala;
int n;cin>>n;
vector<string> bir, iki;
for(int i=0;i<n;i++){
string str;cin>>str;
bir.pb(str);
if((str[0]-'0'<=9)){
mp[str]=str;
}
else{
mp[str]="&&";
}
var[str]=1;
}
int yes=1;
for(int i=0;i<n;i++){
string str;cin>>str;
iki.pb(str);
if((str[0]-'0'<=9)){
mp[str]=str;
}
else{
if(var[str]==0)mp[str]="&&";
}var[str]=1;
if(mp[iki[i]]==mp[bir[i]])continue;
if(mp[iki[i]]=="&&")mp[iki[i]]=mp[bir[i]];
if(mp[bir[i]]=="&&")mp[bir[i]]=mp[iki[i]];
if(mp[bir[i]]!=mp[iki[i]])yes=0;
}
int uwu=10;
while(uwu--){
if(yes==0)break;
for(int i=n-1;i>-1;i--){
if(mp[iki[i]]==mp[bir[i]])continue;
if(mp[iki[i]]=="&&")mp[iki[i]]=mp[bir[i]];
if(mp[bir[i]]=="&&")mp[bir[i]]=mp[iki[i]];
if(mp[bir[i]]!=mp[iki[i]]){
yes=0;
break;
}
}
for(int i=0;i<n;i++){
if(mp[iki[i]]==mp[bir[i]])continue;
if(mp[iki[i]]=="&&")mp[iki[i]]=mp[bir[i]];
if(mp[bir[i]]=="&&")mp[bir[i]]=mp[iki[i]];
if(mp[bir[i]]!=mp[iki[i]]){
yes=0;
break;
}
}
}
if(yes)cout<<"DA"<<endl;
else cout<<"NE"<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
528 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
980 KB |
Output is correct |
4 |
Correct |
5 ms |
980 KB |
Output is correct |
5 |
Correct |
23 ms |
1052 KB |
Output is correct |
6 |
Correct |
5 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2348 KB |
Output is correct |
2 |
Correct |
171 ms |
4648 KB |
Output is correct |
3 |
Correct |
74 ms |
7048 KB |
Output is correct |
4 |
Correct |
78 ms |
9188 KB |
Output is correct |
5 |
Correct |
781 ms |
12696 KB |
Output is correct |
6 |
Correct |
470 ms |
9468 KB |
Output is correct |