結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,752 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 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,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 49 ms
7,680 KB
testcase_11 AC 37 ms
6,940 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;

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;
}

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;
        for(int i=0;i<m;i++){
            for(auto d : div){
                if(b[i]%d == 0){
                    mp[d]++;
                }
            }
        }
        ll cnt = 0;
        for(int i=0;i<n;i++){
            ll dmax = 1;
            for(auto d : div){
                if(a[i]%d == 0){
                    dmax = max(dmax, d);
                }
            }
            cnt += mp[k/dmax];
        }
        cout << cnt << endl;
    }
    return 0;
}
0