結果

問題 No.551 夏休みの思い出(2)
ユーザー kotatsugamekotatsugame
提出日時 2019-02-22 19:38:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 977 ms / 4,000 ms
コード長 991 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 27,528 KB
最終ジャッジ日時 2023-08-16 11:10:57
合計ジャッジ時間 11,897 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 17 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,384 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,384 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 268 ms
10,016 KB
testcase_28 AC 261 ms
9,996 KB
testcase_29 AC 107 ms
5,200 KB
testcase_30 AC 234 ms
9,132 KB
testcase_31 AC 106 ms
5,140 KB
testcase_32 AC 229 ms
8,944 KB
testcase_33 AC 266 ms
9,924 KB
testcase_34 AC 208 ms
8,112 KB
testcase_35 AC 116 ms
5,496 KB
testcase_36 AC 170 ms
7,244 KB
testcase_37 AC 977 ms
27,528 KB
testcase_38 AC 810 ms
23,484 KB
testcase_39 AC 352 ms
12,228 KB
testcase_40 AC 638 ms
19,720 KB
testcase_41 AC 309 ms
11,356 KB
testcase_42 AC 817 ms
23,832 KB
testcase_43 AC 357 ms
12,276 KB
testcase_44 AC 473 ms
15,604 KB
testcase_45 AC 378 ms
13,012 KB
testcase_46 AC 908 ms
26,344 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
long P,R;
long power(long a,long b){return b?power(a*a%P,b/2)*(b%2?a:1)%P:1;}
main()
{
	int q;cin>>P>>R>>q;
	int m=sqrt(q*P);
	vector<pair<int,int> >table(m);
	long e=1;
	for(int i=0;i<m;i++)
	{
		table[i]=make_pair(e,i);
		e=e*R%P;
	}
	sort(table.begin(),table.end());
	long inv=power(power(R,P-2),m);
	for(;q--;)
	{
		long a,b,c;cin>>a>>b>>c;
		long d=(b*b%P-4*a*c%P+P)%P*power(4*a*a%P,P-2)%P;
		long t=(P-b*power(2*a%P,P-2)%P)%P;
		if(d==0)
		{
			cout<<t<<endl;
		}
		else
		{
			long k,now=d;
			for(int i=0;;i++)
			{
				pair<int,int>p=*lower_bound(table.begin(),table.end(),make_pair((int)now,-1));
				if(p.first==now)
				{
					k=i*m+p.second;
					break;
				}
				now=now*inv%P;
			}
			if(k%2==0)
			{
				long x=(power(R,k/2)+t)%P,y=(power(R,(k/2+P/2)%(P-1))+t)%P;
				if(x<y)cout<<x<<" "<<y<<endl;
				else cout<<y<<" "<<x<<endl;
			}
			else
			{
				cout<<-1<<endl;
			}
		}
	}
}
0