結果

問題 No.1703 Much Matching
ユーザー KudeKude
提出日時 2021-10-08 23:21:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,996 bytes
コンパイル時間 4,119 ms
コンパイル使用メモリ 262,988 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-30 13:15:24
合計ジャッジ時間 7,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int op(int x, int y) { return max(x, y); }
int e() { return -1001001001; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    VI cnt1(n), cnt2(m);
    VI to1(n, -1), to2(m, -1);
    rep(_, q) {
        int a, b;
        cin >> a >> b;
        cnt1[a - 1]++;
        cnt2[b - 1]++;
        to1[a - 1] = b - 1;
        to2[b - 1] = a - 1;
    }
    vector<char> valid1(n, true), valid2(m, true);
    rep(i, n) if (cnt1[i] >= 2 || cnt1[i] == 1 && cnt2[to1[i]] >= 2) valid1[i] = false;
    rep(i, m) if (cnt2[i] >= 2 || cnt2[i] == 1 && cnt1[to2[i]] >= 2) valid2[i] = false;
    VI idx1(n), idx2(m);
    {
        int p1 = 0;
        rep(i, n) if (valid1[i]) idx1[i] = p1++;
        int p2 = 0;
        rep(i, m) if (valid2[i]) idx2[i] = p2++;
        VI nto1(p1), nto2(p2);
        rep(i, n) if (valid1[i]) nto1[i] = cnt1[i] == 0 ? -1 : idx2[to1[i]];
        rep(i, m) if (valid2[i]) nto2[i] = cnt2[i] == 0 ? -1 : idx1[to2[i]];
        n = p1, m = p2, to1 = nto1, to2 = nto2;
    }
    int base = n, add = 0;
    segtree<int, op, e> seg(n + m + 1);
    seg.set(base, 0);
    rep(i, n) {
        if (to1[i] != -1) {
            int j = to1[i];
            int x = seg.prod(base, base + j + 1) + 1;
            seg.set(base + j + 1, max(x, seg.get(base + j + 1)));
        } else {
            base--, add++;
        }
    }
    int ans = seg.prod(base, base + m + 1) + add;
    cout << ans << endl;
}
0