Submission #464654

# Submission time Handle Problem Language Result Execution time Memory
464654 2021-08-13T15:16:05 Z soba Zamjena (COCI18_zamjena) C++14
70 / 70
113 ms 5124 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200000+5;

int n ,k , sol;

int fat[N];

int fin(int x)
{
    if(fat[x]!=x)
        return fat[x] = fin(fat[x]);
    return x;
}

void unio(int a , int b)
{
    int aa = fin(a);
    int bb = fin(b);
    if(aa!=bb)
    {
        fat[aa] = bb;
    }
    else sol++;
}
int toint(string s)
{
    int x=0;
    for(int i = 0 ; i <s.size(); i++)
    {
        x*=10;
        x+=(s[i]-'0');
    }
    return x;
}
int main() {

    cin>>n;
    for(int i = 0;i<N;i++)
        fat[i] = i;
    map<string,int>mp;
    string a , b;
    int x , y;
    vector<int>v1,v2;
    int flag=1;
    int cnt=1001;
    for(int i = 0;i<n;i++){
        cin>>a;
        flag=1;
        for(int j = 0 ; j  < a.size() ;j++)
        {
            if(a[j]>'9'||a[j]<'0')
                flag=0;
        }
        if(flag)
            x=toint(a);
        else
        {
            if(mp[a]==0)
            {
                mp[a]=cnt++;
            }
            x=mp[a];
        }
        v1.push_back(x);
    }
    for(int i = 0;i<n;i++){
        cin>>a;
        flag=1;
        for(int j = 0 ; j  < a.size() ;j++)
        {
            if(a[j]>'9'||a[j]<'0')
                flag=0;
        }
        if(flag)
            x=toint(a);
        else
        {
            if(mp[a]==0)
            {
                mp[a]=cnt++;
            }
            x=mp[a];
        }
        //cout << v1[i] << " " << x << "\n";
        unio(x , v1[i]);
    }
    flag=1;
    for(int i = 0 ; i<=1000 ; i++)
    {
        for(int j = 0 ; j<= 1000 ; j++)
        {
            if(i==j)continue;
            x=fin(i);
            y=fin(j);
            if(x==y)
            {
                flag=0;
                break;
            }
        }
        if(!flag)break;
    }
    if(!flag)
    {
        cout << "NE";
        return 0;
    }
    cout << "DA";
    return 0;
}

Compilation message

zamjena.cpp: In function 'int toint(std::string)':
zamjena.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0 ; i <s.size(); i++)
      |                     ~~^~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:51:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j = 0 ; j  < a.size() ;j++)
      |                         ~~~^~~~~~~~~~
zamjena.cpp:71:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = 0 ; j  < a.size() ;j++)
      |                         ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 3 ms 1072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 2 ms 972 KB Output is correct
5 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 3 ms 1084 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 3 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1100 KB Output is correct
2 Correct 4 ms 1076 KB Output is correct
3 Correct 5 ms 1272 KB Output is correct
4 Correct 6 ms 1228 KB Output is correct
5 Correct 8 ms 1284 KB Output is correct
6 Correct 5 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1652 KB Output is correct
2 Correct 35 ms 2268 KB Output is correct
3 Correct 54 ms 3208 KB Output is correct
4 Correct 69 ms 3620 KB Output is correct
5 Correct 113 ms 5124 KB Output is correct
6 Correct 90 ms 3252 KB Output is correct