結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ngtkanangtkana
提出日時 2020-04-10 20:46:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 212,628 KB
実行使用メモリ 17,040 KB
最終ジャッジ日時 2023-10-13 17:17:18
合計ジャッジ時間 4,341 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 35 ms
7,556 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 78 ms
4,624 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 27 ms
4,440 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 40 ms
8,548 KB
testcase_17 AC 12 ms
4,352 KB
testcase_18 AC 78 ms
4,584 KB
testcase_19 AC 34 ms
4,352 KB
testcase_20 AC 113 ms
17,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m,k;std::cin>>n>>m>>k;
    char c;std::cin>>c;
    std::vector<lint>a(n),b(m);
    for(lint&y:b)std::cin>>y;
    for(lint&x:a)std::cin>>x;
    lint ans=0;
    if(c=='+'){
        std::map<lint,lint>map;
        for(lint y:b)map[y%k]++;
        for(lint x:a){
            x%=k;
            ans+=map[x?k-x:0];
        }
    }else{
        std::vector<lint>divs;
        for(lint i=1;i*i<=k;i++){
            if(k%i)continue;
            divs.push_back(i);
            if(i*i!=k)divs.push_back(k/i);
        }
        std::map<lint,lint>map;
        for(lint y:b){
            map[std::gcd(k,y)]++;
        }
        for(auto[d,mu]:map){
            for(lint e:divs){
                if(d==e||d%e)continue;
                map[e]+=mu;
            }
        }
        for(lint x:a){
            ans+=map[k/std::gcd(k,x)];
        }
    }
    std::cout<<ans<<'\n';
}
0