Submission #855696

# Submission time Handle Problem Language Result Execution time Memory
855696 2023-10-01T16:33:26 Z vjudge1 Zamjena (COCI18_zamjena) C++17
70 / 70
43 ms 8372 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 100000
using namespace std;
const int mod=1000000007ll;

bool isdig(string s){
    for(int i=0;i<s.size();i++){
        switch (s[i])
        {
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
            break;
            default:
            return 0;
        }
    }
    return 1;
}

unordered_map<string,string>parent;
string find(string i){
    if(parent[i]==i){
        return i;
    }
    return parent[i]=find(parent[i]);
}
void unite(string&i,string&j){
    string x=find(i),y=find(j);
    if(isdig(x)){
        parent[y]=x;
    }else{
        parent[x]=y;
    }
}

void solve(){
    int n;
    cin>>n;
    string s1[n],s2[n];
    for(int i=0;i<n;i++){
        cin>>s1[i];
        if(!parent.count(s1[i]))parent[s1[i]]=s1[i];
    }
    for(int i=0;i<n;i++){
        cin>>s2[i];
        if(!parent.count(s2[i]))parent[s2[i]]=s2[i];
    }
    for(int i=0;i<n;i++){
        unite(s1[i],s2[i]);
        //cerr<<s1[i]<<" "<<s2[i]<<"\n";
        //cerr<<find(s1[i])<<" "<<find(s2[i])<<"\n";
        //cerr<<"\n";
    }//cerr<<"\n";
    for(auto p:parent){
        if(isdig(p.first)&&find(p.first)!=p.first){
            cout<<"NE\n";
            return;
        }//else cerr<<p.first<<" "<<find(p.first)<<"\n";
    }
    cout<<"DA\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}

Compilation message

zamjena.cpp: In function 'bool isdig(std::string)':
zamjena.cpp:13:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1628 KB Output is correct
2 Correct 14 ms 2976 KB Output is correct
3 Correct 24 ms 4792 KB Output is correct
4 Correct 27 ms 5560 KB Output is correct
5 Correct 43 ms 8372 KB Output is correct
6 Correct 37 ms 5468 KB Output is correct