結果

問題 No.938 賢人を探せ
ユーザー tnakao0123tnakao0123
提出日時 2019-12-03 14:29:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 92,884 KB
実行使用メモリ 8,072 KB
最終ジャッジ日時 2023-08-21 03:33:44
合計ジャッジ時間 2,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
8,072 KB
testcase_01 AC 2 ms
4,616 KB
testcase_02 AC 2 ms
4,824 KB
testcase_03 AC 3 ms
4,608 KB
testcase_04 AC 2 ms
4,608 KB
testcase_05 AC 2 ms
4,728 KB
testcase_06 AC 3 ms
4,708 KB
testcase_07 AC 3 ms
4,764 KB
testcase_08 AC 15 ms
6,152 KB
testcase_09 AC 17 ms
6,376 KB
testcase_10 AC 3 ms
4,708 KB
testcase_11 AC 21 ms
6,412 KB
testcase_12 AC 17 ms
6,256 KB
testcase_13 AC 16 ms
6,356 KB
testcase_14 AC 17 ms
6,140 KB
testcase_15 AC 17 ms
6,248 KB
testcase_16 AC 17 ms
6,132 KB
testcase_17 AC 17 ms
6,240 KB
testcase_18 AC 17 ms
6,216 KB
testcase_19 AC 17 ms
6,232 KB
testcase_20 AC 17 ms
6,244 KB
testcase_21 AC 17 ms
6,224 KB
testcase_22 AC 26 ms
7,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 938.cc:  No.938 賢人を探せ - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20000;
const int MAX_M = MAX_N * 2;

/* typedef */

typedef map<string,int> msi;

/* global variables */

msi idmap;
string ss[MAX_M];
int as[MAX_N], bs[MAX_N];
bool es[MAX_M];

/* subroutines */

inline int allocid(char s[], int &n) {
  string t(s);
  msi::iterator mit = idmap.find(t);
  if (mit != idmap.end()) return mit->second;
  ss[n] = t;
  return (idmap[t] = n++);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int m = 0;
  for (int i = 0; i < n; i++) {
    char s0[16], s1[16];
    scanf("%s%s", s0, s1);
    int id0 = allocid(s0, m);
    int id1 = allocid(s1, m);
    as[i] = id0, bs[i] = id1;
    es[id0] = true;
  }

  for (int i = 0; i < n; i++)
    if (! es[bs[i]]) {
      puts(ss[bs[i]].c_str());
      es[bs[i]] = true;
    }
  return 0;
}
0