結果

問題 No.1201 お菓子配り-4
ユーザー beetbeet
提出日時 2020-08-28 22:29:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,178 ms / 4,000 ms
コード長 959 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 193,472 KB
最終ジャッジ日時 2025-01-13 18:26:20
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

const unsigned int MOD = 1e9+7;
// sum_{i=0}^{n-1} (ai + b) // m
// 0 <= a, b
template<typename T>
inline T sum_of_floor(T n,T a){
  T res=0;
  while(1){
    if(a>=n){
      res+=(n-1)*n*(a/n)/2;
      a%=n;
    }
    T y=a;
    if(y==0) return res;
    T nn=y;
    T na=n;
    n=nn;
    a=na;
  }
  cout<<newl;
  return res;
}

//INSERT ABOVE HERE
using ull = unsigned long long;
const int MAX = 2020;
ull as[MAX];
ull bs[MAX];

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  ull n,m;
  cin>>n>>m;
  for(ull i=0;i<n;i++) cin>>as[i];
  for(ull j=0;j<m;j++) cin>>bs[j];

  vector<ull> ans(m);
  for(ull i=0;i<n;i++)
    for(ull j=0;j<m;j++)
      ans[j]+=sum_of_floor(bs[j],as[i]);

  ull res=0;
  for(ull j=0;j<m;j++){
    res+=ans[j]%MOD;
    res%=MOD;
  }

  for(ull i=0;i<n;i++) res+=as[i]*m;

  res*=2;
  res%=MOD;
  cout<<res<<newl;
  return 0;
}
0