結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー sahiyasahiya
提出日時 2020-12-21 16:14:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,115 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 119,380 KB
実行使用メモリ 18,740 KB
最終ジャッジ日時 2023-10-21 11:43:25
合計ジャッジ時間 3,790 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 28 ms
7,184 KB
testcase_11 AC 19 ms
4,784 KB
testcase_12 AC 85 ms
5,340 KB
testcase_13 AC 13 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 38 ms
8,604 KB
testcase_17 WA -
testcase_18 AC 84 ms
5,340 KB
testcase_19 AC 34 ms
4,580 KB
testcase_20 AC 135 ms
18,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const ll MOD = 1E+09 + 7; // =998244353;
const ll INF = 1E18;
const int MAX_N = 1E+05;

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

int N, M;
ll K;

ll A[MAX_N + 1], B[MAX_N + 1];

ll gcd(ll a, ll b);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M >> K;
    char op;
    cin >> op;

    for (int i = 1; i <= M; i++) {
        cin >> B[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    ll ans = 0;
    if (op == '+') {
        unordered_map<ll, ll> AM, BM;
        for (int i = 1; i <= N; i++) {
            AM[A[i] % K]++;
        }
        for (int j = 1; j <= M; j++) {
            BM[B[j] % K]++;
        }
        for (auto p : AM) {
            ans += BM[K - p.first] * p.second;
        }
    } else {
        unordered_map<ll, ll> AD, BD;
        for (int i = 1; i <= N; i++) {
            AD[gcd(A[i], K)]++;
        }
        for (int j = 1; j <= M; j++) {
            BD[gcd(B[j], K)]++;
        }
        for (auto pa : AD) {
            for (auto pb : BD) {
                ll da = pa.first, db = pb.first;
                if ((da * db) % K == 0) {
                    ans += pa.second * pb.second;
                }
            }
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

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

    return gcd(b, a % b);
}
0