제출 #1008053

#제출 시각아이디문제언어결과실행 시간메모리
1008053vicvicZamjena (COCI18_zamjena)C++11
42 / 70
23 ms3728 KiB
#include <iostream> #include <unordered_map> #include <set> #include <cstring> #include <string> using namespace std; unordered_map <int, int> umap; unordered_map <string, int> found; int v[50005], v1[50005], n, cnt=1000; int transform_nr (string s) { if (!isdigit (s[0])) { if (found[s]) { return found[s]; } else { found[s]=++cnt; return found[s]; } } else { int nr=0; for (int i=0;s[i];i++) { nr=nr*10+s[i]-'0'; } return nr; } } int main() { cin >> n; for (int i=1;i<=n;i++) { string s; cin >> s; v[i]=transform_nr (s); } for (int i=1;i<=n;i++) { string s; cin >> s; v1[i]=transform_nr (s); } for (int i=1;i<=n;i++) { if (v[i]<=1000 && v1[i]<=1000) { if (v[i]!=v1[i]) { cout << "NE"; return 0; } } if (v[i]>1000 && v1[i]<=1000) { if (umap[v[i]] && umap[v[i]]!=v1[i]) { cout << "NE"; return 0; } else { umap[v[i]]=v1[i]; } } if (v[i]<=1000 && v1[i]>1000) { if (umap[v1[i]] && umap[v1[i]]!=v[i]) { cout << "NE"; return 0; } else { umap[v1[i]]=v[i]; } } if (v[i]>1000 && v1[i]>1000) { if (!umap[v[i]] && !umap[v1[i]]) { continue; } if (umap[v[i]] && umap[v1[i]] && umap[v[i]]!=umap[v1[i]]) { cout << "NE"; return 0; } else if (!umap[v[i]]) { umap[v[i]]=umap[v1[i]]; } else if (!umap[v1[i]]) { umap[v1[i]]=umap[v[i]]; } } } for (int i=1;i<=n;i++) { if (v[i]>1000 && v1[i]>1000) { if (!umap[v1[i]] && !umap[v[i]]) { continue; } if (!umap[v[i]]) { umap[v[i]]=umap[v1[i]]; } else if (!umap[v1[i]]) { umap[v1[i]]=umap[v[i]]; } if (umap[v[i]]!=umap[v1[i]]) { cout << "NE"; return 0; } } } cout << "DA"; 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...