답안 #1083745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083745 2024-09-04T02:12:53 Z BlueGlaucus1 Zamjena (COCI18_zamjena) C++17
28 / 70
33 ms 4176 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Incorrect 0 ms 380 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Incorrect 3 ms 860 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1372 KB Output is correct
2 Correct 22 ms 2760 KB Output is correct
3 Incorrect 33 ms 4176 KB Output isn't correct
4 Halted 0 ms 0 KB -