結果

問題 No.756 チャンパーノウン定数 (1)
ユーザー kriiikriii
提出日時 2018-12-09 02:03:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 32,672 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 10:27:51
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int len = 4;
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()
{
	B = 10;
	scanf ("%s",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