답안 #1014009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014009 2024-07-04T09:33:52 Z Saladd Zamjena (COCI18_zamjena) C++14
14 / 70
6 ms 1112 KB
#include <bits/stdc++.h>
using namespace std;
map <string,int> mp;

int pa[1100000],arr[1100000],arr2[1100000],st[1100000];

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

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    int idx=1;
    cin >> n;
    for (int i=1;i<=n;i++){
        string str;
        int cnt=0;
        cin >> str;
        int len = str.size();
        //cout << mp[str] << "  ----\n";
        if(mp[str]>0){
            arr[i]=mp[str];
            continue;
        }

        for (int j=0;j<len && cnt==0;j++){
            //cout << str[j] << "\n";
            if(isalpha(str[j])){
                arr[i]=idx;
                pa[idx]=idx;
                mp[str]=idx;
                st[idx++]=1;
                cnt=1;
            }
            else{
                arr[i]=idx;
                pa[idx]=idx;
                mp[str]=idx;
                st[idx++]=0;
                cnt=1;
            }
        }
    }

    for (int i=1;i<=n;i++){
        string str;
        int cnt=0;
        cin >> str;
        int len = str.size();
        if(mp[str]>0){
            arr2[i]=mp[str];
            continue;
        }
        for (int j=0;j<len && cnt==0;j++){
            if(isalpha(str[j])){
                arr2[i]=idx;
                pa[idx]=idx;
                mp[str]=idx;
                st[idx++]=1;
                cnt=1;
            }
            else{
                arr2[i]=idx;
                pa[idx]=idx;
                mp[str]=idx;
                st[idx++]=0;
                cnt=1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        int a=arr[i];
        int b=arr2[i];

        if(root(a)==root(b)) continue;
        if(st[root(a)]==1 && st[root(b)]==1) continue;
        if(root(a)!=root(b) && (st[root(b)]==1 || st[root(a)]==1)){
            if (st[root(a)]==1) {
                pa[root(a)]=root(b);
                st[root(a)]=0;
            }
            else if(st[root(b)]==1){
                pa[root(b)]=root(a);
                st[root(b)]=0;
            }
        }
        else if(root(a)!=root(b) && (st[root(b)]==0 && st[root(a)]==0)){
            cout << "NE";
            return 0;
        }

    }
    cout << "DA";

    /*cout << '\n';
    for (int i=1;i<=n;i++){
        cout << pa[arr[i]] << " ";
    }
    cout << '\n';
    for (int i=1;i<=n;i++){
        cout << pa[arr2[i]] << " ";
    }*/
    return 0;
}
/*
4
4 5 iks ipasdasd
1 iks 3 iks

3
5 iks ipasdasd
iks 3 iks

5
x 3 x y 3
x y 2 z 3
*/
# 결과 실행 시간 메모리 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 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 1 ms 348 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 Incorrect 2 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -