Submission #95403

# Submission time Handle Problem Language Result Execution time Memory
95403 2019-01-31T15:21:47 Z dalgerok Zamjena (COCI18_zamjena) C++14
70 / 70
176 ms 7708 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e6 + 5;


int sz, p[N], cnt[N];
map < string, int > q;

int dsu_get(int v){
    return p[v] ? p[v] = dsu_get(p[v]) : v;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int sz = 0;
    string a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(q.find(a[i]) == q.end()){
            q[a[i]] = ++sz;
        }
    }
    string b[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> b[i];
        if(q.find(b[i]) == q.end()){
            q[b[i]] = ++sz;
        }
        if(dsu_get(q[a[i]]) != dsu_get(q[b[i]])){
            p[dsu_get(q[a[i]])] = dsu_get(q[b[i]]);
        }
    }
    for(auto it : q){
        if(isdigit(it.first[0])){
            cnt[dsu_get(it.second)] += 1;
        }
    }
    for(int i = 1; i <= sz; i++){
        if(cnt[i] > 1){
            return cout << "NE", 0;
        }
    }
    cout << "DA";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 452 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 7 ms 732 KB Output is correct
4 Correct 7 ms 760 KB Output is correct
5 Correct 7 ms 760 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1528 KB Output is correct
2 Correct 38 ms 2944 KB Output is correct
3 Correct 78 ms 4344 KB Output is correct
4 Correct 112 ms 5500 KB Output is correct
5 Correct 176 ms 7708 KB Output is correct
6 Correct 99 ms 5632 KB Output is correct