# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
555350 | new_acc | Zamjena (COCI18_zamjena) | C++14 | 24 ms | 3948 KiB |
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>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int fau[N],akt[N];
ll t[N],t2[N];
bool b1[N],b2[N];
unordered_map<int,int>m;
int Find(int a){
if(fau[a]==a) return a;
return fau[a]=Find(fau[a]);
}
void Union(int a,int b){
fau[Find(a)]=Find(fau[b]);
}
void solve(){
int n;
cin>>n;
int l=0;
for(int i=1;i<=n;i++){
string s;
cin>>s;
if(int(s[0])>=48 and int(s[0])<=57){
int curr=0;
for(int j=0;j<s.size();j++) curr=curr*10+(s[j])-48;
t[i]=curr;
b1[i]=1;
continue;
}
ll akth=0;
for(int j=0;j<s.size();j++){
akth=akth*p+int(s[j]);
akth%=mod;
}
if(!m[akth]) m[akth]=++l;
t[i]=akth;
}
for(int i=1;i<=n;i++){
string s;
cin>>s;
if(int(s[0])>=48 and int(s[0])<=57){
int curr=0;
for(int j=0;j<s.size();j++) curr=curr*10+(s[j])-48;
t2[i]=curr;
b2[i]=1;
continue;
}
ll akth=0;
for(int j=0;j<s.size();j++){
akth=akth*p+int(s[j]);
akth%=mod;
}
if(!m[akth]) m[akth]=++l;
t2[i]=akth;
}
for(int i=1;i<=l;i++) fau[i]=i;
for(int i=1;i<=n;i++) if(!b1[i] and !b2[i]) Union(m[t[i]],m[t2[i]]);
bool res=1;
for(int i=1;i<=n;i++){
if(!b1[i] and !b2[i]) continue;
if(b1[i] and b2[i]){
if(t[i]!=t2[i]) res=0;
continue;
}
if(b1[i]){
int pom=Find(m[t2[i]]);
if(!akt[pom]) akt[pom]=t[i];
if(akt[pom]!=t[i]) res=0;
}else{
int pom=Find(m[t[i]]);
if(!akt[pom]) akt[pom]=t2[i];
if(akt[pom]!=t2[i]) res=0;
}
}
cout<<(res?"DA":"NE")<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
while(tt--) solve();
}
Compilation message (stderr)
# | 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... |