# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
986114 | FIFI_cpp | Zamjena (COCI18_zamjena) | C++17 | 10 ms | 1624 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[60001],sizes[60001];
bool num[60001] = {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 < 60000;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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |