답안 #620539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620539 2022-08-03T06:52:00 Z 3omar_ahmed Zamjena (COCI18_zamjena) C++17
14 / 70
32 ms 3208 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std ;
using namespace __gnu_pbds;

#define int long long
#define endl '\n'
#define ordered_set tree<pair < int ,int >,null_type,less<pair < int ,int >>,rb_tree_tag,tree_order_statistics_node_update>
#define all(a) a.begin() , a.end()
#define alr(a) a.rbegin() , a.rend()
bool check(string x){
    return(x[0] >= '0' && x[0] <= '9');
}
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0);

    int n ;
    cin >> n ;
    vector < string > a(n) , b(n);
    map < string , string > mp ;
    for( auto &i : a )
        cin >> i;
    for( auto &i : b )
        cin >> i;
    for( int i = 0 ; i < n ; i++ )
        mp[a[i]] = mp[b[i]] = "inf";
    for( int re = 0 ; re < 10 ; re++ ) {
        for( int i = 0 ; i < n ; i++ ){
            bool f1 = check(a[i]) , f2 = check(b[i]);
            if( f1 && f2 ){
                mp[a[i]] = a[i] , mp[b[i]] = b[i];
                if(a[i] != b[i]) return cout << "NE" , 0;
            }
            else{
                if(!f1 && !f2){
                    if(mp[a[i]] != "inf") a[i] = mp[a[i]];
                    if(mp[b[i]] != "inf") b[i] = mp[b[i]];
                }
                else {
                    if(mp[(f1 ? b[i] : a[i])] == "inf")
                        mp[(f1 ? b[i] : a[i])] = a[i] , (f1 ? b[i] : a[i]) = (f1 ? a[i] : b[i]);
                    else{
                        if(mp[(f1 ? b[i] : a[i])] != (f1 ? b[i] : b[i])) return cout << "NE" , 0;
                        else (f1 ? b[i] : a[i]) = (f1 ? a[i] : b[i]);
                    }
                }
            }
        }
    }
    for( int i = 0 ; i < n ; i++ )
        a[i] = mp[a[i]] , b[i] = mp[b[i]];
    cout << (a == b? "DA" : "NE");
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1672 KB Output is correct
2 Incorrect 14 ms 3208 KB Output isn't correct
3 Halted 0 ms 0 KB -