結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tnakao0123tnakao0123
提出日時 2020-02-15 22:34:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,664 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 100,892 KB
実行使用メモリ 9,064 KB
最終ジャッジ日時 2023-08-10 03:19:11
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 32 ms
5,880 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 RE -
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 32 ms
4,384 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 33 ms
5,700 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 99 ms
9,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 990.cc:  No.990 N×Mマス計算(Kの倍数) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const int MAX_DN = 32;

/* typedef */

typedef long long ll;
typedef map<int,int> mii;

/* global variables */

int as[MAX_N], bs[MAX_M];
mii brs;
int kds[MAX_DN], bdns[MAX_DN];

/* subroutines */

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  char s[4];
  scanf("%s", s);
  char op = s[0];

  int asum = 0, bsum = 0;
  for (int j = 0; j < m; j++) scanf("%d", bs + j);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  ll sum = 0;
  if (op == '+') {
    for (int j = 0; j < m; j++) brs[bs[j] % k]++;
    for (int i = 0; i < n; i++) {
      mii::iterator mit = brs.find((k - as[i] % k) % k);
      if (mit != brs.end()) sum += mit->second;
    }
  }
  else {
    int kdn = 0;
    for (int p = 1; p * p <= k; p++)
      if (k % p == 0) {
	kds[kdn++] = p;
	int q = k / p;
	if (q != p) kds[kdn++] = q;
      }
    sort(kds, kds + kdn);

    for (int j = 0; j < m; j++)
      for (int di = 0; di < kdn; di++)
	if (bs[j] % kds[di] == 0) bdns[di]++;
	  
    for (int i = 0; i < n; i++)
      for (int di = kdn - 1; di >= 0; di--)
	if (as[i] % kds[di] == 0) {
	  sum += bdns[kdn - 1 - di];
	  break;
	}
  }

  printf("%lld\n", sum);
  return 0;
}
0