Submission #245838

#TimeUsernameProblemLanguageResultExecution timeMemory
245838alradZamjena (COCI18_zamjena)C++17
28 / 70
10 ms1536 KiB
#include <bits/stdc++.h> using namespace std; #define N (int)100 + 2 #define all(x) x.begin(), x.end() bool isNum(string x) { bool ok = true; for (char c : x) { int code = int(c - '0'); ok &= (0 <= code && code <= 9); } return ok; } int strToNum(string x) { int res = 0 , base = 1; reverse(all(x)); for (char c : x) { int dig = int(c - '0'); res += (dig * base); base *= 10; } return res; } int main() { #ifdef judge ifstream cin("input.txt"); ofstream cout("output.txt"); #endif // judge ios_base :: sync_with_stdio(0); cin.tie(0) , cout.tie(0); int n; cin >> n; unordered_map<string , int> vars; vector<string> a(n) , b(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (!isNum(a[i])) { vars[a[i]] = -1; } } for (int i = 0; i < n; i++) { cin >> b[i]; if (!isNum(b[i])) { vars[b[i]] = -1; } } vector<int> bad; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { continue; } bool isNumA = isNum(a[i]) , isNumB = isNum(b[i]); if (isNumA && isNumB) { cout << "NE" << '\n'; return 0; } if (!isNumA && !isNumB) { bad.push_back(i); continue; } if (isNumA && !isNumB) { if (vars[b[i]] == -1) { vars[b[i]] = strToNum(a[i]); } else { if (strToNum(a[i]) != vars[b[i]]) { cout << "NE" << '\n'; return 0; } } } if (!isNumA && isNumB) { if (vars[a[i]] == -1) { vars[a[i]] = strToNum(b[i]); } else { if (strToNum(b[i]) != vars[a[i]]) { cout << "NE" << '\n'; return 0; } } } } for (int pos : bad) { if (vars[a[pos]] == -1 || vars[b[pos]] == -1) { continue; } if (vars[a[pos]] != vars[b[pos]]) { cout << "NE" << '\n'; return 0; } } cout << "DA" << '\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...