結果

問題 No.1201 お菓子配り-4
ユーザー SSRSSSRS
提出日時 2020-08-28 22:12:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,000 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 196,288 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-26 13:10:34
合計ジャッジ時間 31,061 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
6,812 KB
testcase_01 AC 1,052 ms
6,944 KB
testcase_02 AC 1,563 ms
6,940 KB
testcase_03 AC 735 ms
6,944 KB
testcase_04 AC 355 ms
6,940 KB
testcase_05 AC 889 ms
6,940 KB
testcase_06 AC 134 ms
6,940 KB
testcase_07 AC 401 ms
6,940 KB
testcase_08 AC 1,120 ms
6,944 KB
testcase_09 AC 827 ms
6,940 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 213 ms
6,940 KB
testcase_12 AC 1,718 ms
6,940 KB
testcase_13 AC 49 ms
6,944 KB
testcase_14 AC 25 ms
6,944 KB
testcase_15 AC 1,349 ms
6,948 KB
testcase_16 AC 409 ms
6,944 KB
testcase_17 AC 530 ms
6,940 KB
testcase_18 AC 86 ms
6,940 KB
testcase_19 AC 81 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2,171 ms
6,944 KB
testcase_31 AC 2,159 ms
5,376 KB
testcase_32 AC 2,159 ms
5,376 KB
testcase_33 AC 2,170 ms
5,376 KB
testcase_34 AC 2,153 ms
5,376 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++){
      long long tmp = gauss_sum(B[j], A[i], A[i], B[j]);
      ans += tmp % MOD;
    }
  }
  ans *= 2;
  ans %= MOD;
  cout << ans << endl;
}
0