結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー otamay6otamay6
提出日時 2020-02-14 21:56:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,184 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 180,800 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-27 19:36:41
合計ジャッジ時間 4,756 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 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,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,948 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 46 ms
6,944 KB
testcase_11 AC 42 ms
6,944 KB
testcase_12 AC 783 ms
6,940 KB
testcase_13 AC 29 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 59 ms
7,296 KB
testcase_17 WA -
testcase_18 AC 789 ms
6,940 KB
testcase_19 AC 453 ms
6,940 KB
testcase_20 AC 147 ms
13,312 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];
        cout<<ans<<endl;
    }
    else{
        vector<int> d;
        d.reserve(1344);
        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));
        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