結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー kriiikriii
提出日時 2018-12-09 02:02:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 32,540 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 10:27:09
合計ジャッジ時間 3,298 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,348 KB
testcase_01 AC 22 ms
4,348 KB
testcase_02 AC 22 ms
4,348 KB
testcase_03 AC 23 ms
4,348 KB
testcase_04 AC 22 ms
4,348 KB
testcase_05 AC 22 ms
4,348 KB
testcase_06 AC 22 ms
4,352 KB
testcase_07 AC 22 ms
4,352 KB
testcase_08 AC 22 ms
4,352 KB
testcase_09 AC 22 ms
4,352 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 22 ms
4,348 KB
testcase_12 AC 22 ms
4,348 KB
testcase_13 AC 22 ms
4,348 KB
testcase_14 AC 21 ms
4,352 KB
testcase_15 AC 22 ms
4,352 KB
testcase_16 AC 22 ms
4,348 KB
testcase_17 AC 22 ms
4,348 KB
testcase_18 AC 22 ms
4,352 KB
testcase_19 AC 17 ms
4,348 KB
testcase_20 AC 17 ms
4,348 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 16 ms
4,348 KB
testcase_23 AC 22 ms
4,352 KB
testcase_24 AC 16 ms
4,348 KB
testcase_25 AC 22 ms
4,352 KB
testcase_26 AC 22 ms
4,352 KB
testcase_27 AC 22 ms
4,352 KB
testcase_28 AC 25 ms
4,348 KB
testcase_29 AC 24 ms
4,348 KB
testcase_30 AC 15 ms
4,352 KB
testcase_31 AC 19 ms
4,352 KB
testcase_32 AC 18 ms
4,352 KB
testcase_33 AC 18 ms
4,352 KB
testcase_34 AC 21 ms
4,352 KB
testcase_35 AC 18 ms
4,348 KB
testcase_36 AC 14 ms
4,352 KB
testcase_37 AC 23 ms
4,348 KB
testcase_38 AC 25 ms
4,348 KB
testcase_39 AC 28 ms
4,348 KB
testcase_40 AC 27 ms
4,348 KB
testcase_41 AC 28 ms
4,348 KB
testcase_42 AC 27 ms
4,348 KB
testcase_43 AC 26 ms
4,352 KB
testcase_44 AC 26 ms
4,352 KB
testcase_45 AC 27 ms
4,348 KB
testcase_46 AC 26 ms
4,352 KB
testcase_47 AC 26 ms
4,352 KB
testcase_48 AC 27 ms
4,348 KB
testcase_49 AC 27 ms
4,348 KB
testcase_50 AC 23 ms
4,352 KB
testcase_51 AC 23 ms
4,348 KB
testcase_52 AC 24 ms
4,348 KB
testcase_53 AC 23 ms
4,348 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 (F[i]){
		if (i) F[i-1] += F[i] % l * B;
		F[i] /= l;
	}

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

	return 0;
}
0