結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー veqccveqcc
提出日時 2020-02-14 22:25:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,518 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 116,556 KB
実行使用メモリ 17,020 KB
最終ジャッジ日時 2023-08-10 02:06:42
合計ジャッジ時間 2,930 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 40 ms
7,488 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 115 ms
4,896 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 32 ms
4,464 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 51 ms
8,528 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 AC 105 ms
4,952 KB
testcase_19 AC 63 ms
4,376 KB
testcase_20 AC 167 ms
17,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }
    return ret;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    ll k;
    cin >> n >> m >> k;

    char op;
    cin >> op;

    vector <ll> a(n), b(m);
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> a[i];

    ll ans = 0;
    if (op == '+') {
        map <ll, ll> mp;
        for (int i = 0; i < n; i++) mp[a[i] % k]++;
        for (int i = 0; i < m; i++) ans += mp[(k - b[i] % k) % k];
    } else {
        map <ll, ll> mp_a, mp_b;
        for (int i = 0; i < m; i++) mp_b[gcd(k, b[i])]++;
        for (int i = 0; i < n; i++) mp_a[gcd(k, a[i])]++;

        auto div = divisor(k);

        for (ll d1 : div) {
            for (ll d2 : div) {
                if (d1 * d2 % k == 0) {
                    ans += mp_a[d1] * mp_b[d2];
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}
0