結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー outlineoutline
提出日時 2020-03-05 17:43:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 120,248 KB
実行使用メモリ 5,040 KB
最終ジャッジ日時 2023-08-10 04:12:03
合計ジャッジ時間 2,632 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 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,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 105 ms
5,040 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 41 ms
4,420 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 25 ms
4,380 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 105 ms
4,776 KB
testcase_19 AC 37 ms
4,376 KB
testcase_20 AC 59 ms
4,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    ll k;
    char op;
    cin >> n >> m >> k >> op;
    vector<ll> b(m);
    vector<ll> a(n);
    ll res = 0;
    if(op == '+'){
        for(int i = 0; i < m; ++i){
            cin >> b[i];
            b[i] %= k;
        }
        for(int i = 0; i < n; ++i){
            cin >> a[i];
            a[i] %= k;
        }
        sort(b.begin(), b.end());
        for(int i = 0; i < n; ++i){
            res += upper_bound(b.begin(), b.end(), (k - a[i]) % k) - lower_bound(b.begin(), b.end(), (k - a[i]) % k);
        }
    }
    else{
        for(int i = 0; i < m; ++i)  cin >> b[i];
        for(int i = 0; i < n; ++i)  cin >> a[i];
        map<ll, ll> gcd_a, gcd_b;
        for(int i = 0; i < n; ++i)  ++gcd_a[gcd(a[i], k)];
        for(int i = 0; i < m; ++i)  ++gcd_b[gcd(b[i], k)];
        for(auto A : gcd_a){
            for(auto B : gcd_b){
                if(A.first * B.first % k == 0)  res += A.second * B.second;
            }
        }
    }
    cout << res << endl;
}
0