Submission #1083377

# Submission time Handle Problem Language Result Execution time Memory
1083377 2024-09-03T03:44:20 Z BlueGlaucus1 Zamjena (COCI18_zamjena) C++17
0 / 70
7 ms 1624 KB
#include <iostream>
#include <string>
#include <map>
using namespace std;

int isint(string s){
    if(s[0]-'0' >=0 &&s[0] <=9){
        return stoi(s);
    }
    return 0;
}

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;
    int final1[n];
    int final2[n];
    for(int i =0 ; i <n;i++){
        int man = 0;
        int temp1 = 0;
        int temp2 = 0;
            temp1 = isint(fir[i]); 
            temp2 = isint(sec[i]); 
        if(temp1!=0&&temp2!=0){
            if(temp1!=temp2){
                cout <<"NE";
                return 0;
            }
        }
        if(temp1!=0){
            //fir
            if(ms[sec[i]]==0){
                ms[sec[i]]=temp1;
            }else if(ms[sec[i]]!=temp1){
                cout <<"NE";
                return 0;
            }
            man = temp1;
        }
        if(temp2 !=0){
            //sec
            if(ms[fir[i]]==0){
                ms[fir[i]]=temp2;
            }else if(ms[fir[i]]!=temp2){
                cout <<"NE";
                return 0;
            }
            man = temp2;
        }
        final1[i] = final2[i] = man;

    }
    for(int i =0 ; i <n;i++){
        if(final1[i]==0){
            if(ms[fir[i]]!=0){
                final1[i] = ms[fir[i]];
            }
        }
        if(final2[i]==0){
            if(ms[sec[i]]!=0){
                final2[i] = ms[sec[i]];
            }
        }

    }
    for(int i = 0; i <n;i++){
        if(final1[i]!=0 && final2[i]!=0){
            if(final1[i]!=final2[i]){
                cout <<"NE";
                return 0;
            }
        }
        if(final1[i]!=0){
            if(ms[sec[i]]==0){
                ms[sec[i]]=final1[i];
            }
            else if(ms[sec[i]]!=final1[i]){
                cout <<"NE";
                return 0;
            }
            final2[i] = final1[i];
        }
        if(final2[i]!=0){
            if(ms[fir[i]]==0){
                ms[fir[i]]=final2[i];
            }else if(ms[fir[i]]!=final2[i]){
                cout <<"NE";
                return 0;
            }
            final1[i] = final2[i];
        }
    }
    cout <<"DA";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 2 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1624 KB Output isn't correct
2 Halted 0 ms 0 KB -