結果

問題 No.2146 2 Pows
ユーザー 👑 ygussanyygussany
提出日時 2022-12-02 23:24:54
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,325 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 32,348 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 08:39:51
合計ジャッジ時間 23,123 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1,290 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 47 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 839 ms
5,376 KB
testcase_18 AC 325 ms
5,376 KB
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 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int bit[22] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152};

void chmin(long long* a, long long b)
{
	if (*a > b) *a = b;
}

int main()
{
	int N;
	long long A, B, C;
	scanf("%d %lld %lld %lld", &N, &A, &B, &C);
	
	int i, ii, j, k, x, y, yy, z, rem[200001] = {};
	const long long sup = 1LL << 60;
	long long ans[200001], tmp;
	for (i = 1, tmp = 1, rem[1] = 1; 1; i++) {
		tmp = tmp * 2 % N;
		if (rem[tmp] != 0) break;
		rem[tmp] = i + 1;
	}
	for (i = 2, ans[1] = A + B; i <= N; i++) {
		ans[i] = sup;
		if (rem[i] != 0) ans[i] = A + B + C * (rem[i] - 1);
		for (ii = i; ii <= i; ii += N) {
			for (z = 0; bit[z] <= ii; z++) {
				if (ii % bit[z] == 0) {
					chmin(&(ans[i]), A * (ii / bit[z]) + B + C * z);
					continue;
				}
				for (y = 2; y <= z + 1; y++) {
					for (k = z, j = ii, x = 0, yy = 0; yy < y - 1 && j > 0; k--) {
						if (j / bit[k] > 0) {
							yy++;
							x += j / bit[k];
							j %= bit[k];
						}
					}
					if (yy == y - 1 && j > 0) {
						for (; j % bit[k] != 0; k--);
						x += j / bit[k];
						chmin(&(ans[i]), A * x + B * y + C * z);
					} else break;
				}
			}
		}
	}
	
	printf("%lld\n", ans[N]);
	for (i = 1; i < N; i++) printf("%lld\n", ans[i]);
	fflush(stdout);
	return 0;
}
0