結果

問題 No.1201 お菓子配り-4
ユーザー SSRSSSRS
提出日時 2020-08-28 22:15:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,159 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 197,096 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-04-26 13:15:14
合計ジャッジ時間 31,021 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
10,144 KB
testcase_01 AC 1,053 ms
6,940 KB
testcase_02 AC 1,524 ms
6,944 KB
testcase_03 AC 739 ms
6,940 KB
testcase_04 AC 360 ms
6,940 KB
testcase_05 AC 899 ms
6,944 KB
testcase_06 AC 137 ms
6,940 KB
testcase_07 AC 409 ms
6,940 KB
testcase_08 AC 1,133 ms
6,944 KB
testcase_09 AC 833 ms
6,944 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 216 ms
6,944 KB
testcase_12 AC 1,736 ms
6,940 KB
testcase_13 AC 49 ms
6,940 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 1,369 ms
6,944 KB
testcase_16 AC 415 ms
6,944 KB
testcase_17 AC 530 ms
6,944 KB
testcase_18 AC 88 ms
6,940 KB
testcase_19 AC 82 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 2,180 ms
6,940 KB
testcase_31 AC 2,203 ms
6,940 KB
testcase_32 AC 2,209 ms
6,940 KB
testcase_33 AC 2,188 ms
6,944 KB
testcase_34 AC 2,184 ms
6,940 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
//https://judge.yosupo.jp/submission/7028
long long gauss_sum(long long n, long long a, long long b, long long c) {
	if (n == 0) return 0;
	long long res = 0;
	{
		long long p = a / c;
		res += n * (n-1) / 2 * p;
		a %= c;
	}
	{
		long long p = b / c;
		res += n * p;
		b %= c;
	}
	if (a == 0) return res;
	long long top = (a * (n-1) + b) / c;
	res += top * n;
	long long h = 1;
	if (h <= top) {
		res -= gauss_sum(top - h + 1, c, c * h - (b + 1), a) + top - h + 1;
	}
	return res;
}
int main(){
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> B(M);
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      if (A[i] >= B[j]){
        long long tmp = B[j] * (B[j] + 1) % MOD * (A[i] / B[j]) % MOD;
        ans += tmp;
      }
      long long tmp = gauss_sum(B[j], A[i] % B[j], A[i] % B[j], B[j]);
      ans += tmp * 2 % MOD;
    }
  }
  ans %= MOD;
  cout << ans << endl;
}
0