結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー vwxyzvwxyz
提出日時 2023-07-15 05:06:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,706 bytes
コンパイル時間 6,473 ms
コンパイル使用メモリ 138,212 KB
実行使用メモリ 14,204 KB
最終ジャッジ日時 2023-10-14 19:41:16
合計ジャッジ時間 5,712 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 23 ms
6,308 KB
testcase_11 WA -
testcase_12 AC 851 ms
4,600 KB
testcase_13 AC 12 ms
4,372 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 12 ms
4,372 KB
testcase_16 AC 29 ms
7,012 KB
testcase_17 AC 9 ms
4,368 KB
testcase_18 AC 855 ms
4,592 KB
testcase_19 AC 378 ms
4,368 KB
testcase_20 AC 69 ms
14,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<int> Divisors(int N) {
    vector<int> divisors;
    for (int i = 1; i <= N; i++) {
        if (i * i >= N) {
            break;
        } else if (N % i == 0) {
            divisors.push_back(i);
        }
    }
    int i = sqrt(N);
    if (i * i == N) {
        divisors.push_back(i);
        for (int j = divisors.size() - 1; j >= 0; j--) {
            divisors.push_back(N / divisors[j]);
        }
    } else {
        for (int j = divisors.size() - 1; j >= 0; j--) {
            divisors.push_back(N / divisors[j]);
        }
    }
    return divisors;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, K;
    cin >> N >> M >> K;
    string op;
    cin >> op;
    vector<int> B(M);
    for (int m = 0; m < M; m++) {
        cin >> B[m];
    }
    vector<int> A(N);
    for (int n = 0; n < N; n++) {
        cin >> A[n];
    }
    long long ans;
    if (op == "+") {
        unordered_map<int, int> cnt;
        for (int b : B) {
            cnt[b % K]++;
        }
        ans = 0;
        for (int a : A) {
            ans += cnt[((-a) % K+K)%K];
        }
        cout << ans << endl;
    } else {
        unordered_map<int, int> cnt;
        vector<int> D = Divisors(K);
        for (int b : B) {
            for (int d : D) {
                if (b % d == 0) {
                    cnt[d]++;
                }
            }
        }
        ans = 0;
        for (int a : A) {
            int g = __gcd(a, K);
            ans += cnt[K / g];
        }
        cout << ans << endl;
    }
    return 0;
}
0