結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 1,616 ms
4,772 KB
testcase_13 AC 16 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,617 ms
4,676 KB
testcase_19 AC 678 ms
4,376 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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) scanf("%lld", &b[i]), b[i]%=k;
  re(i, n) scanf("%lld", &a[i]), a[i]%=k;
  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) scanf("%lld", &b[i]);
  re(i, n) scanf("%lld", &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();
}
0