結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー face4face4
提出日時 2020-02-18 19:53:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,661 ms / 2,000 ms
コード長 1,190 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 89,780 KB
実行使用メモリ 13,876 KB
最終ジャッジ日時 2023-08-10 03:40:14
合計ジャッジ時間 6,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 53 ms
6,420 KB
testcase_11 AC 41 ms
4,376 KB
testcase_12 AC 1,655 ms
4,908 KB
testcase_13 AC 27 ms
4,376 KB
testcase_14 AC 57 ms
4,424 KB
testcase_15 AC 33 ms
4,376 KB
testcase_16 AC 68 ms
7,468 KB
testcase_17 AC 26 ms
4,376 KB
testcase_18 AC 1,661 ms
4,688 KB
testcase_19 AC 932 ms
4,380 KB
testcase_20 AC 226 ms
13,876 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 == '*'){
        vector<int> fact;
        for(ll i = 1; i*i <= k; i++){
            if(k%i) continue;
            fact.push_back(i);
            if(i != k/i)    fact.push_back(k/i);
        }
        vector<int> v;
        for(int j : fact){
            int tmp = 0;
            for(int i = 0; i < m; i++)  if(b[i]%j==0)   tmp++;
            v.push_back(tmp);
        }
        map<int,int> cnt;
        for(int i = 0; i < fact.size(); i++)    cnt[fact[i]] = v[i];
        for(int i = 0; i < n; i++){
            ll g = gcd(k, a[i]);
            g = k/g;
            ret += cnt[g];
        }
    }
    cout << ret << endl;
    return 0;
}
0