/* _____ __ __
/^--^\ | () )\ \/ /
\____/ |_()_) |__|
/ \ _____ _ __ __ ____ _ ____ ____ _____
| || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _|
\__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| |
#include <Orz/i_am_noob.h>
#include <Orz/balbit.h>
#include <Orz/nathanlee726.h>*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define int ll
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (ll)(1e9+7)
#define INF (1e18)
#define EPS (1e-6)
#ifdef LOCALMEOW
#define debug(...) do{\
cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\
" : ("#__VA_ARGS__ << ") = ";\
_OUT(__VA_ARGS__);\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
void INIT(){ ios::sync_with_stdio(false); cin.tie(0); }
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
int ans=1,now=b;
while(p){
if(p&1) ans=ans*now%MOD;
p/=2; now=now*now%MOD;
}
return ans;
}
map<string,int> mp;
struct DSU{
int p[100050];
int cnt[100050];
void init(int n,int k){
p[n]=n;
cnt[n]=k;
}
int find(int n){
if(p[n]==n) return n;
return p[n]=find(p[n]);
}
bool uni(int a,int b){
a=find(a); b=find(b);
if(a!=b){
p[a]=b;
cnt[b]+=cnt[a];
}
if(cnt[b]>1) return false;
return true;
}
}dsu;
int32_t main(){
INIT();
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//code...
int n; cin>>n;
string s;
vector<int> a(n),b(n);
int nowid=0;
For(i,0,n-1){
cin>>s;
if(!mp.count(s)){
mp[s]=nowid;
dsu.init(nowid,(s[0]<'a'));
nowid++;
}
a[i]=mp[s];
}
For(i,0,n-1){
cin>>s;
if(!mp.count(s)){
mp[s]=nowid;
dsu.init(nowid,(s[0]<'a'));
nowid++;
}
b[i]=mp[s];
}
For(i,0,n-1){
if(a[i]!=b[i]){
if(!dsu.uni(a[i],b[i])){
cout<<"NE\n";
return 0;
}
}
}
cout<<"DA\n";
//for(auto &i:mp){
// cout<<i.F<<" "<<i.S<<" "<<dsu.find(i.S)<<" "<<dsu.cnt[dsu.find(i.S)]<<"\n";
//}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
640 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1024 KB |
Output is correct |
2 |
Correct |
29 ms |
1940 KB |
Output is correct |
3 |
Correct |
50 ms |
3064 KB |
Output is correct |
4 |
Correct |
65 ms |
3448 KB |
Output is correct |
5 |
Correct |
102 ms |
5368 KB |
Output is correct |
6 |
Correct |
76 ms |
3192 KB |
Output is correct |