結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー otamay6otamay6
提出日時 2020-02-14 22:28:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 886 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 177,996 KB
実行使用メモリ 13,152 KB
最終ジャッジ日時 2023-08-10 02:07:59
合計ジャッジ時間 5,740 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 51 ms
6,280 KB
testcase_11 AC 44 ms
4,380 KB
testcase_12 AC 885 ms
4,376 KB
testcase_13 AC 29 ms
4,380 KB
testcase_14 AC 57 ms
4,380 KB
testcase_15 AC 32 ms
4,376 KB
testcase_16 AC 64 ms
6,952 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 886 ms
4,380 KB
testcase_19 AC 513 ms
4,380 KB
testcase_20 AC 182 ms
13,152 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<int> 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)%K];
        cout<<ans<<endl;
    }
    else{
        vector<int> d;
        d.reserve(1344);
        for(int 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));
        int n=d.size();
        vector<int> imos(n);
        REP(i,M) for(int j=n-1;j>=0;--j){
            if(B[i]%d[j]==0){
                imos[n-j-1]++;
                break;
            }
        }
        REP(i,N) REP(j,n){
            if(A[i]%d[j]==0){
                ans+=imos[j];
            }
        }
        cout<<ans<<endl;
    }
}
0