結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー leaf_1415leaf_1415
提出日時 2020-02-14 21:52:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 4,522 ms
コンパイル使用メモリ 81,924 KB
実行使用メモリ 18,208 KB
最終ジャッジ日時 2023-08-10 01:51:20
合計ジャッジ時間 4,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 48 ms
8,452 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 711 ms
13,136 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 56 ms
9,032 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 711 ms
12,848 KB
testcase_19 AC 308 ms
6,932 KB
testcase_20 AC 166 ms
18,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint h, w, k;
char op;
int a[100005], b[100005];
vector<int> vec;
int num[2005];
map<int, int> mp, mpA, mpB;

int gcd(int a,int b)
{
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main(void)
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> h >> w >> k;
  cin >> op;
  for(int i = 1; i <= w; i++) cin >> a[i];
  for(int i = 1; i <= h; i++) cin >> b[i];

  for(int i = 1; i <= w; i++) mpA[a[i]%k]++;
  for(int i = 1; i <= h; i++) mpB[b[i]%k]++;

  if(op == '+'){
    llint ans = 0;
    for(auto it = mpA.begin(); it != mpA.end(); it++){
      ans += it->second * mpB[(k-it->first) % k];
    }
    cout << ans << endl;
    return 0;
  }
  else{

    for(int i = 1; i*i <= k; i++){
      if(k % i == 0){
        vec.push_back(i);
        vec.push_back(k/i);
      }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    int m = vec.size();
    for(int i = 0; i < m; i++) mp[vec[i]] = i;
    for(int i = 1; i <= w; i++){
      for(int j = 0; j < m; j++){
        if(a[i] % vec[j] == 0) num[j]++;
      }
    }

    llint ans = 0;
    for(int i = 1; i <= h; i++){
      llint g = gcd(k, b[i]);
      ans += num[mp[k / g]];
    }
    cout << ans << endl;
    return 0;
  }

  return 0;
}
0