답안 #639886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639886 2022-09-12T15:50:18 Z Vladth11 Zamjena (COCI18_zamjena) C++14
0 / 70
12 ms 13852 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 100001;
const ll VMAX = 101;
const ll INF = 2e9;
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll base = 117;
const ll nr_of_bits = 24;
const ll inv2 = 500000004;

map <string, int> mp;

bool isNumar[NMAX];
string a[NMAX], b[NMAX];

int cnt = 0;
int parent[NMAX];
int cati[NMAX];
int numere[NMAX];

int root(int x){
    if(parent[x] == x)
        return x;
    return parent[x] = root(parent[x]);
}

void merge(int a, int b){
    a = root(a);
    b = root(b);
    if(cati[a] < cati[b]) swap(a, b);
    cati[a] += cati[b];
    numere[a] += numere[b];
    parent[b] = a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i;
    cin >> n;
    for(i = 1; i <= n; i++){
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()){
            mp[s] = ++cnt;
        }
        if('0' <= s[i] && s[i] <= '9'){
            isNumar[mp[s]] = 1;
        }
        a[i] = s;
    }
    for(i = 1; i <= n; i++){
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()){
            mp[s] = ++cnt;
        }
        if('0' <= s[i] && s[i] <= '9'){
            isNumar[mp[s]] = 1;
        }
        b[i] = s;
    }
    for(i = 1; i <= cnt; i++){
        parent[i] = i;
        cati[i] = 1;
        numere[i] = isNumar[i];
    }
    for(i = 1; i <= n; i++){
        merge(mp[a[i]], mp[b[i]]);
    }
    int ok = 1;
    for(i = 1; i <= cnt; i++){
        if(numere[i] > 1){
            ok = 0;
        }
    }
    if(ok) cout << "DA";
    else cout << "NE";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6612 KB Output is correct
2 Incorrect 3 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 4 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 6484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 6612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 13852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -