結果
| 問題 | No.2188 整数列コイントスゲーム |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-08-13 17:00:16 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,178 bytes |
| 記録 | |
| コンパイル時間 | 592 ms |
| コンパイル使用メモリ | 66,844 KB |
| 最終ジャッジ日時 | 2025-01-30 22:17:24 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 |
ソースコード
#include <iostream>
#include <stdio.h>
#include <stdint.h>
using namespace std;
using ll = long long;
#define CIN( LL , A ) LL A; cin >> A
#define FOR_LL( VAR , INITIAL , FINAL_PLUS_ONE ) for( ll VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define RETURN( LL , ANSWER ) const LL answer_for_contest = ( ANSWER ); cout << answer_for_contest << endl; return 0
int main()
{
// X ^ K
// = sum( ll i = 0 ; true ; i++ ) A( i ) Combination( X , i )
// = sum( ll i = 0 ; i <= k ; i++ ) A( i ) Combination( X , i )
// A( I ) = Difference ^ I( X ^ K )( 0 )
// = sum( ll i = 0 ; i <= I ; j++ ) ( -1 ) ^ ( I - i ) * Combination( I , i ) * i ^ K
CIN( ll , K );
CIN( ll , I );
if( K < I ){
RETURN( ll , 0 );
}
ll I_next = I + 1;
ll answer = 0;
ll combination = 1;
FOR_LL( i , 0 , I_next ){
ll exponent = K;
ll power = 1;
ll power2 = i;
while( exponent != 0 ){
if( exponent % 2 == 1 ){
power *= power2;
}
exponent /= 2;
power2 = power2 * power2;
}
answer += ( ( I - i ) % 2 == 0 ? 1 : -1 ) * combination * power;
combination = ( combination * ( I - i ) ) / ( i + 1 );
}
RETURN( ll , answer );
}