답안 #197673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197673 2020-01-22T08:59:18 Z Nordway Zamjena (COCI18_zamjena) C++14
70 / 70
171 ms 16344 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=5e4+11;
const int M=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+9;
const double EPS=1e-9;

int n;
string a[N],b[N];
int num[3*N];
int used[3*N];

vector<int>g[3*N];

bool check(string s){
  for(int i=0;i<sz(s);i++){
    if(isalpha(s[i]))return 0;
  }
  return 1;
}

void dfs(int v,string s){
  used[v]=1;
  if(num[v]){
    if(v>n){
      if(b[v-n]!=s){
        cout<<"NE";
        exit(0);
      }
    }
    if(v<=n&&a[v]!=s){
      cout<<"NE";
      exit(0);
    }
  }
  for(int i=0;i<sz(g[v]);i++){
    int to=g[v][i];
    if(used[to])continue;
    dfs(to,s);
  }
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    num[i]=check(a[i]);
  }
  for(int i=1;i<=n;i++){
    cin>>b[i];
    num[i+n]=check(b[i]);
  }
  for(int i=1;i<=n;i++){
    if(num[i]==1&&num[i+n]==1){
      if(a[i]!=b[i]){
        cout<<"NE";
        return 0;
      }
    }
    else{
      g[i].pb(i+n);
      g[i+n].pb(i);
    }
  }
  vector<pair<string,int>>v;
  for(int i=1;i<=n;i++){
    v.pb(mp(a[i],i));
    v.pb(mp(b[i],i+n));
  }
  sort(all(v));
  int cur=n+n;
  for(int i=0;i<sz(v);i++){
    int j=i;
    while(j<sz(v)-1&&v[j].x==v[j+1].x)j++;
    if(j>i){
      cur++;
      for(int k=i;k<=j;k++){
        g[cur].pb(v[k].y);
        g[v[k].y].pb(cur);
      }
    }
    i=j;
  }
  for(int i=1;i<=n;i++){
    if(num[i]){
      dfs(i,a[i]);
    }
    if(num[i+n]){
      dfs(i+n,b[i]);
    }
  }
  cout<<"DA";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6904 KB Output is correct
2 Correct 7 ms 6904 KB Output is correct
3 Correct 8 ms 7032 KB Output is correct
4 Correct 8 ms 7004 KB Output is correct
5 Correct 8 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7004 KB Output is correct
2 Correct 8 ms 6904 KB Output is correct
3 Correct 8 ms 6904 KB Output is correct
4 Correct 8 ms 6904 KB Output is correct
5 Correct 8 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7032 KB Output is correct
2 Correct 8 ms 7032 KB Output is correct
3 Correct 8 ms 6904 KB Output is correct
4 Correct 8 ms 7032 KB Output is correct
5 Correct 8 ms 6904 KB Output is correct
6 Correct 6 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7288 KB Output is correct
2 Correct 10 ms 7160 KB Output is correct
3 Correct 17 ms 7640 KB Output is correct
4 Correct 15 ms 7640 KB Output is correct
5 Correct 16 ms 7640 KB Output is correct
6 Correct 16 ms 7732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 9228 KB Output is correct
2 Correct 64 ms 11116 KB Output is correct
3 Correct 88 ms 12644 KB Output is correct
4 Correct 117 ms 15456 KB Output is correct
5 Correct 171 ms 16344 KB Output is correct
6 Correct 159 ms 16196 KB Output is correct