답안 #986118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986118 2024-05-19T18:30:46 Z FIFI_cpp Zamjena (COCI18_zamjena) C++17
70 / 70
71 ms 8020 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++)
    {
        int ci = i;
        ci = find_parent(i);
        if (i <= 1000)
        {
            if (num[ci])
            {
                cout << "NE" << '\n';
                return 0;
            }
            else
                num[ci] = 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 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 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 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 1128 KB Output is correct
5 Correct 4 ms 1116 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1884 KB Output is correct
2 Correct 21 ms 3160 KB Output is correct
3 Correct 37 ms 4700 KB Output is correct
4 Correct 45 ms 5456 KB Output is correct
5 Correct 71 ms 8020 KB Output is correct
6 Correct 53 ms 5968 KB Output is correct