結果
問題 |
No.1201 お菓子配り-4
|
ユーザー |
![]() |
提出日時 | 2020-08-28 21:55:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,181 bytes |
コンパイル時間 | 2,240 ms |
コンパイル使用メモリ | 194,392 KB |
最終ジャッジ日時 | 2025-01-13 17:19:15 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 TLE * 8 |
ソースコード
#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; }