Submission #561551

# Submission time Handle Problem Language Result Execution time Memory
561551 2022-05-13T06:22:45 Z AGE Zamjena (COCI18_zamjena) C++14
70 / 70
596 ms 12484 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()
      | ^~~~
# Verdict Execution time Memory 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 2 ms 4052 KB Output is correct
5 Correct 2 ms 4052 KB Output is correct
# Verdict Execution time Memory 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 3 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4052 KB Output is correct
2 Correct 3 ms 4052 KB Output is correct
3 Correct 2 ms 4008 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 3 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4124 KB Output is correct
2 Correct 6 ms 4052 KB Output is correct
3 Correct 18 ms 4456 KB Output is correct
4 Correct 20 ms 4564 KB Output is correct
5 Correct 19 ms 4556 KB Output is correct
6 Correct 15 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 5148 KB Output is correct
2 Correct 117 ms 6552 KB Output is correct
3 Correct 250 ms 8468 KB Output is correct
4 Correct 249 ms 9028 KB Output is correct
5 Correct 596 ms 12484 KB Output is correct
6 Correct 330 ms 7884 KB Output is correct