Submission #86832

#TimeUsernameProblemLanguageResultExecution timeMemory
86832jovitreZamjena (COCI18_zamjena)C++14
42 / 70
70 ms6720 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 50005 #define MAXSZ 2050 #define INF 999999999 #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef vector <ll> vi; int arr1[MAXN], arr2[MAXN]; string sArr1[MAXN], sArr2[MAXN]; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; map <string, int> mapa; string in; int aux; bool isNum; for(int i = 1; i <= n; i++){ cin >> in; isNum = true; if(in.size() <= 4){ for(auto c : in){ aux = c - '0'; if(aux < 0 or aux > 9){ isNum = false; break; } } } else isNum = false; if(isNum){ arr1[i] = stoi(in); sArr1[i] = ""; } else { arr1[i] = -1; sArr1[i] = in; } } for(int i = 1; i <= n; i++){ cin >> in; isNum = true; if(in.size() <= 4){ for(auto c : in){ aux = c - '0'; if(aux < 0 or aux > 9){ isNum = false; break; } } } else isNum = false; if(isNum){ arr2[i] = stoi(in); sArr2[i] = ""; } else { arr2[i] = -1; sArr2[i] = in; } } bool ok = true; for(int i = 1; i <= n && ok; i++){ if(arr1[i] != -1){ if(arr2[i] != -1 && arr2[i] != arr1[i]) ok = false; else if(arr2[i] == -1){ if(!mapa[sArr2[i]]) mapa[sArr2[i]] = arr1[i]; else if(mapa[sArr2[i]] != arr1[i]) ok = false; } } else { if(arr2[i] == -1){ if(!mapa[sArr1[i]] && !mapa[sArr2[i]]) continue; if(mapa[sArr1[i]] && !mapa[sArr2[i]]) mapa[sArr2[i]] = mapa[sArr1[i]]; else if(!mapa[sArr1[i]] && mapa[sArr2[i]]) mapa[sArr1[i]] = mapa[sArr2[i]]; else if(mapa[sArr1[i]] != mapa[sArr2[i]]) ok = false; } else if(arr2[i] != -1){ if(!mapa[sArr1[i]]) mapa[sArr1[i]] = arr2[i]; else if(mapa[sArr1[i]] != arr2[i]) ok = false; } } } for(int i = 1; i <= n && ok; i++){ if(arr1[i] != -1){ if(arr2[i] != -1 && arr2[i] != arr1[i]) ok = false; else if(arr2[i] == -1){ if(!mapa[sArr2[i]]) mapa[sArr2[i]] = arr1[i]; else if(mapa[sArr2[i]] != arr1[i]) ok = false; } } else { if(arr2[i] == -1){ if(!mapa[sArr1[i]] && !mapa[sArr2[i]]) continue; if(mapa[sArr1[i]] && !mapa[sArr2[i]]) mapa[sArr2[i]] = mapa[sArr1[i]]; else if(!mapa[sArr1[i]] && mapa[sArr2[i]]) mapa[sArr1[i]] = mapa[sArr2[i]]; else if(mapa[sArr1[i]] != mapa[sArr2[i]]) ok = false; } else if(arr2[i] != -1){ if(!mapa[sArr1[i]]) mapa[sArr1[i]] = arr2[i]; else if(mapa[sArr1[i]] != arr2[i]) ok = false; } } } cout << (ok ? "DA" : "NE") << endl; 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...