結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー rogi52rogi52
提出日時 2022-10-17 13:39:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 3,194 ms
コンパイル使用メモリ 209,760 KB
実行使用メモリ 17,092 KB
最終ジャッジ日時 2023-09-10 12:37:10
合計ジャッジ時間 6,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 38 ms
7,544 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 88 ms
4,860 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 32 ms
4,408 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 49 ms
8,672 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 89 ms
4,948 KB
testcase_19 AC 29 ms
4,376 KB
testcase_20 AC 167 ms
17,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll N,M,K; cin >> N >> M >> K;
    char op; cin >> op;
    vector<ll> A(N), B(M);
    rep(i,M) cin >> B[i];
    rep(i,N) cin >> A[i];

    ll ans = 0;
    if(op == '+') {
        map<ll,ll> mpB;
        rep(i,M) mpB[B[i] % K]++;
        rep(i,N) ans += mpB[(K - A[i] % K) % K];
    } else {
        map<ll,ll> mpA, mpB;
        rep(i,N) mpA[gcd(A[i], K)]++;
        rep(i,M) mpB[gcd(B[i], K)]++;
        for(auto [a, ca] : mpA) for(auto [b, cb] : mpB) {
            if((a * b) % K == 0) {
                ans += ca * cb;
            }
        }
    }
    cout << ans << endl;
}
0