結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー kriiikriii
提出日時 2018-12-09 01:58:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 975 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 32,364 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-13 10:24:48
合計ジャッジ時間 3,665 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,352 KB
testcase_01 AC 23 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 23 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 23 ms
4,352 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 23 ms
4,352 KB
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 AC 20 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 27 ms
4,352 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 23 ms
4,348 KB
testcase_51 AC 24 ms
4,348 KB
testcase_52 AC 24 ms
4,348 KB
testcase_53 AC 23 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int len = 100100;
int B,D[len],F[len]; char S[len];

bool chk(int l)
{
	l--;
	for (int i=0;i<len;i++) F[i] = D[i];
	for (int i=0;i<l;i++) F[i] -= (B-1) * (i+1);
	for (int i=0;i<len;i++) if (F[i] < 0){
		if (i == len-1) return false;
		int g = (-F[i] + B-1) / B;
		F[i] += g * B;
		F[i+1] -= g;
	}
	return true;
}

int main()
{
	scanf ("%d %s",&B,S);

	{
		int l = 0;
		while (S[l]) l++;
		for (int j=0;j<l;j++) D[l-j-1] = S[j] - '0';
		D[0]--;
		for (int j=0;;j++){
			if (D[j] >= 0) break;
			D[j] += B;
			D[j+1]--;
		}
	}

	int l = 1, r = len;
	while (l + 1 < r){
		int m = (l + r) / 2;
		if (chk(m)) l = m;
		else r = m;
	}
	chk(l);

	int p = 0;
	for (int i=len-1;i>=0;i--){
		p = (p * B + F[i]) % l;
	}

	F[0] -= p;
	for (int i=0;;i++){
		if (F[i] >= 0) break;
		while (F[i] < 0){
			F[i] += B;
			F[i+1]--;
		}
	}

	for (int i=len-1;i>=0;i--){
		if (i) F[i-1] += F[i] % l;
		F[i] /= l;
	}

	l--;
	F[l]++;
	printf ("%d\n",F[l-p]);

	return 0;
}
0