結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tonegawatonegawa
提出日時 2020-09-24 19:38:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,807 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 132,712 KB
実行使用メモリ 4,904 KB
最終ジャッジ日時 2023-09-10 13:49:14
合計ジャッジ時間 6,854 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll n, m, k;
void solve_add(){
  vll a(n), b(m);
  re(i, m) std::cin >> b[i];
  re(i, n) std::cin >> a[i];
  sort(all(a));
  ll ans = 0;
  for(int i=0;i<m;i++){
    ll target = (k - b[i])%k;
    ll l = upper_bound(all(a), target) - a.begin();
    ll r = upper_bound(all(a), target+1) - a.begin();
    ans += r - l;
  }
  std::cout << ans << '\n';
}


ll gcd(ll a, ll b){
  if(b<a) swap(a, b);
  ll r = a % b;
  if(r==0) return b;
  while(r!=0) r = a % b, a = b, b = r;
  return a;
}

void solve_mul(){
  vll a(n), b(m);
  re(i, m) std::cin >> b[i];
  re(i, n) std::cin >> a[i];

  vll d;//kの約数
  d.push_back(1);
  d.push_back(k);

  for(ll i=2;i*i<=k;i++){
    if(k%i==0){
      d.push_back(i);
      if(i*i!=k) d.push_back(k/i);
    }
  }
  vll cnt(d.size(), 0);
  for(int i=0;i<n;i++) for(int j=0;j<d.size();j++) if(a[i]%d[j]==0) cnt[j]++;
  map<ll, ll> mp;
  for(int i=0;i<d.size();i++){
    mp.emplace(d[i], i);
  }
  ll ans = 0;
  for(int i=0;i<m;i++){
    ll g = gcd(k, b[i]);
    ll need_idx = mp[k/g];
    ans += cnt[need_idx];
  }
  std::cout << ans << '\n';
}
int main(){
  std::cin >> n >> m >> k;
  char op;std::cin >> op;
  if(op=='+') solve_add();
  else solve_mul();
  return 1;
}
0