結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー CleyLCleyL
提出日時 2020-02-14 22:48:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,985 ms / 2,000 ms
コード長 1,520 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 90,224 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 20:00:25
合計ジャッジ時間 7,002 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 33 ms
6,940 KB
testcase_11 AC 36 ms
6,944 KB
testcase_12 AC 1,985 ms
6,944 KB
testcase_13 AC 26 ms
6,944 KB
testcase_14 AC 58 ms
6,940 KB
testcase_15 AC 33 ms
6,944 KB
testcase_16 AC 43 ms
6,940 KB
testcase_17 AC 28 ms
6,940 KB
testcase_18 AC 1,984 ms
6,944 KB
testcase_19 AC 814 ms
6,944 KB
testcase_20 AC 100 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
template <typename T>
T gcd(T a,T b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){
  return a/gcd(a,b)*b;
}
int main(){
    long long n,m,k;cin>>n>>m>>k;
    long long ans = 0;
    char z;cin>>z;
    vector<long long> A(n);
    vector<long long> B(m);
    for(int i = 0; m > i; i++)cin>>B[i];
    for(int i = 0; n > i; i++)cin>>A[i];
    //A[i]と互いに素なB[j]の個数が答え..........O(NM)!!!!!!解散!!!!!笑
    if(z == '*'){
      for(int i = 0; m > i; i++){
        B[i] = gcd(B[i],k);
      }
      for(int i = 0; n > i; i++){
        A[i] = gcd(A[i],k);
      }
      vector<long long> C;
      for(long long i = 1; k >= i*i; i++){
        if(!(k%i)){
          C.push_back(i);
          if(i*i != k)C.push_back(k/i);
        }
      }
      map<int,int> nya;
      for(int i = 0; m > i; i++){
        for(int j = 0; C.size() > j; j++){
          if(!(B[i]%C[j])){
            nya[C[j]]++;
          }
        }
      }
      for(int i = 0; n > i; i++){
        ans += nya[k/A[i]];
      }
      cout << ans << endl;
    }else{//O(n log m)
      for(int i = 0; m > i; i++){
        B[i] = B[i]%k;
      }
      sort(B.begin(),B.end());
      for(int i = 0; n > i; i++){
        A[i] = A[i]%k;
        int want = (k-A[i])%k;
        ans += (upper_bound(B.begin(),B.end(),want)-lower_bound(B.begin(),B.end(),want));
      }
      cout << ans << endl;
    }
}
0