結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー cotton_fn_cotton_fn_
提出日時 2020-02-15 02:04:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 121,764 KB
実行使用メモリ 23,416 KB
最終ジャッジ日時 2023-08-10 03:08:27
合計ジャッジ時間 3,132 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 39 ms
4,380 KB
testcase_12 AC 153 ms
4,888 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 79 ms
10,636 KB
testcase_17 WA -
testcase_18 AC 152 ms
5,156 KB
testcase_19 AC 54 ms
4,376 KB
testcase_20 AC 219 ms
23,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

i64 gcd(i64 x, i64 y) {
    while (y > 0) {
        x %= y;
        swap(x, y);
    }
    return x;
}

int main() {
    i64 n, m, k;
    char op;
    cin >> n >> m >> k >> op;
    vector<i64> a(n), b(m);
    for (int i = 0; i < m; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) cin >> a[i];

    i64 ans = 0;
    if (op == '+') {
        map<i64, i64> ma, mb;
        for (i64 x : a) ma[x % k]++;
        for (i64 x : b) mb[x % k]++;
        for (auto p : ma) {
            i64 x, c;
            tie(x, c) = p;
            ans += mb[(k - x) % k];
        }
    } else {
        map<i64, i64> ma, mb;
        for (i64 x : a) ma[gcd(x, k)]++;
        for (i64 x : b) mb[gcd(x, k)]++;
        for (auto p : ma) {
            i64 x, c;
            tie(x, c) = p;
            for (auto p : mb) {
                i64 y, d;
                tie(y, d) = p;
                if (x * y % k == 0) {
                    ans += c * d;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0