Submission #95550

#TimeUsernameProblemLanguageResultExecution timeMemory
95550kimcodingZamjena (COCI18_zamjena)C++17
70 / 70
182 ms9100 KiB
#include <cstdio> #include <iostream> #include <vector> #include <map> #include <string> using namespace std; int n; map <string, string> m; vector <string> a, b; bool is_number(string s) { return (s[0] >= '0' && s[0] <= '9'); } string find(string s) { if (!m.count(s)) return s; if (is_number(s)) return s; return m[s] = find(m[s]); } bool cmp(string x, string y){ x = find(x); y = find(y); if (x == y) return true; bool nx = is_number(x), ny = is_number(y); if (nx && ny) return x == y; else if (nx && !ny) m[y] = x; else if (!nx && ny) m[x] = y; else m[x] = y; return true; } bool solve() { for (int i = 1; i <= n; i++) if (!cmp(a[i], b[i])) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; a = b = vector <string>(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; cout << (solve() ? "DA" : "NE") << '\n'; 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...