Submission #82267

#TimeUsernameProblemLanguageResultExecution timeMemory
82267MilkiZamjena (COCI18_zamjena)C++14
70 / 70
154 ms15944 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i < b; ++i) #define REP(i, n) FOR(i, 0, n) #define _ << " " << #define sz(x) ((int) x.size()) #define pb(x) push_back(x) typedef long long ll; typedef pair<int, int> point; const int MAXN = 5e4 + 5; unordered_map<string, string> val; unordered_map<string, vector<string> > isti; int n; string a[MAXN], b[MAXN]; void postavi(string x, string value){ string realVal = val[x]; if(realVal != ""){ if(realVal == value) return; else{ cout << "NE\n"; exit(0); } } val[x] = value; for(auto it : isti[x]){ postavi(it, value); } isti[x].clear(); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; REP(i, n){ if(a[i] == b[i]) continue; if(a[i][0] >= '0' && a[i][0] <= '9' && b[i][0] >= '0' && b[i][0] <= '9'){ if(a[i] != b[i]){ cout << "NE\n"; return 0; } } else if( (a[i][0] >= '0' && a[i][0] <= '9') || (b[i][0] >= '0' && b[i][0] <= '9')){ if(a[i][0] >= '0' && a[i][0] <= '9') swap(a[i], b[i]); postavi(a[i], b[i]); } else{ string val_a = val[a[i]], val_b = val[b[i]]; //cout << val_a _ val_b <<" value\n"; if(val_a == "") { swap(val_a, val_b); swap(a[i], b[i]); } if(val_a == "" && val_b == ""){ isti[a[i]].pb(b[i]); isti[b[i]].pb(a[i]); } else if(val_a != "" && val_b == ""){ postavi(b[i], val_a); } else if(val_a != val_b){ cout << "NE\n"; return 0; } } } cout << "DA\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...