結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー recososorecososo
提出日時 2020-02-16 11:18:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 177,736 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-27 20:59:35
合計ジャッジ時間 7,996 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
int main(){
    ll n,m,k;cin >> n >> m >> k;
    map<ll,ll> mb;
    char c;cin >> c;
    vector<ll> b(m),a(n);
    for(int i=0;i<m;i++){
        cin >> b[i];
        mb[b[i]%k]++;
    }
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=0;
    if(c=='+'){
        for(int i=0;i<n;i++){
            ans+=mb[(k-a[i]%k)%k]++;
        }
    }
    else
    {
        vector<ll> v;
        for(int i=1;i*i<=k;i++){
            if(k%i==0){
                v.push_back(i);
                if(i*i!=k){
                    v.push_back(k/i);
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<v.size();j++){
                if(a[i]*v[j]%k==0){
                    ans+=mb[v[j]%k];
                }
            }
        }
    }
    cout << ans << endl;
}
0