답안 #986117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986117 2024-05-19T18:25:44 Z FIFI_cpp Zamjena (COCI18_zamjena) C++17
0 / 70
10 ms 1628 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
using ll = long long;
#define pb push_back
#define all(a) a.begin(),a.end()
//#define int int64_t
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// xcode cant include bits/stdc++.h
using namespace std;
//ifstream fin ("fenceplan.in");
//ofstream fout ("fenceplan.out");
/*   /\_/\
*   (= ._.)
*   / >  \>
*/
// encouraging cat
const ll INF = 100000000000000;
const ll mod = 1000000007;
map<string,int> m;
int parent[70001],sizes[70001];
bool num[70001] = {false};//each component allowed only 1 integer
bool d(string s ) {
   for(int i = 0; i < s.length(); i++ ) {
      if(!isdigit(s[i])) {
         return false;
      }
   }
   return true;
}
int find_parent(int x)
{
    if (parent[x] == x)
        return x;
    return parent[x] = find_parent(parent[x]);
}
void merge(int a, int b)
{
    a = find_parent(a);
    b = find_parent(b);
    if (sizes[a] < sizes[b])
        swap(a,b);
    if (a == b)
        return;
    sizes[a] += sizes[b];
    parent[b] = a;
}
int32_t main() {
    int n;
    cin >> n;
    for (int i = 0;i <= 60000;i++)
    {
        parent[i] = i;
        num[i] = false;
    }
    vector<string> f(n),s(n);
    int hs = 1;
    for (int i = 0;i < n;i++)
    {
        cin >> f[i];
    }
    for (int i = 0;i < n;i++)
    {
        cin >> s[i];
        int hsa = 0;
        int hsb = 0;
        if (d(f[i]))
        {
            hsa = stoi(f[i]);
        }
        else
        {
            if (m[f[i]] == 0)
            {
                m[f[i]] = 1000 + ++hs;
                hsa = m[f[i]];
            }
            else
                hsa = m[f[i]];
        }
        if (d(s[i]))
        {
            hsb = stoi(s[i]);
        }
        else
        {
            if (m[s[i]] == 0)
            {
                m[s[i]] = 1000 + ++hs;
                hsb = m[s[i]];
            }
            else
                hsb = m[s[i]];
            
        }
        merge(hsa,hsb);
    }
    for (int i = 0;i <= 70000;i++)
    {
        if (i <= 1000)
        {
            if (num[parent[i]])
            {
                cout << "NE" << '\n';
                return 0;
            }
            else
                num[parent[i]] = true;
        }
    }
    cout << "DA" << '\n';
    return 0;
}

Compilation message

zamjena.cpp:31:9: warning: "/*" within comment [-Wcomment]
   31 | /*   /\_/\
      |          
zamjena.cpp: In function 'bool d(std::string)':
zamjena.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for(int i = 0; i < s.length(); i++ ) {
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Incorrect 0 ms 604 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Incorrect 3 ms 860 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -