結果

問題 No.1201 お菓子配り-4
ユーザー mine691mine691
提出日時 2020-11-27 11:54:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 915 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 34,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-01 04:09:20
合計ジャッジ時間 25,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
4,376 KB
testcase_01 AC 895 ms
4,376 KB
testcase_02 AC 1,285 ms
4,380 KB
testcase_03 AC 624 ms
4,380 KB
testcase_04 AC 304 ms
4,380 KB
testcase_05 AC 756 ms
4,376 KB
testcase_06 AC 115 ms
4,376 KB
testcase_07 AC 342 ms
4,376 KB
testcase_08 AC 961 ms
4,376 KB
testcase_09 AC 701 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 182 ms
4,376 KB
testcase_12 AC 1,462 ms
4,376 KB
testcase_13 AC 41 ms
4,376 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 1,150 ms
4,376 KB
testcase_16 AC 350 ms
4,376 KB
testcase_17 AC 451 ms
4,376 KB
testcase_18 AC 73 ms
4,380 KB
testcase_19 AC 69 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1,845 ms
4,376 KB
testcase_31 AC 1,855 ms
4,380 KB
testcase_32 AC 1,853 ms
4,380 KB
testcase_33 AC 1,862 ms
4,380 KB
testcase_34 AC 1,854 ms
4,380 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   32 | main()
      | ^~~~

ソースコード

diff #

#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);
}
0