結果

問題 No.1201 お菓子配り-4
ユーザー cn_449cn_449
提出日時 2020-08-28 22:07:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,651 ms / 4,000 ms
コード長 1,934 bytes
コンパイル時間 2,780 ms
コンパイル使用メモリ 130,000 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-08 20:44:32
合計ジャッジ時間 21,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
4,376 KB
testcase_01 AC 789 ms
4,376 KB
testcase_02 AC 1,150 ms
4,376 KB
testcase_03 AC 559 ms
4,380 KB
testcase_04 AC 269 ms
4,380 KB
testcase_05 AC 672 ms
4,376 KB
testcase_06 AC 103 ms
4,380 KB
testcase_07 AC 305 ms
4,380 KB
testcase_08 AC 851 ms
4,380 KB
testcase_09 AC 625 ms
4,388 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 163 ms
4,380 KB
testcase_12 AC 1,307 ms
4,380 KB
testcase_13 AC 37 ms
4,376 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 1,021 ms
4,376 KB
testcase_16 AC 312 ms
4,376 KB
testcase_17 AC 400 ms
4,380 KB
testcase_18 AC 66 ms
4,376 KB
testcase_19 AC 62 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1,650 ms
4,376 KB
testcase_31 AC 1,639 ms
4,380 KB
testcase_32 AC 1,644 ms
4,384 KB
testcase_33 AC 1,651 ms
4,376 KB
testcase_34 AC 1,639 ms
4,380 KB
testcase_35 AC 1,513 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;

ll modinv(ll a) {
	a %= mod;
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, m;
	cin >> n >> m;
	vector<ll> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	ll ans = 0;
	rep(i, n) {
		rep(j, m) {
			ll g = gcd(a[i], b[j]);
			ll x = (b[j] - g) * b[j] % mod;
			if (x & 1) x += mod;
			x >>= 1;
			ll sum = (b[j] + 1) * b[j] / 2 % mod;
			sum *= a[i]; sum %= mod;
			sum -= x; if (sum < 0) sum += mod;
			sum *= modinv(b[j]); sum %= mod;
			ans += sum;
		}
	}
	cout << ans * 2 % mod << '\n';
}
0