Submission #434276
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define gc getchar int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; } int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; } template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; } const int n = 5; int grid[n][n]; int res = 0; int used[25]; bool check() { for (int i = 0; i < 3; i++) for (int j = 0; j < 5; j++) { if (grid[i][j] == 0) continue; if (grid[i + 1][j] == 0) continue; if (grid[i + 2][j] == 0) continue; if (grid[i][j] < grid[i + 1][j] && grid[i + 1][j] < grid[i + 2][j]) return false; if (grid[i][j] > grid[i + 1][j] && grid[i + 1][j] > grid[i + 2][j]) return false; } for (int i = 0; i < 5; i++) for (int j = 0; j < 3; j++) { if (grid[i][j] == 0) continue; if (grid[i][j + 1] == 0) continue; if (grid[i][j + 2] == 0) continue; if (grid[i][j] < grid[i][j + 1] && grid[i][j + 1] < grid[i][j + 2]) return false; if (grid[i][j] > grid[i][j + 1] && grid[i][j + 1] > grid[i][j + 2]) return false; } return true; } void solve(int r, int c) { if (c == 5) { solve(r + 1, 0); return; } if (r == 5) { res++; return; } if (grid[r][c]) { solve(r, c + 1); return; } for (int a = 1; a <= 25; a++) if (used[a] == 0) { grid[r][c] = a; used[a] = 1; if (check()) solve(r, c + 1); used[a] = 0; } } int main () { int i, j, tcc, tc = 1; for (tcc = 0; tcc < tc; tcc++) { for (i = 0; i <= 25; i++) used[i] = 0; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { int a = getint(); used[a] = 1, grid[i][j] = a; } res = 0; solve(0, 0); cout << res << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 双子と○×ゲーム |
User | Hagentern |
Language | C++11 (GCC 4.9.2) |
Score | 0 |
Code Size | 2241 Byte |
Status | WA |
Exec Time | 26 ms |
Memory | 924 KB |
Compile Error
./Main.cpp: In function ‘void solve(int, int)’: ./Main.cpp:44:45: warning: iteration 24u invokes undefined behavior [-Waggressive-loop-optimizations] for (int a = 1; a <= 25; a++) if (used[a] == 0) { ^ ./Main.cpp:44:5: note: containing loop for (int a = 1; a <= 25; a++) if (used[a] == 0) { ^ ./Main.cpp: In function ‘int main()’: ./Main.cpp:56:46: warning: iteration 25u invokes undefined behavior [-Waggressive-loop-optimizations] for (i = 0; i <= 25; i++) used[i] = 0; ^ ./Main.cpp:56:9: note: containing loop for (i = 0; i <= 25; i++) used[i] = 0; ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt |
All | test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample-01.txt | WA | 24 ms | 796 KB |
sample-02.txt | WA | 26 ms | 760 KB |
test-01.txt | WA | 22 ms | 792 KB |
test-02.txt | WA | 22 ms | 672 KB |
test-03.txt | WA | 23 ms | 924 KB |
test-04.txt | WA | 23 ms | 924 KB |
test-05.txt | WA | 24 ms | 788 KB |
test-06.txt | WA | 22 ms | 796 KB |
test-07.txt | WA | 24 ms | 700 KB |
test-08.txt | WA | 22 ms | 672 KB |
test-09.txt | WA | 25 ms | 800 KB |
test-10.txt | WA | 25 ms | 796 KB |
test-11.txt | WA | 23 ms | 800 KB |
test-12.txt | WA | 24 ms | 792 KB |
test-13.txt | WA | 22 ms | 796 KB |
test-14.txt | WA | 22 ms | 796 KB |
test-15.txt | WA | 25 ms | 796 KB |
test-16.txt | WA | 24 ms | 676 KB |
test-17.txt | WA | 23 ms | 792 KB |
test-18.txt | WA | 24 ms | 804 KB |
test-19.txt | WA | 23 ms | 676 KB |
test-20.txt | WA | 24 ms | 672 KB |