結果

問題 No.362 門松ナンバー
ユーザー FF256grhyFF256grhy
提出日時 2016-04-18 16:23:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 3,000 ms
コード長 1,251 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 27,428 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 02:42:12
合計ジャッジ時間 1,787 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:9: warning: ‘len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   for(d = len - 1; 2 <= d; d--) {
       ~~^~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int isK(int a, int b, int c) {
	return ( (a < b && b > c && a != c) || (a > b && b < c && a != c) );
}

long long int dp[15][10][10];

int main() {
	int d, i, j, k, l;
	for(i = 0; i < 10; i++) {
	for(j = 0; j < 10; j++) {
		if(i != j) { dp[2][i][j] = 1; } 
	}
	}
	
	for(d = 3; d <= 14; d++) {
		for(i = 0; i < 10; i++) {
		for(j = 0; j < 10; j++) {
		for(k = 0; k < 10; k++) {
			if( isK(i, j, k) ) {
				dp[d][i][j] += dp[d - 1][j][k];
			}
		}
		}
		}
	}
	
	int t;
	scanf("%d", &t);
	for(i = 0; i < t; i++) {
		
		long long int x;
		scanf("%lld", &x);
		
		int ans[14], len;
		long long int count = 0;
		for(d = 3; d <= 14; d++) {
			for(j = 1; j < 10; j++) {
			for(k = 0; k < 10; k++) {
				if(count + dp[d][j][k] >= x) {
					ans[d - 1] = j;
					ans[d - 2] = k;
					len = d;
					d = j = k = 15; // 3重ループ脱出
				} else { count += dp[d][j][k]; }
			}
			}
		}
		
		for(d = len - 1; 2 <= d; d--) {
			j = ans[d    ];
			k = ans[d - 1];
			for(l = 0; l < 10; l++) {
				if( isK(j, k, l) ) {
					if(count + dp[d][k][l] >= x) {
						ans[d - 2] = l;
						break;
					} else { count += dp[d][k][l]; }
				}
			}
		}
		
		for(d = len - 1; 0 <= d; d--) {
			printf("%d", ans[d]);
		}
		printf("\n");
		
	}
	return 0;
}
0