結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー erbowlerbowl
提出日時 2020-03-30 22:03:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 177,720 KB
実行使用メモリ 17,120 KB
最終ジャッジ日時 2023-09-05 08:37:00
合計ジャッジ時間 3,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 38 ms
7,480 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 111 ms
4,872 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 32 ms
4,380 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 49 ms
8,524 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 111 ms
4,872 KB
testcase_19 AC 65 ms
4,384 KB
testcase_20 AC 141 ms
17,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,k;
    std::cin >> n>>m>>k;
    
    char op;
    std::cin >> op;
    vector<ll> a(n),b(m);
    
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    if(op=='+'){
        map<ll,ll> cnt;
        for (int i = 0; i < n; i++) {
            cnt[(k-a[i]%k)%k]++;
        }
        ll ans = 0;
        for (int i = 0; i < m; i++) {
            ans += cnt[b[i]%k];
        }
        std::cout << ans << std::endl;
    }else{
        ll ans = 0;
        map<ll,ll> cnt;
        for (int i = 1; i <= sqrt(k); i++) {
            if(k%i==0){
                cnt[i]=0;
                cnt[k/i]=0;
            }
        }
        for (int i = 0; i < n; i++) {
            ll g = __gcd(k,a[i]);
            cnt[k/g]++;
        }
        map<ll,ll> sum;
        for (auto e : cnt) {
            for (auto ee : cnt) {
                if(e.first%ee.first==0) sum[e.first] += ee.second;
            }
            // std::cout << sum[e.first]<<" "<<e.first<<" "<<e.second << std::endl;
        }
        for (int i = 0; i < m; i++) {
            ans += sum[__gcd(b[i],k)];
        }
        std::cout << ans << std::endl;
    }
}

0