답안 #560175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560175 2022-05-11T06:53:21 Z AGE Zamjena (COCI18_zamjena) C++14
70 / 70
639 ms 12936 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int long long
using namespace std;
const int N=6e4,M=2e3+10,mod=100000000000031;
vector<int>v;

long long  summ(long long  x,long long  y){
    return ((x%mod)+(y%mod))%mod;
}

long long  mult(long long  x,long long  y){
    return ((x%mod)*(y%mod))%mod;
}
string a[N],b[N];
map< string ,string > p;
map<string,int>sz;

string root(string i)
{
    if(p[i]!=p[p[i]])
        p[i]=root(p[i]);

    return p[i];
}
void onion(string x,string y){

    x=root(x);
    y=root(y);
    if(x==y)
        return ;

    if(sz[x]<sz[y])
        swap(x,y);

    p[y]=x;
    sz[x]+=sz[y];

}

bool okk(string s){
    return (s[0]>='a'&&s[0]<='z');
}


main()
{

    int n;
    cin>>n;

    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
        cin>>b[i];

    for(int i=0;i<n;i++)
        p[a[i]]=a[i],p[b[i]]=b[i],sz[a[i]]=0,sz[b[i]]=0;

    int ok=0;

    for(int i=0;i<n;i++)
        if(okk(a[i])&&okk(b[i])){
            onion(a[i],b[i]);
        }

    for(int i=0;i<n;i++){

        if(!okk(a[i]))
            sz[a[i]]=100001;

        if(!okk(b[i]))
            sz[b[i]]=100001;

    }

    for(int i=0;i<n;i++){

        if(!okk(a[i])&&okk(b[i]))
            onion(b[i],a[i]);

        else if(okk(a[i])&&!okk(b[i]))
            onion(b[i],a[i]);

    }


    for(int i=0;i<n;i++){

        if(okk(a[i])){

            string x=root(a[i]);
            if(!okk(x))
                a[i]=x;
            else a[i]="1";

        }

        if(okk(b[i])){

            string x=root(b[i]);
            if(!okk(x))
                b[i]=x;
            else b[i]="1";

        }

    }

    for(int i=0;i<n;i++)
        if(a[i]!=b[i])
            ok=1;


    if(ok==1)
        cout<<"NE"<<endl;

    else cout<<"DA"<<endl;

    return 0;

}
/*
4
4 5 iks ipsilon
1 iks 3 iks

5
x 3 x y 3
x y 2 z 3

*/

Compilation message

zamjena.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4052 KB Output is correct
2 Correct 2 ms 4052 KB Output is correct
3 Correct 2 ms 4052 KB Output is correct
4 Correct 4 ms 3976 KB Output is correct
5 Correct 3 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4052 KB Output is correct
2 Correct 2 ms 4052 KB Output is correct
3 Correct 3 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 2 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4052 KB Output is correct
2 Correct 2 ms 4052 KB Output is correct
3 Correct 3 ms 4052 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 2 ms 4052 KB Output is correct
6 Correct 2 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4180 KB Output is correct
2 Correct 7 ms 4068 KB Output is correct
3 Correct 28 ms 4456 KB Output is correct
4 Correct 31 ms 4540 KB Output is correct
5 Correct 17 ms 4560 KB Output is correct
6 Correct 19 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 5140 KB Output is correct
2 Correct 147 ms 6624 KB Output is correct
3 Correct 351 ms 8824 KB Output is correct
4 Correct 313 ms 9356 KB Output is correct
5 Correct 639 ms 12936 KB Output is correct
6 Correct 407 ms 8316 KB Output is correct