답안 #82261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82261 2018-10-29T16:42:05 Z Milki Zamjena (COCI18_zamjena) C++14
14 / 70
16 ms 5752 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 5e4 + 5;

unordered_map<string, string> val;
unordered_map<string, vector<string> > isti;

int n;
string a[MAXN], b[MAXN];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];

    REP(i, n){
        if(a[i][0] >= '0' && a[i][0] <= '9' && b[i][0] >= '0' && b[i][0] <= '9'){
            if(a[i] != b[i]){
                cout << "NE\n";
                return 0;
            }
        }
        else if( (a[i][0] >= '0' && a[i][0] <= '9') || (b[i][0] >= '0' && b[i][0] <= '9')){
            if(b[i][0] >= '0' && b[i][0] <= '9') swap(a[i], b[i]);

            val[a[i]] = b[i];
            for(auto it : isti[a[i]]){
                val[it] = b[i];
                for(auto it2 : isti[it])
                    val[it2] = b[i];
                isti[it].clear();
            }
            isti[a[i]].clear();
        }
        else{
            string val_a = val[a[i]], val_b = val[b[i]];
            if(val_a == "") {
                swap(val_a, val_b);
                swap(a[i], b[i]);
            }

            if(val_a == "" && val_b == ""){
                isti[a[i]].pb(b[i]);
                isti[b[i]].pb(a[i]);
            }
            else if(val_a != "" && val_b == ""){
                val[b[i]] = val_a;
                for(auto it : isti[b[i]]){
                    val[it] = val_a;
                    for(auto it2 : isti[it])
                        val[it2] = val_a;
                    isti[it].clear();
                }
                isti[b[i]].clear();
            }
            else if(val_a != val_b){
                cout << "NE\n";
                return 0;
            }
        }
    }
    cout << "DA\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 4 ms 3608 KB Output is correct
3 Correct 4 ms 3608 KB Output is correct
4 Correct 5 ms 3608 KB Output is correct
5 Correct 5 ms 3608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3608 KB Output is correct
2 Incorrect 5 ms 3608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3648 KB Output is correct
2 Correct 5 ms 3660 KB Output is correct
3 Incorrect 5 ms 3660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4044 KB Output is correct
2 Correct 5 ms 4044 KB Output is correct
3 Incorrect 8 ms 4344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 5752 KB Output isn't correct
2 Halted 0 ms 0 KB -