結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
6,812 KB
testcase_01 AC 2,189 ms
6,944 KB
testcase_02 AC 3,173 ms
6,944 KB
testcase_03 AC 1,535 ms
6,940 KB
testcase_04 AC 758 ms
6,944 KB
testcase_05 AC 1,863 ms
6,940 KB
testcase_06 AC 283 ms
6,944 KB
testcase_07 AC 853 ms
6,940 KB
testcase_08 AC 2,373 ms
6,944 KB
testcase_09 AC 1,729 ms
6,940 KB
testcase_10 AC 14 ms
6,944 KB
testcase_11 AC 449 ms
6,940 KB
testcase_12 AC 3,627 ms
6,940 KB
testcase_13 AC 99 ms
6,940 KB
testcase_14 AC 50 ms
6,944 KB
testcase_15 AC 2,867 ms
6,940 KB
testcase_16 AC 869 ms
6,940 KB
testcase_17 AC 1,122 ms
6,940 KB
testcase_18 AC 180 ms
6,944 KB
testcase_19 AC 171 ms
6,944 KB
testcase_20 AC 2 ms
6,944 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,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

// sum_{i=0}^{n-1} (ai + b) // m
// 0 <= a, b
template<typename T>
T sum_of_floor(T n,T m,T a,T b){
  T res=0;
  if(a>=m){
    res+=(n-1)*n*(a/m)/2;
    a%=m;
  }
  if(b>=m){
    res+=n*(b/m);
    b%=m;
  }
  T y=(a*n+b)/m;
  T x=y*m-b;
  if(y==0) return res;
  res+=(n-(x+a-1)/a)*y;
  res+=sum_of_floor(y,a,m,(a-x%a)%a);
  // cout<<(int)res<<endl;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,m;
  cin>>n>>m;
  auto as=read(n);
  auto bs=read(m);

  const int MOD = 1e9+7;
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      ans+=sum_of_floor<__int128_t>(bs[j]+1,bs[j],as[i],0)%MOD;
      ans%=MOD;
    }
  }

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