Submission #621133

#TimeUsernameProblemLanguageResultExecution timeMemory
621133ElnadyZamjena (COCI18_zamjena)C++17
70 / 70
197 ms15728 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long #define all(pr1) pr1.begin(),pr1.end() #define alr(pr1) pr1.rbegin(),pr1.rend() #define CEIL(pr1, pr2) (pr1 + pr2 - 1) / pr2 #define IOS std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define RT(s) return cout<<s,0 #define sz(s) (long long)(s.size()) const long long N = 2e5 + 9, M = 1e9 + 9, MOD = 1e9 + 7, OO = 0x3f3f3f3f, MAX = 2147483647, LOO = 0x3f3f3f3f3f3f3f3f; bool isNum(char c) { if (c >= '0' && c <= '9') return 1; return 0; } int32_t main() { IOS; int n; cin >> n; vector<string> a(n), b(n); multiset <pair<string, string>> st; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; bool can = 1; map<string, int> mp; map<string, vector<string>> mp2; for (int i = 0; i < n && can; i++) { bool aa = isNum(a[i][0]); bool bb = isNum(b[i][0]); if (aa && bb) { if (a[i] != b[i]) can = 0; } else if (aa && !bb) st.insert({ a[i],b[i] }); else if (!aa && bb) st.insert({ b[i],a[i] }); else { mp2[a[i]].push_back(b[i]); mp2[b[i]].push_back(a[i]); } } while (can && sz(st)) { pair<string, string> xx = *(st.begin()); st.erase(st.begin()); int x = stoi(xx.first); string y = xx.second; if (mp.find(y) != mp.end() && mp[y] != x) can = 0; else { mp[y] = x; for (int i = sz(mp2[y]) - 1; i >= 0; i--) { string z = to_string(x); st.insert({ z, mp2[y].back() }); mp2[y].pop_back(); } } } cout << (can ? "DA\n" : "NE\n"); }
#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...