Submission #237969

#TimeUsernameProblemLanguageResultExecution timeMemory
237969tc_abdZamjena (COCI18_zamjena)C++14
56 / 70
345 ms23320 KiB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define It it=se.begin();it!=se.end();it++ #define mem(dp,i) memset(dp,i,sizeof(dp)) #define all(x) begin(x),end(x) #define unmap unordered_map #define pii pair<int,int> #include <bits/stdc++.h> #define pll pair<ll,ll> #define vll vector<ll> #define vi vector<int> #define ld long double #define ll long long #define pb push_back #define sh short int #define mid (l+r)/2 #define S second #define F first #define sqr 447 using namespace std; const int inf = 1e9+9; const int mod = 1e9+7; const ld pai=acos(-1); int n; string a[50009]; string b[50009]; set < string > s,se; map < string , bool > dn; map < string , bool > done; map < string , string > val; map < string , vector < string > > v; void dfs(string node){ dn[node] = 1; if(done[node]) s.insert(val[node]); for(auto u:v[node]){ if(!dn[u]) dfs(u); } } int main(){ fast,cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; for(int i=0;i<n;i++){ int id1 = a[i][0]-'0'; int id2 = b[i][0]-'0'; if(id1 < 0 || id1 > 9){ se.insert(a[i]); if(id2 < 0 || id2 > 9){ se.insert(b[i]); v[a[i]].pb(b[i]); v[b[i]].pb(a[i]); } else{ if(done[a[i]] && val[a[i]] != b[i]){ cout<<"NE"<<endl; return 0; } done[a[i]] = 1,val[a[i]] = b[i]; } } else if(id2 < 0 || id2 > 9){ se.insert(b[i]); if(done[b[i]] && val[b[i]] != a[i]){ cout<<"NE"<<endl; return 0; } done[b[i]] = 1,val[b[i]] = a[i]; } } for(int i=0;i<n;i++){ if(!dn[a[i]]){ s.clear(),dfs(a[i]); if(s.size() > 1){ cout<<"NE"<<endl; return 0; } } if(!dn[b[i]]){ s.clear(),dfs(b[i]); if(s.size() > 1){ cout<<"NE"<<endl; return 0; } } } cout<<"DA"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...