답안 #237975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237975 2020-06-09T14:28:41 Z tc_abd Zamjena (COCI18_zamjena) C++14
70 / 70
508 ms 22776 KB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define It it=se.begin();it!=se.end();it++
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define unmap unordered_map
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define sh short int
#define mid (l+r)/2
#define S second
#define F first
#define sqr 447
using namespace std;
const int inf = 1e9+9;
const int mod = 1e9+7;
const ld pai=acos(-1);
int n;
string a[50009];
string b[50009];
set < string > s,se;
map < string , bool > dn;
map < string , bool > done;
map < string , string > val;
map < string , vector < string > > v;
void dfs(string node){
    dn[node] = 1;
    if(done[node]) s.insert(val[node]);
    for(auto u:v[node]){
        if(!dn[u]) dfs(u);
    }
}
int main(){
    fast,cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++){
        int id1 = a[i][0]-'0';
        int id2 = b[i][0]-'0';
        if(id1 < 0 || id1 > 9){
            se.insert(a[i]);
            if(id2 < 0 || id2 > 9){
                se.insert(b[i]);
                v[a[i]].pb(b[i]);
                v[b[i]].pb(a[i]);
            }
            else{
                if(done[a[i]] && val[a[i]] != b[i]){
                    cout<<"NE"<<endl;
                    return 0;
                }
                done[a[i]] = 1,val[a[i]] = b[i];
            }
        }
        else if(id2 < 0 || id2 > 9){
            se.insert(b[i]);
            if(done[b[i]] && val[b[i]] != a[i]){
                cout<<"NE"<<endl;
                return 0;
            }
            done[b[i]] = 1,val[b[i]] = a[i];
        }
        else{
            if(a[i] != b[i]){
                cout<<"NE"<<endl;
                return 0;
            }
        }
    }
    for(auto it=se.begin();it!=se.end();it++){
        if(dn[*it]) continue;
        s.clear(),dfs(*it);
        if(s.size() > 1){
            cout<<"NE"<<endl;
            return 0;
        }
    }
    cout<<"DA"<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3456 KB Output is correct
2 Correct 7 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Correct 6 ms 3456 KB Output is correct
5 Correct 6 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 7 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Correct 6 ms 3456 KB Output is correct
5 Correct 6 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3456 KB Output is correct
2 Correct 7 ms 3456 KB Output is correct
3 Correct 6 ms 3456 KB Output is correct
4 Correct 6 ms 3456 KB Output is correct
5 Correct 7 ms 3456 KB Output is correct
6 Correct 7 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3840 KB Output is correct
2 Correct 8 ms 3712 KB Output is correct
3 Correct 15 ms 4352 KB Output is correct
4 Correct 13 ms 4352 KB Output is correct
5 Correct 17 ms 4480 KB Output is correct
6 Correct 12 ms 4224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 6144 KB Output is correct
2 Correct 78 ms 9696 KB Output is correct
3 Correct 170 ms 14200 KB Output is correct
4 Correct 184 ms 14464 KB Output is correct
5 Correct 508 ms 22776 KB Output is correct
6 Correct 267 ms 15096 KB Output is correct