Submission #81719

#TimeUsernameProblemLanguageResultExecution timeMemory
81719Mouhanad_HafezZamjena (COCI18_zamjena)C++11
70 / 70
984 ms63916 KiB
#include<bits/stdc++.h> using namespace std; unordered_map <string, int> mp; unordered_map <string, vector <string> > v; string arr1[100007],arr2[100007]; bool ch (string s) { if ((int)(s[0]-'0') <= 10)return 1; return 0; } int toint (string s) { int t=1,sum=0; for (int i=s.size()-1; i>=0; i--) { sum+=(s[i]-'0')*t; t*=10; } return sum; } void dfs (string u, int x) { mp[u] = x; for (auto w : v[u]) if (!mp.count (w)) dfs (w, x); } int main() { int n; cin >> n; for (int i = 0; i < n; i++)cin>>arr1[i]; for (int i = 0; i < n; i++)cin>>arr2[i]; for (int j = 1; j <= 10; j++) { for (int i = 0; i < n; i++) { if (ch (arr1[i])) { if (ch (arr2[i])) { if (arr1[i] != arr2[i]) { cout << "NE" ; return 0; } } else { int x = toint (arr1[i]); if (!mp.count (arr2[i])) { dfs (arr2[i], x); } if (!mp.count (arr2[i])||mp[arr2[i]] == x) mp[arr2[i]] = x; else { cout << "NE" ; return 0; } } } else { if (ch (arr2[i])) { int x = toint (arr2[i]); if (!mp.count (arr1[i])) { dfs (arr1[i], x); } if (!mp.count (arr1[i])||mp[arr1[i]] == x) mp[arr1[i]] = x; else { cout << "NE" ; return 0; } } else { if (mp.count (arr1[i])) { if (mp.count (arr2[i])) { if (mp[arr1[i]] != mp[arr2[i]]) { cout << "NE" ; return 0; } } else { mp[arr2[i]] = mp[arr1[i]]; } } else if (mp.count (arr2[i])) { mp[arr1[i]] = mp[arr2[i]]; } v[arr1[i]].push_back (arr2[i]); v[arr2[i]].push_back (arr1[i]); } } } } cout << "DA" ; return 0; }
#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...