Submission #1083745

#TimeUsernameProblemLanguageResultExecution timeMemory
1083745BlueGlaucus1Zamjena (COCI18_zamjena)C++17
28 / 70
33 ms4176 KiB
#include <iostream> #include <string> #include <map> using namespace std; int isint(string s){ if(s[0] <='9'&&s[0]>='0'){ return stoi(s); } return 0; } int final1[500005]; int final2[500005]; int main(){ int n; cin >>n; string fir[n]; string sec[n]; for(int i = 0; i <n;i++){ cin >> fir[i]; } for(int i =0; i <n;i++){ cin >> sec[i]; } map<string, int> ms; for(int i = 0; i <n;i++){ int i1 = isint(fir[i]); int i2 = isint(sec[i]); if(i1!=0&&i2!=0){ if(i1!=i2){ cout <<"NE"; return 0; } } //fir[i] is an integer else if(i1!=0){ if(ms[sec[i]]!=0){ if(ms[sec[i]]!=i1){ cout <<"NE"; return 0; } }else{ ms[sec[i]]= i1; } final1[i] =final2[i] = i1; } else if(i2!=0){ if(ms[fir[i]]!=0){ if(ms[fir[i]]!=i2){ cout <<"NE"; return 0; } }else{ ms[fir[i]]= i2; } final1[i] =final2[i] = i2; } } for(int i = n-1; i >=0;i--){ int i1 = final1[i]; int i2 = final2[i]; if(i1!=0&&i2!=0){ if(i1!=i2){ cout <<"NE"; return 0; } } //fir[i] is an integer else if(i1!=0){ if(ms[sec[i]]!=0){ if(ms[sec[i]]!=i1){ cout <<"NE"; return 0; } }else{ ms[sec[i]]= i1; } final1[i] =final2[i] = i1; } else if(i2!=0){ if(ms[fir[i]]!=0){ if(ms[fir[i]]!=i2){ cout <<"NE"; return 0; } }else{ ms[fir[i]]= i2; } final1[i] =final2[i] = i2; } } for(int i =0; i <n;i++){ if(final1[i]==0&&final2[i]==0){ if(ms[fir[i]]){ if(!ms[sec[i]]){ ms[sec[i]] = ms[fir[i]]; } } if(ms[sec[i]]){ if(!ms[fir[i]]){ ms[fir[i]] = ms[sec[i]]; } } if(ms[fir[i]]!=ms[sec[i]]){ cout <<"NE"; return 0; }else{ final1[i] = final2[i] = ms[fir[i]]; } }else if(final2[i]==0){ if(final1[i]!=ms[sec[i]]){ cout <<"NE"; return 0; }else{ final1[i] = final2[i] = ms[sec[i]]; } }else if(final1[i]==0){ if(final2[i]!=ms[fir[i]]){ cout <<"NE"; return 0; }else{ final1[i] = final2[i] = ms[fir[i]]; } } } 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...