Submission #115173

#TimeUsernameProblemLanguageResultExecution timeMemory
115173izanbfZamjena (COCI18_zamjena)C++14
14 / 70
12 ms1024 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define D(x) cerr << #x << " = " << (x) << ", " template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \ if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;} #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef unsigned int uint; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unsigned char uchar; struct secure_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template<typename T> using V = vector<T>; template<typename T, typename U> using umap = unordered_map<T,U>; template<typename T> using uset = unordered_set<T>; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T>; int parent[100000], size[100000], value[100000]; umap<string,int> idt; bool is_num(string& s) { for (char c : s) { if (not isdigit(c)) return false; } return true; } int get_id(string& s) { auto it = idt.find(s); if (it == idt.end()) { int id = idt.size(); parent[id] = id; size[id] = 1; value[id] = (is_num(s) ? stoi(s) : -1); idt[s] = id; return id; } return it->second; } int ufind(int u) { if (parent[u] != u) parent[u] = ufind(parent[u]); return parent[u]; } bool ujoin(int u, int v) { u = ufind(u), v = ufind(v); if (u != v) { if (size[u] < size[v]) swap(u, v); if (value[u] != -1 and value[v] != -1 and value[u] != value[v]) return false; parent[v] = u; size[u] += size[v]; } return true; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; V<V<int>> a(2, V<int>(n)); rep(k,0,2) { rep(i,0,n) { string s; cin >> s; a[k][i] = get_id(s); } } rep(i,0,n) { if (not ujoin(a[0][i], a[1][i])) { cout << "NE" << endl; exit(0); } } cout << "DA" << endl; }
#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...