結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー yukarinokiyukarinoki
提出日時 2020-02-15 06:42:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 2,058 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 115,096 KB
実行使用メモリ 4,936 KB
最終ジャッジ日時 2023-08-10 03:09:07
合計ジャッジ時間 3,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 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,380 KB
testcase_10 AC 36 ms
4,376 KB
testcase_11 AC 42 ms
4,376 KB
testcase_12 AC 184 ms
4,936 KB
testcase_13 AC 28 ms
4,376 KB
testcase_14 AC 56 ms
4,380 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 45 ms
4,376 KB
testcase_17 AC 25 ms
4,376 KB
testcase_18 AC 185 ms
4,584 KB
testcase_19 AC 61 ms
4,388 KB
testcase_20 AC 99 ms
4,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

long long int gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(b==0) return 0;
    if(a%b == 0) return b;
    else return gcd(b,a%b); 
}

int main(){
    long long int n,m,k; cin >> n >> m >> k;
    string s; cin >> s;
    vector<long long int> v(m); rep(i,m) cin >> v[i];
    vector<long long int> a(n); rep(i,n) cin >> a[i];
    rep(i,m) v[i] %= k;
    rep(i,n) a[i] %= k;
    sort(all(a));
    sort(all(v));
    long long int ans = 0;
    if(s=="+") for(int i=0;i<m;i++){
        if(binary_search(all(a), (k-v[i])%k)){
            int id = lower_bound(all(a), (k-v[i])%k) - a.begin();
            int idd = upper_bound(all(a), (k-v[i])%k) - a.begin();
            ans = ans + idd - id;
        }
    }else{
        map<long long int,long long int> vm,am;
        rep(i,m){
            int gc = gcd(v[i], k);
            if(vm.count(gc)==0) vm[gc] = 1;
            else vm[gc]++;
        }
        rep(i,n){
            int gc = gcd(a[i], k);
            if(am.count(gc)==0) am[gc] = 1;
            else am[gc]++;
        }
        for(const auto& [key,val]: vm){
            for(auto [kk,vv]: am){              
                if((key*kk) % k == 0){
                  //  cout << vv << " " << val << endl;
                    ans = ans + (val*vv);
                }
            }
        }
    }      
    cout << ans << endl;

    return 0;
}
0