結果

問題 No.938 賢人を探せ
ユーザー CELICACELICA
提出日時 2020-08-11 20:31:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 182,124 KB
実行使用メモリ 6,536 KB
最終ジャッジ日時 2023-08-21 03:46:27
合計ジャッジ時間 2,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
6,464 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 9 ms
4,896 KB
testcase_09 AC 8 ms
4,692 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 11 ms
5,188 KB
testcase_12 AC 8 ms
4,596 KB
testcase_13 AC 9 ms
4,504 KB
testcase_14 AC 8 ms
4,516 KB
testcase_15 AC 8 ms
4,464 KB
testcase_16 AC 9 ms
4,692 KB
testcase_17 AC 9 ms
4,536 KB
testcase_18 AC 9 ms
4,464 KB
testcase_19 AC 9 ms
4,508 KB
testcase_20 AC 8 ms
4,464 KB
testcase_21 AC 8 ms
4,452 KB
testcase_22 AC 19 ms
6,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

typedef pair<string, int> vsi;

auto compare = [](const vsi& x, const vsi& y)
{
    return x.second > y.second;
};

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

    int n;
    cin >> n;
    vector<string> va(n);
    unordered_map<string, int> m;

    for (int i = 0; i < n; ++i)
    {
        string b;
        cin >> va[i] >> b;
        if (!m.count(b))
            m[b] = i;
    }

    priority_queue<vsi, vector<vsi>, decltype(compare)> que{ compare };

    for (int i = 0; i < n; ++i)
    {
        auto it = m.find(va[i]);
        if (it != m.end())
            m.erase(it);
    }

    for (const auto& im : m)
    {
        vsi elm{ im.first, im.second };
        que.push(elm);
    }

    while (!que.empty())
    {
        vsi elem = que.top();
        cout << elem.first << "\n";
        que.pop();
    }

    return 0;
}
0