結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-02-14 22:56:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,937 ms / 2,000 ms
コード長 2,184 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 216,208 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2024-04-27 20:04:53
合計ジャッジ時間 7,881 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 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 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 30 ms
6,940 KB
testcase_11 AC 16 ms
6,940 KB
testcase_12 AC 1,913 ms
6,944 KB
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 27 ms
6,944 KB
testcase_15 AC 14 ms
6,944 KB
testcase_16 AC 38 ms
7,808 KB
testcase_17 AC 13 ms
6,940 KB
testcase_18 AC 1,937 ms
6,940 KB
testcase_19 AC 574 ms
6,940 KB
testcase_20 AC 102 ms
14,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
vector<int> enumdiv(int n) { 
    vector<int> S;
    for (int i = 1; 1LL*i*i <= n; i++) if (n%i == 0) { S.push_back(i); if (i*i != n) S.push_back(n / i); }
    sort(S.begin(), S.end());
    return S;
}
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, K; char op;
ll B[101010], A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K >> op;
	rep(i, 0, M) cin >> B[i];
	rep(i, 0, N) cin >> A[i];

	ll ans = 0;
	if (op == '+') {
		map<int, int> cnt;
		rep(i, 0, M) cnt[B[i] % K]++;
		rep(i, 0, N) {
			int b_mo = K - (A[i] % K);
			b_mo %= K;
			ans += cnt[b_mo];
		}
	}
	else {
		auto ed = enumdiv(K);

		map<int, int> cnt;
		rep(i, 0, M) cnt[gcd(K, B[i])]++;

		rep(i, 0, N) fore(d, ed) if ((A[i] * d) % K == 0) ans += cnt[d];
	}
	cout << ans << endl;
}





0