Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2023-02-23-00.15.00
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define all(we) we.begin(),we.end()
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define nl '\n'
- ll ans=0;
- ll tr[100005][11],v[100005],id=0;
- void insert1(string &a)
- {
- ll now=0;
- for(ll i=0;a[i];i++)
- {
- if(tr[now][(a[i]-'0')]==0)
- {
- tr[now][(a[i]-'0')]=++id;
- }
- else if(tr[now][(a[i]-'0')] && i==a.size()-1)
- {
- ans=0;
- }
- now=tr[now][(a[i]-'0')];
- if(v[now])
- {
- ans=0;
- }
- }
- v[now]=1;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll n,m,i,j,k,l;
- cin>>n;
- string a;
- ans=1;
- id=0;
- memset(tr,0,sizeof tr);
- memset(v,0,sizeof v);
- for(i=0;i<n;i++)
- {
- cin>>a;
- insert1(a);
- }
- cout<<"Case "<<cs<<": ";
- if(ans) cout<<"YES"<<nl;
- else cout<<"NO"<<nl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement