Submission #1013615

# Submission time Handle Problem Language Result Execution time Memory
1013615 2024-07-03T17:24:28 Z Uniq0rn Zamjena (COCI18_zamjena) C++17
70 / 70
128 ms 8784 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ull unsigned long long
#define ll long long int
#define pi pair<int,int>
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)


map<string,string> pa;
string root(string s){
    return pa[s] == s ? s : pa[s] = root(pa[s]);
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;cin >> n;
    vector<string> a(n),b(n);
    for(auto &e:a){
        cin >> e;
        pa[e] = e;
    }
    for(auto &e:b){
        cin >> e;
        pa[e] = e;
    }
    for(int i=0;i<n;i++){
        string u = root(a[i]),v = root(b[i]);
        if(!isdigit(pa[u][0]) && !isdigit(pa[v][0])){
            pa[u] = v;
        }
        else if(!isdigit(pa[u][0])){
            pa[u] = v;
        }
        else if(!isdigit(pa[v][0])){
            pa[v] = u;
        }
        else if(pa[u] == pa[v]){
            pa[u] = v;
        }
        else{
            cout << "NE";
            return 0;
        }
    }
    cout << "DA";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 5 ms 968 KB Output is correct
6 Correct 4 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1684 KB Output is correct
2 Correct 40 ms 3160 KB Output is correct
3 Correct 66 ms 5204 KB Output is correct
4 Correct 58 ms 6200 KB Output is correct
5 Correct 128 ms 8784 KB Output is correct
6 Correct 125 ms 6240 KB Output is correct