Submission #1131248
Source Code Expand
// Template {{{ #include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef long long LL; #ifdef LOCAL #include "contest.h" #else #define error(args...) #endif const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; inline bool valid(int x, int w) { return 0 <= x && x < w; } void iostream_init() { ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(12); } //}}} int N; int encode(bool state[3][3]) { int s = 0; REP(i, N) REP(j, N) { s = s << 1 | (state[i][j] ? 1 : 0); } return s; } void decode(int s, bool state[3][3]) { for(int i = N-1; i >= 0; i--) { for(int j = N-1; j >= 0; j--) { state[i][j] = (s & 1); s >>= 1; } } } int main(){ iostream_init(); while(cin >> N) { assert(N <= 3); bool grid[3][3] = {}; REP(i, N) { string s; cin >> s; REP(j, N) { grid[i][j] = s[j] == '#'; } } queue<int> que; int dist[1 << 10] = {}; int start = encode(grid); memset(dist, -1, sizeof(dist)); dist[start] = 0; que.push(start); int ans = -1; while(!que.empty()) { int s = que.front(); que.pop(); bool state[3][3]; decode(s, state); bool ok = true; REP(i, N) REP(j, N) if(!state[i][j]) ok = false; if(ok) { ans = dist[s]; break; } REP(i, N){ REP(j, N) { bool nstate[3][3] = {}; REP(x, N) REP(y, N) nstate[y][x] = state[y][x]; bool d[3] = {}; REP(k, N) d[k] = state[i][k]; REP(k, N) { nstate[k][j] = d[k]; } int ns = encode(nstate); if(dist[ns] == -1) { dist[ns] = dist[s] + 1; que.push(ns); } } } } cout << ans << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Row to Column |
User | ichyo |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 2309 Byte |
Status | RE |
Exec Time | 429 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 0 / 1000 | ||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
Subtask | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt, 2_16.txt, 2_17.txt, 2_18.txt, 2_19.txt, 2_20.txt, 2_21.txt, 2_22.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
0_04.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 1 ms | 256 KB |
1_04.txt | AC | 1 ms | 256 KB |
1_05.txt | AC | 1 ms | 256 KB |
1_06.txt | AC | 1 ms | 256 KB |
1_07.txt | AC | 1 ms | 256 KB |
1_08.txt | AC | 1 ms | 256 KB |
1_09.txt | AC | 1 ms | 256 KB |
1_10.txt | AC | 1 ms | 256 KB |
1_11.txt | AC | 1 ms | 256 KB |
1_12.txt | AC | 1 ms | 256 KB |
1_13.txt | AC | 1 ms | 256 KB |
1_14.txt | AC | 1 ms | 256 KB |
2_00.txt | RE | 429 ms | 256 KB |
2_01.txt | RE | 96 ms | 256 KB |
2_02.txt | RE | 97 ms | 256 KB |
2_03.txt | RE | 97 ms | 256 KB |
2_04.txt | RE | 96 ms | 256 KB |
2_05.txt | RE | 96 ms | 256 KB |
2_06.txt | RE | 97 ms | 256 KB |
2_07.txt | RE | 98 ms | 256 KB |
2_08.txt | RE | 96 ms | 256 KB |
2_09.txt | RE | 97 ms | 256 KB |
2_10.txt | RE | 97 ms | 256 KB |
2_11.txt | RE | 96 ms | 256 KB |
2_12.txt | RE | 97 ms | 256 KB |
2_13.txt | RE | 97 ms | 256 KB |
2_14.txt | RE | 98 ms | 256 KB |
2_15.txt | RE | 97 ms | 256 KB |
2_16.txt | RE | 96 ms | 256 KB |
2_17.txt | RE | 97 ms | 256 KB |
2_18.txt | RE | 98 ms | 256 KB |
2_19.txt | RE | 96 ms | 256 KB |
2_20.txt | RE | 96 ms | 256 KB |
2_21.txt | RE | 98 ms | 256 KB |
2_22.txt | RE | 96 ms | 256 KB |