結果
問題 |
No.1201 お菓子配り-4
|
ユーザー |
![]() |
提出日時 | 2020-08-28 22:24:09 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,213 bytes |
コンパイル時間 | 13,157 ms |
コンパイル使用メモリ | 273,180 KB |
最終ジャッジ日時 | 2025-01-13 18:17:09 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 TLE * 1 |
ソースコード
#pragma GCC target ("sse4") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #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 m,T a,T b){ T res=0; while(1){ 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; T nn=y; T nm=a; T na=m; T nb=(a-x%a)%a; n=nn; m=nm; a=na; b=nb; } 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],bs[j],as[i],0ull); 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; }