結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 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 50 ms
6,944 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 24 ms
6,944 KB
testcase_14 AC 51 ms
6,940 KB
testcase_15 AC 30 ms
6,940 KB
testcase_16 AC 58 ms
7,680 KB
testcase_17 AC 23 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 162 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    return b==0 ? a : gcd(b, a%b);
}

int main(){
    int n, m, k;
    char op;
    cin >> n >> m >> k >> op;
    vector<ll> b(m), a(n);
    for(int i = 0; i < m; i++)  cin >> b[i];
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll ret = 0;
    if(op == '+'){
        map<int,int> cnt;
        for(int i = 0; i < m; i++)  cnt[b[i]%k]++;
        for(int i = 0; i < n; i++)  ret += cnt[(k-a[i]%k)%k];
    }else if(op == '*'){
        map<int,int> bcnt, acnt;
        for(int i = 0; i < m; i++){
            bcnt[gcd(b[i], k)]++;
        }
        for(int i = 0; i < n; i++){
            acnt[gcd(a[i], k)]++;
        }
        for(auto p : bcnt){
            for(auto q : acnt){
                if(p.first*q.first%k==0)    ret += p.second*q.second;
            }
        }
    }
    cout << ret << endl;
    return 0;
}
0