Submission #433762
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 << 28; for (tcc = 0; tcc < tc; tcc++) { 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 | D - 25個の整数 |
User | Hagentern |
Language | C++11 (GCC 4.9.2) |
Score | 0 |
Code Size | 2199 Byte |
Status | WA |
Exec Time | 25 ms |
Memory | 928 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) { ^
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 30 | 0 / 70 | ||||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt |
Subtask2 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt, test-2-01.txt, test-2-02.txt, test-2-03.txt, test-2-04.txt, test-2-05.txt, test-2-06.txt, test-2-07.txt, test-2-08.txt, test-2-09.txt, test-2-10.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample-01.txt | WA | 22 ms | 920 KB |
sample-02.txt | WA | 22 ms | 796 KB |
sample-03.txt | AC | 22 ms | 800 KB |
sample-04.txt | AC | 23 ms | 800 KB |
test-1-01.txt | AC | 22 ms | 800 KB |
test-1-02.txt | WA | 23 ms | 800 KB |
test-1-03.txt | WA | 24 ms | 804 KB |
test-1-04.txt | WA | 22 ms | 800 KB |
test-1-05.txt | WA | 22 ms | 928 KB |
test-1-06.txt | WA | 22 ms | 800 KB |
test-1-07.txt | AC | 22 ms | 800 KB |
test-1-08.txt | WA | 23 ms | 924 KB |
test-1-09.txt | WA | 24 ms | 704 KB |
test-1-10.txt | AC | 24 ms | 928 KB |
test-1-11.txt | AC | 23 ms | 796 KB |
test-1-12.txt | WA | 24 ms | 924 KB |
test-1-13.txt | AC | 24 ms | 800 KB |
test-1-14.txt | WA | 24 ms | 792 KB |
test-1-15.txt | WA | 25 ms | 804 KB |
test-2-01.txt | WA | 24 ms | 920 KB |
test-2-02.txt | WA | 24 ms | 924 KB |
test-2-03.txt | WA | 24 ms | 672 KB |
test-2-04.txt | WA | 22 ms | 928 KB |
test-2-05.txt | WA | 22 ms | 668 KB |
test-2-06.txt | WA | 24 ms | 924 KB |
test-2-07.txt | WA | 22 ms | 796 KB |
test-2-08.txt | WA | 23 ms | 924 KB |
test-2-09.txt | WA | 23 ms | 924 KB |
test-2-10.txt | WA | 24 ms | 672 KB |