結果

問題 No.938 賢人を探せ
ユーザー takumi152takumi152
提出日時 2019-12-01 06:54:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,010 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 95,776 KB
実行使用メモリ 9,760 KB
最終ジャッジ日時 2023-08-21 03:28:48
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
9,756 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 16 ms
5,412 KB
testcase_09 AC 18 ms
5,424 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 24 ms
5,920 KB
testcase_12 AC 26 ms
5,660 KB
testcase_13 AC 26 ms
5,748 KB
testcase_14 AC 26 ms
5,664 KB
testcase_15 AC 26 ms
5,680 KB
testcase_16 AC 26 ms
5,700 KB
testcase_17 AC 26 ms
5,620 KB
testcase_18 AC 26 ms
5,620 KB
testcase_19 AC 26 ms
5,840 KB
testcase_20 AC 26 ms
5,676 KB
testcase_21 AC 26 ms
5,824 KB
testcase_22 AC 61 ms
9,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <queue>
#include <set>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<string> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

  set<string> cheater, clean;
  for (int i = 0; i < n; i++) {
    cheater.insert(a[i]);
    auto it1 = clean.find(a[i]);
    if (it1 != clean.end()) clean.erase(it1);
    auto it2 = cheater.find(b[i]);
    if (it2 == cheater.end()) clean.insert(b[i]);
  }

  vector<string> ans;
  set<string> checked;
  for (int i = 0; i < n; i++) {
    auto it1 = clean.find(b[i]);
    auto it2 = checked.find(b[i]);
    if (it1 != clean.end() && it2 == checked.end()) {
      ans.push_back(b[i]);
      checked.insert(b[i]);
    }
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}
0