結果

問題 No.990 N×Mマス計算(Kの倍数)
コンテスト
ユーザー rabimea
提出日時 2026-03-02 14:05:33
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,074 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,269 ms
コンパイル使用メモリ 345,500 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2026-03-02 14:05:37
合計ジャッジ時間 3,560 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i, a, b) for(int i = (a); i <= (b); i ++)
using std::cin, std::cout, std::cerr;
using ll = long long;

void Solve() {
    int n, m, k; cin >> n >> m >> k;
    char op; cin >> op;
    std::vector<int> a(n), b(m);
    rep(i, 0, m - 1) cin >> b[i];
    rep(i, 0, n - 1) cin >> a[i];

    if(op == '+') {
        std::map<int, int> map;
        for(int x : a)
            map[x % k] ++;
        ll ans = 0;
        for(int x : b)
            ans += map[(k - x % k) % k];
        cout << ans << '\n';
    } else {
        std::map<int, int> cnta, cntb;
        for(int x : a) {
            x = std::gcd(x, k);
            cnta[x] ++;
        }
        for(int x : b) {
            x = std::gcd(x, k);
            cntb[x] ++;
        }
        ll ans = 0;
        for(auto [x, cx] : cnta) for(auto[y, cy] : cntb) {
            if(ll(x) * y % k == 0)
                ans += ll(cx) * cy;
        }
        cout << ans << '\n';
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    int T = 1;
    while(T --) {
        Solve();
    }
}
0