結果
問題 |
No.1201 お菓子配り-4
|
ユーザー |
![]() |
提出日時 | 2020-11-27 11:54:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 915 bytes |
コンパイル時間 | 332 ms |
コンパイル使用メモリ | 30,720 KB |
最終ジャッジ日時 | 2025-01-16 06:02:07 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 TLE * 1 |
コンパイルメッセージ
main.cpp:32:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 32 | main() | ^~~~ main.cpp: In function ‘int main()’: main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:35:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | for(int i=0;i<N;i++)scanf("%d",&A[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:36:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | for(int i=0;i<M;i++)scanf("%d",&B[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<cstdio> using namespace std; #pragma GCC optimize ("O3") #pragma GCC target ("avx2") #pragma GCC optimize("unroll-loops") unsigned long long floor_sum(unsigned long long N,unsigned long long M,unsigned long long A,unsigned long long B) //Sum[floor((A*i+B)/M),{i,0,N-1}] { unsigned long long ans=0; if(A>=M) { unsigned long long AM=A/M; ans+=N*(N-1)/2*AM; A-=AM*M; } if(B>=M) { unsigned long long BM=B/M; ans+=N*BM; B-=BM*M; } unsigned long long Ym=(A*N+B)/M,Xm=Ym*M-B; if(Ym==0)return ans; unsigned long long TX=(Xm+A-1)/A; ans+=(N-TX)*Ym; ans+=floor_sum(Ym,A,M,TX*A-Xm); return ans; } int N,M; int A[2000],B[2000]; main() { scanf("%d%d",&N,&M); for(int i=0;i<N;i++)scanf("%d",&A[i]); for(int i=0;i<M;i++)scanf("%d",&B[i]); unsigned long ans=0; for(int i=0;i<N;i++)for(int j=0;j<M;j++) { ans+=2*floor_sum(B[j],B[j],A[i],A[i]); ans%=(int)1e9+7; } printf("%lu\n",ans); }