結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー erbowlerbowl
提出日時 2020-03-30 21:39:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,041 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 173,496 KB
実行使用メモリ 17,024 KB
最終ジャッジ日時 2023-09-05 07:53:11
合計ジャッジ時間 9,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 40 ms
7,524 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 TLE -
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 33 ms
4,380 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 51 ms
8,544 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 TLE -
testcase_19 AC 485 ms
4,376 KB
testcase_20 AC 180 ms
17,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,k;
    std::cin >> n>>m>>k;
    
    char op;
    std::cin >> op;
    vector<ll> a(n),b(m);
    
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    if(op=='+'){
        map<ll,ll> cnt;
        for (int i = 0; i < n; i++) {
            cnt[(k-a[i]%k)%k]++;
        }
        ll ans = 0;
        for (int i = 0; i < m; i++) {
            ans += cnt[b[i]%k];
        }
        std::cout << ans << std::endl;
    }else{
        ll ans = 0;
        map<ll,ll> cnt;
        for (int i = 0; i < n; i++) {
            ll g = __gcd(k,a[i]);
            cnt[k/g]++;
        }
        for (int i = 0; i < m; i++) {
            for (auto e : cnt) {
                if(b[i]%e.first==0){
                    ans+=e.second;
                }
            }
        }
        std::cout << ans << std::endl;
    }
}

0