結果

問題 No.2847 Birthday Attack
ユーザー kotatsugamekotatsugame
提出日時 2024-08-23 21:56:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 959 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 76,180 KB
実行使用メモリ 160,628 KB
最終ジャッジ日時 2024-08-23 21:56:39
合計ジャッジ時間 8,711 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 324 ms
160,404 KB
testcase_01 AC 309 ms
160,524 KB
testcase_02 AC 303 ms
160,556 KB
testcase_03 AC 312 ms
160,544 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   39 |         for(auto[a,b]:T)
      |                 ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int gcd(int a,int b)
{
	while(b)
	{
		int t=a%b;
		a=b;
		b=t;
	}
	return a;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<pair<int,int> >T;
	T.reserve(20138910);
	auto add=[&](int a,int b){
		int mxab=max(a,b);
		for(int k=1;mxab*k<=(int)4e6;k++)T.emplace_back(a*k,b*k);
	};
	for(int m=1;m*m<=(int)6e6;m++)
	{
		for(int n=1;n<m;n++)
		{
			if(n%2&&m%2)continue;
			if(gcd(n,m)!=1)continue;
			add(m*m-n*n,2*m*n);
			add(2*m*n,m*m-n*n);
		}
	}
	int X,Y,M;
	cin>>X>>Y>>M;
	long ans=0;
	for(auto[a,b]:T)
	{
		int lx=a+1,rx=X-a;
		int ly=b+1,ry=Y-b;
		if(lx>rx||ly>ry)continue;
		ans+=(long)(rx-lx+1)*(ry-ly+1)%M;
		if(ans>=M)ans-=M;
	}
	ans=ans*2%M;
	for(int a=1;a+1<=X-a;a++)
	{
		ans+=(long)(X-a-a-1+1)*Y*2%M;
		if(ans>=M)ans-=M;
	}
	for(int b=1;b+1<=Y-b;b++)
	{
		ans+=(long)X*(Y-b-b-1+1)*2%M;
		if(ans>=M)ans-=M;
	}
	cout<<ans<<endl;
}
0