結果
問題 | No.359 門松行列 |
ユーザー |
![]() |
提出日時 | 2016-04-18 03:33:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,201 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 24,192 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-04 13:14:04 |
合計ジャッジ時間 | 760 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d", &t); | ~~~~~^~~~~~~~~~ main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%d", &l); | ~~~~~^~~~~~~~~~ main.cpp:33:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d", &a[j]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>int isK(int a, int b, int c) {return ( (a < b && b > c && a != c) || (a > b && b < c && a != c) );}int a[9], p, q, l;int isKM(int x) {if( ! (0 < x && x < l) ) { return 0; }a[p] = x;a[q] = l - x;return (isK(a[0], a[1], a[2]) &&isK(a[3], a[4], a[5]) &&isK(a[6], a[7], a[8]) &&isK(a[0], a[3], a[6]) &&isK(a[1], a[4], a[7]) &&isK(a[2], a[5], a[8]) &&isK(a[0], a[4], a[8]) &&isK(a[2], a[4], a[6]));}int main() {int t, i;scanf("%d", &t);for(i = 0; i < t; i++) {int j, k, flag = 1;scanf("%d", &l);for(j = 0; j < 9; j++) {scanf("%d", &a[j]);if(a[j] == 0) { if(flag) { p = j; flag = 0; } else { q = j; } }}int b[18];for(j = 0; j < 9; j++) {b[j] = a[j];b[9 + j] = l - b[j];}b[p] = l / 2;// sortfor(j = 18; 2 <= j; j--) {for(k = 1; k < j; k++) {if(b[k-1] > b[k]) {int tmp = b[k-1];b[k-1] = b[k];b[k] = tmp;}}}int ans = 0;for(j = 1; j < 18; j++) {if(b[j] - 1 > b[j - 1]) {if( isKM(b[j] - 1) ) {ans += (b[j] - 1) - b[j - 1];}}if(b[j] != b[j - 1]) { ans += isKM(b[j]); }}printf("%d\n", ans);}return 0;}