結果

問題 No.1201 お菓子配り-4
ユーザー bachoppibachoppi
提出日時 2020-08-29 10:15:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,647 ms / 4,000 ms
コード長 1,291 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 119,364 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 16:10:30
合計ジャッジ時間 20,596 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
5,248 KB
testcase_01 AC 806 ms
5,376 KB
testcase_02 AC 1,152 ms
5,376 KB
testcase_03 AC 547 ms
5,376 KB
testcase_04 AC 264 ms
5,376 KB
testcase_05 AC 665 ms
5,376 KB
testcase_06 AC 103 ms
5,376 KB
testcase_07 AC 305 ms
5,376 KB
testcase_08 AC 853 ms
5,376 KB
testcase_09 AC 621 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 164 ms
5,376 KB
testcase_12 AC 1,307 ms
5,376 KB
testcase_13 AC 37 ms
5,376 KB
testcase_14 AC 20 ms
5,376 KB
testcase_15 AC 1,022 ms
5,376 KB
testcase_16 AC 310 ms
5,376 KB
testcase_17 AC 399 ms
5,376 KB
testcase_18 AC 66 ms
5,376 KB
testcase_19 AC 62 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1,624 ms
5,376 KB
testcase_31 AC 1,625 ms
5,376 KB
testcase_32 AC 1,633 ms
5,376 KB
testcase_33 AC 1,636 ms
5,376 KB
testcase_34 AC 1,647 ms
5,376 KB
testcase_35 AC 1,495 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

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

int main(){
  int n, m; cin >> n >> m;
  ll a[n], b[m];
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll tmp = 0;
  rep(i, n){
    rep(j, m){
      ll g = gcd(a[i], b[j]); ll made = b[j]/g - 1; ll ans = 0;
      //cout << made << endl;
      ans+=a[i]*b[j]%mod*(b[j]+1)%mod;
      //cout << ans << endl;
      ans-=g*g%mod*made%mod*(made+1)%mod;
      //cout << ans << endl;
      if(ans<0) ans+=mod; ans%=mod;
      ans*=modinv(b[j], mod); ans%=mod;
      tmp+=ans; tmp%=mod;
    }
  }
  cout << tmp << endl;
}
0