結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー face4face4
提出日時 2020-02-18 20:38:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 90,156 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-27 21:15:13
合計ジャッジ時間 2,370 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 47 ms
6,940 KB
testcase_11 AC 36 ms
6,940 KB
testcase_12 AC 141 ms
6,944 KB
testcase_13 AC 24 ms
6,940 KB
testcase_14 AC 52 ms
6,944 KB
testcase_15 AC 30 ms
6,940 KB
testcase_16 AC 61 ms
7,680 KB
testcase_17 AC 23 ms
6,944 KB
testcase_18 AC 140 ms
6,940 KB
testcase_19 AC 49 ms
6,940 KB
testcase_20 AC 158 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;

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

int main(){
    int n, m, k;
    char op;
    cin >> n >> m >> k >> op;
    vector<ll> b(m), a(n);
    for(int i = 0; i < m; i++)  cin >> b[i];
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll ret = 0;
    if(op == '+'){
        map<int,int> cnt;
        for(int i = 0; i < m; i++)  cnt[b[i]%k]++;
        for(int i = 0; i < n; i++)  ret += cnt[(k-a[i]%k)%k];
    }else if(op == '*'){
        map<ll,ll> bcnt, acnt;
        for(int i = 0; i < m; i++){
            bcnt[gcd(b[i], k)]++;
        }
        for(int i = 0; i < n; i++){
            acnt[gcd(a[i], k)]++;
        }
        for(auto p : bcnt){
            for(auto q : acnt){
                if(p.first*q.first%k==0)    ret += p.second*q.second;
            }
        }
    }
    cout << ret << endl;
    return 0;
}
0