Submission #95402

#TimeUsernameProblemLanguageResultExecution timeMemory
95402dalgerokZamjena (COCI18_zamjena)C++14
28 / 70
27 ms4588 KiB
#include<bits/stdc++.h>
using namespace std;




int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    string a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    string b[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    map < string, string > q;
    vector < pair < string, string > > e;
    for(int i = 1; i <= n; i++){
        if(isdigit(a[i][0]) && isdigit(b[i][0])){
            if(a[i] != b[i]){
                return cout << "NE", 0;
            }
        }
        else if(isdigit(a[i][0]) && !isdigit(b[i][0])){
            if(q.find(b[i]) == q.end()){
                q[b[i]] = a[i];
            }
            else if(a[i] != q[b[i]]){
                return cout << "NE", 0;
            }
        }
        else if(!isdigit(a[i][0]) && isdigit(b[i][0])){
            if(q.find(a[i]) == q.end()){
                q[a[i]] = b[i];
            }
            else if(b[i] != q[a[i]]){
                return cout << "NE", 0;
            }
        }
        else{
            if(a[i] == b[i]){
                continue;
            }
            e.push_back(make_pair(a[i], b[i]));
        }
    }
    for(auto it : e){
        string s = it.first, t = it.second;
        if(q.find(s) == q.end() && q.find(t) == q.end()){

        }
        else if(q.find(s) == q.end() && q.find(t) != q.end()){
            q[s] = q[t];
        }
        else if(q.find(s) != q.end() && q.find(t) == q.end()){
            q[t] = q[s];
        }
        else if(q[s] != q[t]){
            return cout << "NE", 0;
        }
    }
    cout << "DA";
}
#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...