結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ktr216ktr216
提出日時 2020-02-14 22:02:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,066 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 174,908 KB
実行使用メモリ 12,300 KB
最終ジャッジ日時 2023-08-10 01:56:51
合計ジャッジ時間 5,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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) {
            //cout << p.first << " " << p.second << endl;
            for (auto q : mb) {
                if ((p.first + q.first) % K == 0) ans += p.second * q.second;
            }
        }
    } else {
        rep(i, N) ma[A[i] / gcd(A[i], K)]++;
        rep(i, M) mb[gcd(B[i], K)]++;
        for (auto p : ma) {
            //cout << p.first << " " << p.second << endl;
            for (auto q : mb) {
                if ((p.first * q.first) % K == 0) ans += p.second * q.second;
            }
        }
    }
    cout << ans << endl;
}
0