답안 #384272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384272 2021-04-01T05:05:32 Z AdiZer0 Zamjena (COCI18_zamjena) C++17
70 / 70
142 ms 17536 KB
#include <bits/stdc++.h>

#define pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)1e5 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;
 
string a[N], b[N];
bool used[N];
string val[N], ans = "-1";
vector<int> g[N];
map<string, int> was;

bool dfs(int v) { 
    used[v] = 1;
    if (ans == "-1" && ('0' <= val[v][0] && val[v][0] <= '9')) ans = val[v];
    if (ans != "-1" && ('0' <= val[v][0] && val[v][0] <= '9') && ans != val[v]) return false;
    for (int to : g[v]) { 
        if (!used[to]) { 
            if (!dfs(to)) return false;
        }
    }
    return true;
}

int main() { 
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    int pos = 0;
    for (int i = 1; i <= n; ++i) {
        int v = -1; 
        if (!was.count(a[i])) v = ++pos, was[a[i]] = pos;
        else v = was[a[i]];
        int to = -1;
        if (!was.count(b[i])) to = ++pos, was[b[i]] = pos;
        else to = was[b[i]];
        val[v] = a[i], val[to] = b[i];
        g[v].pb(to);
        g[to].pb(v);
    }
    for (int i = 1; i <= pos; ++i) { 
        if (!used[i]) { 
            ans = "-1";
            if (!dfs(i)) return cout << "NE\n", 0;
        }
    }
    cout << "DA\n";
    return 0;
}

/*
    5
    x 3 x y 3
    x y 2 z 3 
*/  
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12012 KB Output is correct
2 Correct 9 ms 12012 KB Output is correct
3 Correct 9 ms 12012 KB Output is correct
4 Correct 9 ms 12012 KB Output is correct
5 Correct 9 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12012 KB Output is correct
2 Correct 9 ms 12012 KB Output is correct
3 Correct 9 ms 12012 KB Output is correct
4 Correct 9 ms 12012 KB Output is correct
5 Correct 9 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12012 KB Output is correct
2 Correct 9 ms 12012 KB Output is correct
3 Correct 9 ms 12012 KB Output is correct
4 Correct 9 ms 12012 KB Output is correct
5 Correct 9 ms 12012 KB Output is correct
6 Correct 11 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12140 KB Output is correct
2 Correct 11 ms 12140 KB Output is correct
3 Correct 13 ms 12268 KB Output is correct
4 Correct 14 ms 12396 KB Output is correct
5 Correct 14 ms 12396 KB Output is correct
6 Correct 14 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 12780 KB Output is correct
2 Correct 45 ms 13804 KB Output is correct
3 Correct 68 ms 15084 KB Output is correct
4 Correct 103 ms 15468 KB Output is correct
5 Correct 142 ms 17536 KB Output is correct
6 Correct 97 ms 15212 KB Output is correct