제출 #855696

#제출 시각아이디문제언어결과실행 시간메모리
855696vjudge1Zamjena (COCI18_zamjena)C++17
70 / 70
43 ms8372 KiB
#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();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...