結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー MisterMister
提出日時 2020-08-04 04:47:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 94,216 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2023-10-12 00:24:02
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 41 ms
5,928 KB
testcase_11 AC 19 ms
4,372 KB
testcase_12 AC 99 ms
4,368 KB
testcase_13 AC 13 ms
4,372 KB
testcase_14 AC 38 ms
4,368 KB
testcase_15 AC 16 ms
4,372 KB
testcase_16 AC 42 ms
5,696 KB
testcase_17 AC 17 ms
4,368 KB
testcase_18 AC 101 ms
4,372 KB
testcase_19 AC 30 ms
4,368 KB
testcase_20 AC 129 ms
9,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>
#include <map>

using lint = long long;

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

    if (op == '+') {
        std::map<int, lint> cnt;
        while (m--) {
            int x;
            std::cin >> x;
            x %= k;

            if (!cnt.count(x)) cnt[x] = 0;
            ++cnt[x];
        }

        lint ans = 0;
        while (n--) {
            int x;
            std::cin >> x;
            x = (k - x % k) % k;
            if (cnt.count(x)) ans += cnt[x];
        }

        std::cout << ans << "\n";

    } else {
        std::map<lint, lint> acnt, bcnt;
        while (m--) {
            int x;
            std::cin >> x;
            x = std::gcd(x, k);

            if (!bcnt.count(x)) bcnt[x] = 0;
            ++bcnt[x];
        }

        while (n--) {
            int x;
            std::cin >> x;
            x = std::gcd(x, k);

            if (!acnt.count(x)) acnt[x] = 0;
            ++acnt[x];
        }

        lint ans = 0;
        for (auto [p1, c1] : acnt) {
            for (auto [p2, c2] : bcnt) {
                if (p1 * p2 % k == 0) ans += c1 * c2;
            }
        }

        std::cout << ans << "\n";
    }
}

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

    solve();

    return 0;
}
0