結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー outlineoutline
提出日時 2020-03-05 17:37:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,941 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 122,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 21:43:24
合計ジャッジ時間 2,173 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 18 ms
6,944 KB
testcase_11 AC 15 ms
6,944 KB
testcase_12 AC 92 ms
6,940 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 21 ms
6,944 KB
testcase_17 WA -
testcase_18 AC 94 ms
6,940 KB
testcase_19 AC 33 ms
6,940 KB
testcase_20 AC 53 ms
6,940 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]) - lower_bound(b.begin(), b.end(), k - a[i]);
        }
    }
    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