結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー otamay6otamay6
提出日時 2020-02-14 21:45:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,150 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 190,944 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-27 19:29:49
合計ジャッジ時間 6,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N,M,K;cin>>N>>M>>K;
    char op;cin>>op;
    vector<ll> A(N),B(M);
    REP(i,M) cin>>B[i];
    REP(i,N) cin>>A[i];
    ll ans=0;
    sort(All(B));
    if(op=='+'){
        map<int,int> mp;
        REP(i,M) mp[B[i]%K]++;
        REP(i,N) ans+=mp[K-A[i]%K];
        cout<<ans<<endl;
    }
    else{
        vector<int> d;
        for(ll i=1;i*i<=K;++i){
            if(K%i==0){
                d.push_back(i);
                if(i*i!=K){
                    d.push_back(K/i);
                }
            }
        }
        sort(All(d));
        map<int,ll> imos;
        REP(i,M) for(int j=d.size()-1;j>=0;--j){
            if(B[i]%d[j]==0){
                imos[K/d[j]]++;
                break;
            }
        }
        REP(i,N) REP(j,d.size()){
            if(A[i]%d[j]==0){
                ans+=imos[d[j]];
            }
        }
        cout<<ans<<endl;
    }
}
0