結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー xxxxxx
提出日時 2020-03-06 00:26:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 3,195 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 180,384 KB
実行使用メモリ 4,944 KB
最終ジャッジ日時 2023-08-10 04:13:33
合計ジャッジ時間 3,621 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,380 KB
testcase_04 AC 1 ms
4,380 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 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 23 ms
4,376 KB
testcase_11 AC 19 ms
4,384 KB
testcase_12 AC 108 ms
4,944 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 31 ms
4,408 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 27 ms
4,384 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 111 ms
4,828 KB
testcase_19 AC 38 ms
4,380 KB
testcase_20 AC 55 ms
4,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
int lcm(int x, int y) { return x/gcd(x, y)*y; }
int mod_pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % MOD; } x = x * x % MOD; y >>= 1; } return res; }
int comb(int n, int k) { k = min(k, n - k); int nnn = 1; for (int i = n - k + 1; i <= n; i++) { nnn *= i; nnn %= MOD; } int kkk = 1; for (int i = 1; i <= k; i++) { kkk *= i; kkk %= MOD; } return (nnn * mod_pow(kkk, MOD - 2)) % MOD; }
int to_int(string s) { int n = s.size(); int ans = 0; for (int i = 0; i < n; i++) { ans = ((ans * 10) + (s[i] - '0')) % MOD; } return ans; }
int DisitSum(int x){ int ret=0; while(x){ ret++;x/=10;} return ret; }
bool is_prime(int n) { for(int i = 2; i*i <= n; i++) { if (n % i == 0) return false; } return n != 1; }
int extgcd(int a, int b, int& x, int& y) { // ax+by = gcd(a,b) >> gcd(a,b)
    int d = a;
    if(d != 0) { d = extgcd(b, a%b, y, x); y -= (a/b)*x; }
    else { x = 1, y = 0; }
    return 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    int k;
    cin>>k;
    char x;
    cin>>x;
    vec b(m);
    vec a(n);
    rep(i,m) cin>>b[i];
    rep(i,n) cin>>a[i];
    ll cnt=0;
    if(x=='+'){
        
        rep(i,m) b[i]%=k;
        rep(i,n) a[i]%=k;
        sort(all(a));sort(all(b));
        rep(i,m){
            cnt+=upper_bound(all(a),(k-b[i])%k)-(lower_bound(all(a),(k-b[i])%k));
        }
        cout<<cnt<<endl;
    }
    else{
        map<int,int> mp,mq;
        rep(i,m) b[i]%=k;
        rep(i,n) a[i]%=k;
        rep(i,m) b[i]=gcd(b[i],k),mp[b[i]]++;
        rep(i,n) a[i]=gcd(a[i],k),mq[a[i]]++;
        for(auto &x:mp){
            for(auto &y:mq){
                if((x.fs*y.fs)%k==0){
                    cnt+=x.sc*y.sc;
                }
            }
        }
        cout<<cnt<<endl;
    }
    
}
0