結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,352 KB
testcase_01 AC 23 ms
4,348 KB
testcase_02 AC 23 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 21 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 21 ms
4,352 KB
testcase_09 WA -
testcase_10 AC 22 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 21 ms
4,352 KB
testcase_14 AC 20 ms
4,352 KB
testcase_15 AC 21 ms
4,352 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 16 ms
4,348 KB
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 AC 23 ms
4,352 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 18 ms
4,352 KB
testcase_32 WA -
testcase_33 AC 17 ms
4,352 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 24 ms
4,348 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 25 ms
4,348 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 26 ms
4,348 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 23 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]--;
		}
	}

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

	return 0;
}
0