#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
const int N=5e4+11;
const int M=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+9;
const double EPS=1e-9;
int n;
string a[N],b[N];
int num[3*N];
int used[3*N];
vector<int>g[3*N];
bool check(string s){
for(int i=0;i<sz(s);i++){
if(isalpha(s[i]))return 0;
}
return 1;
}
void dfs(int v,string s){
used[v]=1;
if(num[v]){
if(v>n){
if(b[v-n]!=s){
cout<<"NE";
exit(0);
}
}
if(v<=n&&a[v]!=s){
cout<<"NE";
exit(0);
}
}
for(int i=0;i<sz(g[v]);i++){
int to=g[v][i];
if(used[to])continue;
dfs(to,s);
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
num[i]=check(a[i]);
if(num[i]){
int j=0;
while(a[i][j]=='0'&&j<sz(a[i]))j++;
if(j==sz(a[i]))a[i]="0";
else{
string s="";
for(;j<sz(a[i]);j++){
s+=a[i][j];
}
a[i]=s;
}
}
}
for(int i=1;i<=n;i++){
cin>>b[i];
num[i+n]=check(b[i]);
if(num[i]){
int j=0;
while(b[i][j]=='0'&&j<sz(b[i]))j++;
if(j==sz(b[i]))b[i]="0";
else{
string s="";
for(;j<sz(b[i]);j++){
s+=b[i][j];
}
b[i]=s;
}
}
}
for(int i=1;i<=n;i++){
if(num[i]==1&&num[i+n]==1){
if(a[i]!=b[i]){
cout<<"NE";
return 0;
}
}
else{
g[i].pb(i+n);
g[i+n].pb(i);
}
}
vector<pair<string,int>>v;
for(int i=1;i<=n;i++){
v.pb(mp(a[i],i));
v.pb(mp(b[i],i+n));
}
sort(all(v));
int cur=n+n;
for(int i=0;i<sz(v);i++){
int j=i;
while(j<sz(v)-1&&v[j].x==v[j+1].x)j++;
if(j>i){
cur++;
for(int k=i;k<=j;k++){
g[cur].pb(v[k].y);
g[v[k].y].pb(cur);
}
}
i=j;
}
for(int i=1;i<=n;i++){
if(num[i]){
dfs(i,a[i]);
}
if(num[i+n]){
dfs(i+n,b[i]);
}
}
cout<<"DA";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7032 KB |
Output is correct |
2 |
Correct |
8 ms |
7032 KB |
Output is correct |
3 |
Correct |
8 ms |
7032 KB |
Output is correct |
4 |
Correct |
11 ms |
6904 KB |
Output is correct |
5 |
Correct |
8 ms |
7032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7032 KB |
Output is correct |
2 |
Correct |
7 ms |
7060 KB |
Output is correct |
3 |
Correct |
8 ms |
7032 KB |
Output is correct |
4 |
Correct |
8 ms |
7032 KB |
Output is correct |
5 |
Correct |
8 ms |
6904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6948 KB |
Output is correct |
2 |
Correct |
6 ms |
7032 KB |
Output is correct |
3 |
Correct |
10 ms |
7032 KB |
Output is correct |
4 |
Correct |
10 ms |
7032 KB |
Output is correct |
5 |
Correct |
8 ms |
7036 KB |
Output is correct |
6 |
Correct |
8 ms |
7032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7288 KB |
Output is correct |
2 |
Incorrect |
10 ms |
7160 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
9220 KB |
Output is correct |
2 |
Incorrect |
55 ms |
11216 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |