結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-02-15 08:46:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,762 ms / 2,000 ms
コード長 2,195 bytes
コンパイル時間 2,474 ms
コンパイル使用メモリ 215,384 KB
実行使用メモリ 14,508 KB
最終ジャッジ日時 2023-08-10 03:10:16
合計ジャッジ時間 8,181 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 36 ms
6,936 KB
testcase_11 AC 20 ms
4,464 KB
testcase_12 AC 1,757 ms
5,016 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 32 ms
4,972 KB
testcase_15 AC 17 ms
4,384 KB
testcase_16 AC 45 ms
7,836 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 1,762 ms
5,040 KB
testcase_19 AC 923 ms
4,620 KB
testcase_20 AC 143 ms
14,508 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);

		unordered_map<int, int> cnt, cnt2;
		rep(i, 0, M) fore(d, ed) if(B[i] % d == 0) cnt[d]++;
		rep(i, 0, N) ans += cnt[K / gcd(A[i], K)];
	}
	cout << ans << endl;
}





0