답안 #158696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158696 2019-10-18T12:54:35 Z InfiniteJest Zamjena (COCI18_zamjena) C++14
70 / 70
198 ms 11356 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <map>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

typedef long long ll;

int n;
vector<int> nodi[110000];
string va[50001];
string vb[50001];
int val[110000];
bool flag=1;
bool vis[110000];
map<string,int> indexes;
int indtot=1;

int num(string s){
  int tot=0;
  for(int i=0;i<(int)s.length();i++){
    tot=tot*10+s[i]-48;
  }
  return tot;
}

void dfs(int k, int f){
  vis[k]=1;
  val[k]=f;
  for(int i=0;i<(int)nodi[k].size();i++){
    if(!vis[nodi[k][i]]){
      vis[nodi[k][i]]=1;
      dfs(nodi[k][i],f);
    }
  }

}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>va[i];
    if(indexes[va[i]]==0){
      indexes[va[i]]=indtot;
      indtot++;
    }
  }
  for(int i=0;i<n;i++){
    cin>>vb[i];
    if(indexes[vb[i]]==0){
      indexes[vb[i]]=indtot;
      indtot++;
    }
  }
  for(int i=0;i<n;i++){
    if(va[i][0]>='a'&&va[i][0]<='z'&&vb[i][0]>='a'&&vb[i][0]<='z'){
      nodi[indexes[va[i]]].pb(indexes[vb[i]]);
      nodi[indexes[vb[i]]].pb(indexes[va[i]]);
    }
  }
  for(int i=0;i<n;i++){
    if(va[i][0]>='0'&&va[i][0]<='9'&&(vb[i][0]<'0'||vb[i][0]>'9')){
      if(val[indexes[vb[i]]]==0){
        dfs(indexes[vb[i]],num(va[i]));
      }
      else{
        if(val[indexes[vb[i]]]!=num(va[i])){
          flag=0;
          break;
        }
      }
    }
    else if((va[i][0]<'0'||va[i][0]>'9')&&(vb[i][0]>='0'&&vb[i][0]<='9')){
      if(val[indexes[va[i]]]==0){
        dfs(indexes[va[i]],num(vb[i]));
      }
      else{
        if(val[indexes[va[i]]]!=num(vb[i])){
          flag=0;
          break;
        }
      }
    }
    else if((va[i][0]>='0'&&va[i][0]<='9')&&vb[i][0]>='0'&&vb[i][0]<='9'){
      if(num(va[i])!=num(vb[i])){
        flag=0;
        break;
      }
    }
  }
  if(flag)cout<<"DA";
  else cout<<"NE";

}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 6008 KB Output is correct
2 Correct 7 ms 6008 KB Output is correct
3 Correct 7 ms 6008 KB Output is correct
4 Correct 7 ms 6212 KB Output is correct
5 Correct 7 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6008 KB Output is correct
2 Correct 8 ms 6008 KB Output is correct
3 Correct 7 ms 6140 KB Output is correct
4 Correct 7 ms 6136 KB Output is correct
5 Correct 7 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6008 KB Output is correct
2 Correct 7 ms 6008 KB Output is correct
3 Correct 7 ms 6008 KB Output is correct
4 Correct 7 ms 6136 KB Output is correct
5 Correct 7 ms 6008 KB Output is correct
6 Correct 7 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6136 KB Output is correct
2 Correct 9 ms 6136 KB Output is correct
3 Correct 14 ms 6264 KB Output is correct
4 Correct 14 ms 6392 KB Output is correct
5 Correct 15 ms 6264 KB Output is correct
6 Correct 13 ms 6264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6776 KB Output is correct
2 Correct 63 ms 7556 KB Output is correct
3 Correct 108 ms 8940 KB Output is correct
4 Correct 126 ms 9052 KB Output is correct
5 Correct 198 ms 11356 KB Output is correct
6 Correct 152 ms 8852 KB Output is correct