結果

問題 No.1633 Sorting Integers (Multiple of 2^K)
ユーザー bal4u
提出日時 2021-08-10 12:32:05
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 29,824 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 13:49:37
合計ジャッジ時間 2,399 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

// yuki 1633 Sorting Integers (Multiple of 2^K)
// 2021.8.10

#include <stdio.h>
typedef long long ll;

int N;
int f[10];
int ans;

void rec(int a, int p2, ll p5, int w) {
	int i;
//printf("a=%d, p2=%d, w=%d\n", a, p2, w);
	if (p2 > ans) ans = p2;
	if (w == N) {
		while (!(a & 1)) p2++, a >>= 1;
		if (p2 > ans) ans = p2;
		return;
	}
	for (i = 1; i <= 9; ++i) if (f[i] && !((a+i*p5) & 1)) {
		f[i]--, rec((a+i*p5)>>1, p2+1, 5*p5, w+1), f[i]++;
	}
}

int main() {
	int i;

	scanf("%d", &N);
	for (i = 1; i <= 9; ++i) scanf("%d", f+i);
	for (i = 2; i < 10; i+=2) if (f[i]) {
		f[i]--, rec(i>>1, 1, 5, 1),f[i]++;
	}
	printf("%d\n", ans);
	return 0;
}
0