結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ngtkana
提出日時 2020-04-10 20:39:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,008 bytes
コンパイル時間 2,929 ms
コンパイル使用メモリ 209,332 KB
最終ジャッジ日時 2025-01-09 15:47:57
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

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::set<lint>set;
        for(lint i=1;i*i<=k;i++){
            if(k%i)continue;
            set.insert(i);
            if(i*i!=k)set.insert(k/i);
        }
        std::map<lint,lint>map;
        for(lint y:b){
            for(lint d:set){
                if(!(y%d))map[d]++;
            }
        }
        for(lint x:a){
            ans+=map[k/std::gcd(k,x)];
        }
    }
    std::cout<<ans<<'\n';
}
0