結果

問題 No.1194 Replace
ユーザー tomatoma
提出日時 2020-08-22 17:40:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,213 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 212,816 KB
実行使用メモリ 967,040 KB
最終ジャッジ日時 2024-04-23 11:31:07
合計ジャッジ時間 9,282 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    ll N, M;
    cin >> N >> M;
    set<ll> vals;
    map<ll, vector<ll>> rev;
    rep(i, M) {
        ll B, C;
        cin >> B >> C;
        vals.insert(C);
        rev[C].push_back(B);
    }
    map<ll, ll> id2mp;
    REP(val, 1, N + 1)id2mp[val] = val;
    {
        auto itr = vals.end();
        do {
            --itr;
            for (auto next : rev[*itr]) {
                id2mp[next] = max(id2mp[next], id2mp[*itr]);
            }
        } while (itr != vals.begin());
    }

    ll res = 0;
    REP(i, 1, N + 1) {
        res += id2mp.find(i) == id2mp.end() ? i : id2mp.at(i);
    }
    cout << res << endl;
    return 0;
}
0