結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 32 ms
6,940 KB
testcase_11 AC 35 ms
6,944 KB
testcase_12 AC 135 ms
6,944 KB
testcase_13 AC 23 ms
6,944 KB
testcase_14 AC 58 ms
6,944 KB
testcase_15 AC 32 ms
6,944 KB
testcase_16 AC 40 ms
6,940 KB
testcase_17 AC 27 ms
6,940 KB
testcase_18 AC 144 ms
6,944 KB
testcase_19 AC 50 ms
6,940 KB
testcase_20 AC 100 ms
6,940 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);
      }
      map<long long,int> C;
      for(int i = 0; n > i; i++){
        C[A[i]]++;
      }
      map<long long,int> D;
      for(int i = 0; m > i; i++){
        D[B[i]]++;
      }
      for(auto x:C){
        for(auto y:D){
          if(!((x.first*y.first)%k)){
            ans += (long long)x.second*y.second;
          }
        }
      }
      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