답안 #89820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89820 2018-12-18T13:50:26 Z tpoppo Zamjena (COCI18_zamjena) C++14
14 / 70
61 ms 2580 KB
#include <bits/stdc++.h>

using namespace std;
using ll= long long;

void NE(){
    cout<<"NE";
    exit(0);
}

void DA(){
    cout<<"DA";
    exit(0);
}

vector<string> a,b;
map<string,string> parent;
map<string,int> value;

string find(string a){
    if(parent[a] == a) return a;
    return parent[a] = find(parent[a]);
}

void merge(string a,string b){
    a = find(a);
    b = find(b);
    if(value[a] == -1e9 || value[b] == -1e9 || value[a] == value[b]){
        parent[b] = a;
    }else{
        NE();
    }
}


int main() {
    ll n;
    ll sn = 0;
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    a.resize(n);
    b.resize(n);
    for(auto&el:a){
        cin>>el;
        value[el] = -1e9;
        parent[el] = el;
    }
    for(auto&el:b){
        cin>>el;
        value[el] = -1e9;
        parent[el] = el;
    }
    for(int i=0;i<n;i++){
        if(isdigit(a[i][0]) && isdigit(b[i][0])){
            if(a[i] != b[i]){
                NE();
            }
        }else if(isdigit(a[i][0]) || isdigit(b[i][0])){
            if(isdigit(a[i][0])) swap(a[i],b[i]);
            int c = stoi(b[i]);
            if(value[a[i]] != c && value[a[i]] != -1e9){
                NE();
            }
            value[a[i]] = c;
        }else{
            merge(a[i],b[i]);
        }
    }

    DA();
}

Compilation message

zamjena.cpp: In function 'int main()':
zamjena.cpp:38:8: warning: unused variable 'sn' [-Wunused-variable]
     ll sn = 0;
        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 584 KB Output is correct
2 Incorrect 2 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
4 Incorrect 2 ms 648 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 828 KB Output is correct
2 Correct 5 ms 836 KB Output is correct
3 Incorrect 13 ms 1260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 2580 KB Output isn't correct
2 Halted 0 ms 0 KB -