結果

問題 No.1419 Power Moves
ユーザー publflpublfl
提出日時 2021-03-05 22:40:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,109 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 49,536 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 10:26:41
合計ジャッジ時間 2,460 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
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 -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:83:31: warning: 'inv' may be used uninitialized [-Wmaybe-uninitialized]
   83 |                 long long int inv;
      |                               ^~~

ソースコード

diff #

#include <stdio.h>
#include <vector>
#define MOD 1000000007

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans%=MOD;
		k*=k, k%=MOD;
		b/=2;
	}
	return ans;
}
long long int inv(long long int k)
{
	return power(k,MOD-2);
}

std::pair<long long int, long long int> func(long long int a, long long int b, long long int m)
{
	if(b==0) return std::make_pair(0,1);
	else
	{
		if(b%2==0)
		{
			std::pair<long long int, long long int> P1 = func(a,b/2,m);
			std::pair<long long int, long long int> P2;
			P2.first = (P1.first * P1.second + P1.first * P1.second + (P1.second*P1.second)/m) % MOD;
			P2.first += (((P1.first*P1.first)%MOD)*m) % MOD, P2.first %= MOD;
			P2.second = (P1.second*P1.second)%m;
			return P2;
		}
		else
		{
			std::pair<long long int, long long int> P1 = func(a,(b-1)/2,m);
			std::pair<long long int, long long int> P2;
			P2.first = (P1.first * P1.second + P1.first * P1.second + (P1.second*P1.second)/m) % MOD;
			P2.first += (((P1.first*P1.first)%MOD)*m) % MOD, P2.first %= MOD;
			P2.second = (P1.second*P1.second)%m;
			
			P2.first *= a, P2.first %= MOD;
			P2.second *= a, P2.first += (P2.second/m), P2.first %= MOD, P2.second%= m;
			return P2;
		}
	}
}

long long int ans[100010];
int main()
{
	long long int a,b;
	scanf("%lld%lld",&a,&b);
	
	std::pair<long long int,long long int> C = func(2,b,a);
	
	C.second--;
	if(C.second<0) C.first--, C.second+=a;
	if(C.first<0) C.first += MOD;
	
	
	long long int A = C.first, B = C.second;
	if(a%2==0)
	{
		for(int i=0;i<a;i++)
		{
			if((i+B)%2==1) ans[i] = 0;
			else
			{
				long long int t = (i+B)/2;
				t %= (a/2);
				
				if(B>=t+(a/2)) ans[i] = 2*A+2;
				else if(B>=t) ans[i] = 2*A+1;
				else ans[i] = 2*A;
			}
		}
	}
	else
	{
		long long int inv;
		for(int i=1;i<a;i++)
		{
			if((2*i)%a==1)
			{
				inv = i;
				break;
			}
		}
		for(int i=0;i<a;i++)
		{
			long long int t = ((long long int)(i+B)*inv) % a;
			if(B>=t) ans[i] = A+1;
			else ans[i] = A;
		}
	}
	
	for(int i=0;i<a;i++) printf("%lld\n",(ans[i]*inv(power(2,a)))%MOD);
}
0