Submission #721260

#TimeUsernameProblemLanguageResultExecution timeMemory
721260vjudge1Zamjena (COCI18_zamjena)C++17
70 / 70
594 ms8816 KiB
#include <bits/stdc++.h>

using namespace std;

bool is_str(string s){
   if(s[0] - '0' > 9){
      return true;
   }
   return false;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n; cin >> n;

    vector<string> v1(n);
    map<string, string> mp;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> v1[i];
        if(mp[v1[i]] != "-1"){
            cnt++;
        }
        mp[v1[i]] = "-1";

    }
    vector<string> v2(n);
    for(int i = 0; i < n; i++){
        cin >> v2[i];
        if(mp[v2[i]] != "-1"){
            cnt++;
        }
        mp[v2[i]] = "-1";
    }
    bool XD = false;
    while(XD == false){
        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(!is_str(v1[i]) && !is_str(v2[i]) && v1[i] != v2[i]){
                cout << "NE" <<"\n";
                return 0;
            }
            if(!is_str(v1[i]) && is_str(v2[i])){
                cnt++;
                if(mp[v2[i]] == "-1"){
                   mp[v2[i]] = v1[i];
                }
            }
            if(is_str(v1[i]) && !is_str(v2[i])){
                cnt++;
                if(mp[v1[i]] == "-1"){
                   mp[v1[i]] = v2[i];
                }
            }
        }
        if(cnt == 0){
            XD = true;
        }
        for(int i = 0; i < n; i++){
            if(mp[v1[i]] != "-1"){
                v1[i] = mp[v1[i]];
            }
            if(mp[v2[i]] != "-1"){
                v2[i] = mp[v2[i]];
            }
        }

    }
    for(int i = 0; i < n; i++){
        if(is_str(v1[i]) && is_str(v2[i])){
            continue;
        }
        if(v1[i] != v2[i]){
            cout << "NE" <<"\n";
            return 0;
        }
    }

    cout << "DA" <<"\n";



/*
3
3 1 2
3 1 x

4
4 5 iks ipsilon
1 iks 3 iks

5
x 3 x y 3
x y 2 z 3




5
y 3 x z 4
z x y 2 4



*/

}
#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...