結果

問題 No.1201 お菓子配り-4
ユーザー beetbeet
提出日時 2020-08-28 21:58:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,180 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 195,672 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-26 12:59:02
合計ジャッジ時間 48,553 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
6,816 KB
testcase_01 AC 1,894 ms
5,376 KB
testcase_02 AC 2,806 ms
5,376 KB
testcase_03 AC 1,340 ms
5,376 KB
testcase_04 AC 661 ms
5,376 KB
testcase_05 AC 1,596 ms
5,376 KB
testcase_06 AC 247 ms
5,376 KB
testcase_07 AC 723 ms
5,376 KB
testcase_08 AC 2,078 ms
5,376 KB
testcase_09 AC 1,516 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 385 ms
5,376 KB
testcase_12 AC 3,133 ms
5,376 KB
testcase_13 AC 88 ms
5,376 KB
testcase_14 AC 44 ms
5,376 KB
testcase_15 AC 2,417 ms
5,376 KB
testcase_16 AC 722 ms
5,376 KB
testcase_17 AC 935 ms
5,376 KB
testcase_18 AC 154 ms
5,376 KB
testcase_19 AC 141 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 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 3,846 ms
5,376 KB
testcase_31 AC 3,857 ms
5,376 KB
testcase_32 AC 3,831 ms
5,376 KB
testcase_33 AC 3,880 ms
5,376 KB
testcase_34 AC 3,843 ms
5,376 KB
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<long long>(bs[j]+1,bs[j],as[i],0)%MOD;
      ans%=MOD;
    }
  }

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