結果
問題 | No.2958 Placing Many L-s |
ユーザー | 👑 binap |
提出日時 | 2024-05-21 08:16:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,663 bytes |
コンパイル時間 | 4,461 ms |
コンパイル使用メモリ | 266,804 KB |
実行使用メモリ | 38,912 KB |
最終ジャッジ日時 | 2024-11-08 20:50:28 |
合計ジャッジ時間 | 8,858 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 513 ms
5,248 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} int solve(){ int h, w; cin >> h >> w; int n = h * w; if(n % 4 != 0){ cout << "-1\n"; return 0; } int k = n / 4; vector<int> s(n, 0); bool success = false; auto f = [&](int y, int x){ if(y < 0 || y >= h || x < 0 || x >= w) return -1; return y * w + x; }; auto out = [&](){ cout << k << "\n"; rep(y, h){ rep(x, w) cout << s[f(y, x)] << ' '; cout << "\n"; } }; vector<vector<int>> dy = {{0, 0, 0, 1}, {0, 1, 1, 1}, {0, 0, 0, 1}, {0, 0, 1, 2}, {0, 1, 2, 2}, {0, 0, 1, 2}, {0, 1, 2, 2}, {0, 1, 1, 1}}; vector<vector<int>> dx = {{0, 1, 2, 2}, {0, 0, 1, 2}, {0, 1, 2, 0}, {0, 1, 1, 1}, {0, 0, 0, 1}, {0, 1, 2, 3}, {0, 0, 0, -1}, {0, 0, -1, -2}}; auto next = [&](int pos){ int y = pos / w; int x = pos % w; vector<vector<int>> cand; rep(t, 8){ bool ok = true; vector<int> v; rep(i, 4){ int pos_new = f(y + dy[t][i], x + dx[t][i]); if(pos_new == -1){ok = false; break;} if(s[pos_new] != 0){ok = false; break;} v.push_back(pos_new); } if(ok) cand.push_back(v); } return cand; }; auto dfs = [&](auto dfs, int pos, int num) -> void{ if(success) return; if(pos == n){ out(); success = true; return; } if(s[pos] == 0){ vector<vector<int>> cand = next(pos); for(auto& v : cand){ for(auto pos_new : v) s[pos_new] = num; dfs(dfs, pos + 1, num + 1); for(auto pos_new : v) s[pos_new] = 0; } }else dfs(dfs, pos + 1, num); }; dfs(dfs, 0, 1); if(!success) cout << "-1\n"; return 0; } int main(){ int t; cin >> t; rep(_, t) solve(); }