結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tonegawatonegawa
提出日時 2020-09-24 19:24:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 93,368 KB
実行使用メモリ 9,632 KB
最終ジャッジ日時 2023-09-10 13:48:45
合計ジャッジ時間 2,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 40 ms
6,148 KB
testcase_11 AC 19 ms
4,384 KB
testcase_12 AC 99 ms
4,380 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 38 ms
4,384 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 41 ms
5,692 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 100 ms
4,380 KB
testcase_19 AC 30 ms
4,380 KB
testcase_20 AC 122 ms
9,632 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