Submission #69531719


Source Code Expand

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <atcoder/all>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
using namespace atcoder;
typedef vector<int> Vec;

int lis(Vec a) {
    const int INF = 1e+9;
    int n = a.size(), i;
    Vec dp(n + 1, INF);

    dp[0] = -INF;
    rep(i, n) {
        int it = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
        dp[it] = a[i];
    }

    for (i = n; i >= 0; i--) if (dp[i] < INF) break;
    return i;
}

signed main() {
    int i, n;
    cin >> n;
    Vec p(n), c(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> c[i];

    map<int, Vec> mp;
    rep(i, n) {
        mp[c[i]].push_back(p[i]);
    }

    int ans = 0;
    for (map<int, Vec>::iterator it = mp.begin(); it != mp.end(); it++) {
        Vec vec = it->second;
        int cnt = (int)vec.size() - lis(vec);
        ans += it->first * cnt;
    }

    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Slime Swap
User startcpp
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1190 Byte
Status AC
Exec Time 196 ms
Memory 20236 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 32
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3492 KiB
00_sample_01.txt AC 1 ms 3464 KiB
01_random_00.txt AC 72 ms 10724 KiB
01_random_01.txt AC 45 ms 8420 KiB
01_random_02.txt AC 47 ms 8468 KiB
01_random_03.txt AC 30 ms 6632 KiB
01_random_04.txt AC 16 ms 4712 KiB
01_random_05.txt AC 150 ms 15016 KiB
01_random_06.txt AC 126 ms 12636 KiB
01_random_07.txt AC 158 ms 15816 KiB
01_random_08.txt AC 196 ms 20236 KiB
01_random_09.txt AC 186 ms 19028 KiB
01_random_10.txt AC 50 ms 7844 KiB
01_random_11.txt AC 18 ms 4736 KiB
01_random_12.txt AC 76 ms 8516 KiB
01_random_13.txt AC 21 ms 5036 KiB
01_random_14.txt AC 75 ms 8900 KiB
01_random_15.txt AC 83 ms 9752 KiB
01_random_16.txt AC 83 ms 9328 KiB
01_random_17.txt AC 82 ms 8756 KiB
01_random_18.txt AC 81 ms 8760 KiB
01_random_19.txt AC 81 ms 10216 KiB
01_random_20.txt AC 76 ms 11792 KiB
01_random_21.txt AC 12 ms 4420 KiB
01_random_22.txt AC 17 ms 5492 KiB
01_random_23.txt AC 49 ms 8744 KiB
01_random_24.txt AC 80 ms 12252 KiB
01_random_25.txt AC 79 ms 12528 KiB
01_random_26.txt AC 84 ms 12532 KiB
01_random_27.txt AC 72 ms 12584 KiB
01_random_28.txt AC 80 ms 12628 KiB
01_random_29.txt AC 85 ms 12508 KiB