結果

問題 No.989 N×Mマス計算(K以上)
ユーザー MisterMister
提出日時 2020-04-19 20:25:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 95,188 KB
実行使用メモリ 8,308 KB
最終ジャッジ日時 2024-04-15 23:15:29
合計ジャッジ時間 2,465 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 37 ms
6,424 KB
testcase_11 AC 50 ms
7,448 KB
testcase_12 AC 46 ms
7,040 KB
testcase_13 AC 34 ms
6,504 KB
testcase_14 AC 66 ms
8,308 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 27 ms
5,424 KB
testcase_17 AC 34 ms
6,504 KB
testcase_18 AC 11 ms
5,376 KB
testcase_19 AC 51 ms
7,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < (int)v.size(); ++i) rev[v[i]] = i;
    return rev;
}

using lint = long long;
constexpr lint INF = 1LL << 60;

void solve() {
    int n, m;
    lint k;
    char op;
    std::cin >> n >> m >> k >> op;

    std::vector<lint> xs(m);
    for (auto& x : xs) std::cin >> x;

    auto nxs = xs;
    nxs.push_back(-INF);
    auto revx = compress(nxs);

    std::vector<lint> cnt(revx.size() + 1, 0);
    for (auto x : xs) ++cnt[revx[x]];
    for (int i = 1; i <= (int)revx.size(); ++i) cnt[i] += cnt[i - 1];

    lint ans = 0;
    while (n--) {
        lint y;
        std::cin >> y;

        lint lx;
        if (op == '+') {
            lx = k - y;
        } else {
            lx = (k + y - 1) / y;
        }

        int i = std::lower_bound(nxs.begin(), nxs.end(), lx) -
                nxs.begin();

        ans += m - cnt[i - 1];
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}
0