#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
const int mod = 1e9+7;
using namespace std;
bool comp(pair<int,int>&a ,pair<int,int>&b)
{
if(a.first==b.first)
{
return a.second>b.second;
}
return a.first<b.first;
}
void solve()
{
int n;
cin>>n;
vector<string>v(n),v2(n);
map<string,string>mp;
for(int i=0;i<n;i++)
{
cin>>v[i];
mp[v[i]]="1234";
}
for(int i=0;i<n;i++)
{
cin>>v2[i];
mp[v2[i]]="1234";
}
//1234 is null value
for(int j=0;j<100;j++)
for(int i=0;i<n;i++)
{
char a,b;
a=v[i][0];
b=v2[i][0];
if(isdigit(a) && isdigit(b))
{
if(v[i]!=v2[i])
{
cout<<"NE"<<endl;
return;
}
}
else if(isdigit(a) && !isdigit(b))
{
if(mp[v2[i]]=="1234")
{
mp[v2[i]]=v[i];
v2[i]=v[i];
}
else
{
if(mp[v2[i]]!=v[i])
{
cout<<"NE"<<endl;
return;
}
else
{
v2[i]=v[i];
}
}
}
else if(isdigit(b) && !isdigit(a))
{
if(mp[v[i]]=="1234")
{
mp[v[i]]=v2[i];
v[i]=v2[i];
}
else
{
if(mp[v[i]]!=v2[i])
{
cout<<"NE"<<endl;
return;
}
else
{
v[i]=v2[i];
}
}
}
else
{
if(mp[v[i]]!="1234")
{
v[i]=mp[v[i]];
}
if(mp[v2[i]]!="1234")
{
v2[i]=mp[v2[i]];
}
}
}
for(int j=0;j<100;j++)
for(int i=0;i<n;i++)
{
v[i]=mp[v[i]];
v2[i]=mp[v2[i]];
if(v[i]!=v2[i])
{
cout<<"NE"<<endl;
return;
}
}
reverse(v.begin(),v.end());
reverse(v2.begin(),v2.end());
for(int j=0;j<100;j++)
for(int i=0;i<n;i++)
{
v[i]=mp[v[i]];
v2[i]=mp[v2[i]];
if(v[i]!=v2[i])
{
cout<<"NE"<<endl;
return;
}
}
cout<<"DA"<<endl;
}
int32_t main(){
int t=1;
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//cin>>t;
while(t--){solve();}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
444 KB |
Output is correct |
2 |
Correct |
20 ms |
432 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
10 ms |
716 KB |
Output is correct |
5 |
Correct |
65 ms |
784 KB |
Output is correct |
6 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1584 KB |
Output is correct |
2 |
Correct |
453 ms |
3072 KB |
Output is correct |
3 |
Correct |
115 ms |
4804 KB |
Output is correct |
4 |
Correct |
80 ms |
5700 KB |
Output is correct |
5 |
Execution timed out |
1096 ms |
8284 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |