結果
問題 | No.362 門松ナンバー |
ユーザー | FF256grhy |
提出日時 | 2016-04-18 16:23:42 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 3,000 ms |
コード長 | 1,251 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 24,576 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 14:47:29 |
合計ジャッジ時間 | 1,346 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &t); | ~~~~~^~~~~~~~~~ main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%lld", &x); | ~~~~~^~~~~~~~~~~~ main.cpp:36:30: warning: ‘len’ may be used uninitialized in this function [-Wmaybe-uninitialized] 36 | int ans[14], len; | ^~~
ソースコード
#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; }