結果

問題 No.1201 お菓子配り-4
ユーザー kotatsugamekotatsugame
提出日時 2020-11-27 10:28:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 42,328 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-10-01 04:05:17
合計ジャッジ時間 31,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
7,112 KB
testcase_01 AC 1,154 ms
4,376 KB
testcase_02 AC 1,635 ms
4,376 KB
testcase_03 AC 802 ms
4,380 KB
testcase_04 AC 390 ms
4,376 KB
testcase_05 AC 967 ms
4,376 KB
testcase_06 AC 147 ms
4,384 KB
testcase_07 AC 449 ms
4,380 KB
testcase_08 AC 1,238 ms
4,380 KB
testcase_09 AC 908 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 237 ms
4,376 KB
testcase_12 AC 1,871 ms
4,380 KB
testcase_13 AC 51 ms
4,376 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 1,461 ms
4,376 KB
testcase_16 AC 442 ms
4,376 KB
testcase_17 AC 579 ms
4,380 KB
testcase_18 AC 94 ms
4,376 KB
testcase_19 AC 87 ms
4,376 KB
testcase_20 AC 1 ms
4,376 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 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:31:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   31 | main()
      | ^~~~

ソースコード

diff #

#include<cstdio>
#include<algorithm>
using namespace std;
long long floor_sum(long long N,long long M,long long A,long long B)
//Sum[floor((A*i+B)/M),{i,0,N-1}]
{
	long long ans=0;
	if(B>=M)
	{
		long long BM=B/M;
		ans+=N*BM;
		B-=BM*M;
	}
	while(true)
	{
		long long AM=A/M;
		ans+=N*(N-1)/2*AM;
		A-=AM*M;
		if(A*N+B<M)break;
		long long Ym=(A*N+B)/M,Xm=Ym*M-B;
		long long TX=(Xm+A-1)/A;
		ans+=(N-TX)*Ym;
		N=Ym;
		B=TX*A-Xm;
		swap(A,M);
	}
	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]);
	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("%ld\n",ans);
}
0