답안 #158930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158930 2019-10-19T15:14:52 Z aviroop123 Zamjena (COCI18_zamjena) C++14
14 / 70
46 ms 10592 KB
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
// #define int long long
typedef long long ll;
#define fi first
#define se second
#define pii pair<int,int>
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){
    uniform_int_distribution<ll> uid(l, r);
    return uid(rng);
}

const int mod = 1e9 + 7;
int pwr(int a,ll b) {
    int ans = 1;
    while(b) {
        if(b & 1) {
            ans = ((ll)ans * a) % mod;
        }
        a = ((ll)a * a) % mod;
        b >>= 1;
    }
    return ans;
}

const int N = 1e5 + 5;
vector<int> g[N];
string a[N], b[N];

bool pos = 1;

map<string,int> m;
bool vis[N];

void dfs(int u) {
    vis[u] = 1;
    for(int v : g[u]) {
        if(!vis[v]) {
            dfs(v);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    fr(i, 1, n) {
        cin >> a[i];
        m[a[i]] = 0;
    }
    fr(i, 1, n) {
        cin >> b[i];
        m[a[i]] = 0;
    }
    int cc = 1001;
    for(auto &it : m) {
        it.se = ++cc;
    }
    fr(i, 1, n) {
        int x1 = 0, x2 = 0;
        bool dec1 = 0, dec2 = 0;
        if(a[i][0] >= '0' && a[i][0] <= '9') {
            dec1 = 1;
            x1 = stoi(a[i]);
        }
        else {
            x1 = m[a[i]];
        }
        if(b[i][0] >= '0' && b[i][0] <= '9') {
            dec2 = 1;
            x2 = stoi(b[i]);
        }
        else {
            x2 = m[b[i]];
        }
        if(dec1 && dec2 && a[i] != b[i]) {
            cout << "NE";
            return 0;
        }
        g[x1].pb(x2);
        g[x2].pb(x1);
    }
    fr(i, 1, 1000) {
        if(!vis[i]) {
            dfs(i);
        }
        else {
            cout << "NE";
            return 0;
        }
    }
    cout << "DA" << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8952 KB Output is correct
2 Correct 10 ms 8952 KB Output is correct
3 Incorrect 9 ms 8952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8952 KB Output is correct
2 Correct 9 ms 8952 KB Output is correct
3 Correct 13 ms 8952 KB Output is correct
4 Correct 12 ms 8956 KB Output is correct
5 Correct 12 ms 8952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8980 KB Output is correct
2 Incorrect 12 ms 8952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9024 KB Output is correct
2 Incorrect 13 ms 9084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 9692 KB Output is correct
2 Incorrect 46 ms 10592 KB Output isn't correct
3 Halted 0 ms 0 KB -