結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ktr216ktr216
提出日時 2020-02-14 22:05:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 879 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 175,088 KB
実行使用メモリ 23,264 KB
最終ジャッジ日時 2023-08-10 01:58:46
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 49 ms
8,704 KB
testcase_11 AC 48 ms
6,040 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 50 ms
4,380 KB
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 68 ms
10,664 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 185 ms
23,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    ll N, M, K;
    char op;
    cin >> N >> M >> K >> op;
    vector<ll> A(N), B(M);
    rep(i, M) {
        cin >> B[i];
    }
    rep(i, N) {
        cin >> A[i];
    }
    map<ll, ll> ma, mb;
    ll ans = 0;
    if (op == '+') {
        rep(i, N) ma[A[i] % K]++;
        rep(i, M) mb[B[i] % K]++;
        for (auto p : ma) {
            ans += p.second * mb[(K - p.first) % K];
        }
    } else {
        rep(i, N) ma[A[i] / gcd(A[i], K)]++;
        rep(i, M) mb[gcd(B[i], K)]++;
        for (auto p : ma) {
            for (auto q : mb) {
                if ((p.first * q.first) % K == 0) ans += p.second * q.second;
            }
        }
    }
    cout << ans << endl;
}
0