結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー le_panda_noir
提出日時 2020-04-10 22:38:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 2,269 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 84,328 KB
最終ジャッジ日時 2025-01-09 16:23:16
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;
// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}


#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif

int main() {
  int in(N); int in(M); int in(K);

  char in(op);
  vi A(N), B(M);
  rep(i, M) cin >> B[i];
  rep(i, N) cin >> A[i];

  if (op == '+') {
    vi count(K, 0);
    rep(i, M)
      ++count[B[i] % K];
    ll ans = 0;
    rep(i, N)
      ans += count[(K - A[i] % K) % K];
    cout << ans << endl;
  } else {
    map<int, int> count, count2;
    rep(i, M) ++count[gcd(B[i], K)];
    rep(i, N) ++count2[gcd(A[i], K)];

    ll ans = 0;
    for (const auto& [a, e] : count2) {
      ll tmp = 0;
      for (int j = 1; j * j <= a; ++j) {
        if (a % j == 0) {
          tmp += count[K / (a/j)];
          if (a != j * j)
            tmp += count[K / j];
        }
      }
      ans += tmp * e;
    }

    cout << ans << endl;
  }

  return 0;
}
0