結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー NOSSNOSS
提出日時 2020-02-14 22:04:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,754 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 183,688 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-27 19:40:11
合計ジャッジ時間 5,815 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 18 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 55 ms
7,808 KB
testcase_11 AC 43 ms
6,944 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};

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

ll gcd(ll p, ll q){
    if(q==0) return p;
    else return gcd(q, p%q);
}

int main(){
    ll n, m, k;
    char op;
    cin >> n >> m >> k >> 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];
    }
    if(op == '+'){
        map<ll,ll> mp;
        for(int i=0;i<m;i++){
            mp[b[i]%k]++;
        }
        ll cnt = 0;
        for(int i=0;i<n;i++){
            cnt += mp[(k-a[i]%k)%k];
        }
        cout << cnt << endl;
    }
    else{
        auto div = divisor(k);
        sort(div.begin(), div.end());
        map<ll,ll> mp;
        vector<ll> cum(div.size());
        for(auto d : div){
            mp[d] = mp.size();
        }
        for(int i=0;i<m;i++){
            ll g = gcd(b[i],k);
            cum[mp[g]]++;
        }
        for(auto d : div){
            int i = mp[d];
            ll tmp = 0;
            for(int j=1;d*j<=k;j++){
                if(mp.count(d*j)){
                    tmp += cum[mp[d*j]];
                }
            }
            cum[i] = tmp;
        }
        ll cnt = 0;
        for(int i=0;i<n;i++){
            ll g = gcd(a[i],k);
            cnt += cum[mp[k/g]];
        }
        cout << cnt << endl;
    }
    return 0;
}
0