結果
問題 | No.2263 Perms |
ユーザー | k1suxu |
提出日時 | 2023-04-08 20:30:49 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,558 bytes |
コンパイル時間 | 4,247 ms |
コンパイル使用メモリ | 273,140 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2024-10-03 17:32:23 |
合計ジャッジ時間 | 10,181 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | RE | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | WA | - |
testcase_10 | RE | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
コンパイルメッセージ
main.cpp: In instantiation of 'solve()::<lambda(long long int, auto:55)> [with auto:55 = solve()::<lambda(long long int, auto:55)>]': main.cpp:125:16: required from here main.cpp:107:13: warning: ignoring return value of 'constexpr std::vector<bool, _Alloc>::reference std::vector<bool, _Alloc>::operator[](size_type) [with _Alloc = std::allocator<bool>; reference = std::vector<bool>::reference; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] 107 | used[e%n]; | ^~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:65, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/functional:62, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:71, from main.cpp:5: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:1035:7: note: declared here 1035 | operator[](size_type __n) | ^~~~~~~~
ソースコード
// #pragma GCC target("avx") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) #define FOR(n) for(int i = 0; i < (int)n; i++) #define repi(i,a,b) for(int i = (int)a; i < (int)b; i++) #define all(x) x.begin(),x.end() //#define mp make_pair #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define pii pair<int,int> #define vpii vector<pair<int,int>> template<typename T> void chmax(T &a, const T &b) {a = (a > b? a : b);} template<typename T> void chmin(T &a, const T &b) {a = (a < b? a : b);} using ll = long long; using ld = long double; using ull = unsigned long long; const ll INF = numeric_limits<long long>::max() / 2; const ld pi = 3.1415926535897932384626433832795028; const ll mod = 998244353; int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; #define int long long void solve() { int n, m; cin >> n >> m; vvi a(n, vi(n)); rep(i, n) rep(j, n) cin >> a[i][j]; vi th(n, 0), tw(n, 0); rep(i, n) { rep(j, n) { th[i] += a[i][j]; tw[j] += a[i][j]; } } vi repre; repre.push_back(*min_element(all(th))); repre.push_back(*max_element(all(th))); repre.push_back(*min_element(all(tw))); repre.push_back(*max_element(all(tw))); if(*max_element(all(repre)) != *min_element(all(repre))) { cout << -1 << endl; return; } auto encode = [&](int x, int y) -> int { return x * n + y; }; auto decode = [&](int xy) -> pii { return make_pair(xy/n, xy%n); }; vi b(n*n); rep(i, n) rep(j, n) { b[encode(i, j)] = a[i][j]; } vector<unordered_set<int>> g(n*n); rep(i, n-1) { rep(j, n) { rep(k, n) if(j != k && a[i+1][k] != 0) { g[encode(i, j)].insert(encode(i+1, k)); // cout << encode(i, j) << "->" << encode(i+1, k) << endl; } } } stack<int> st; vector<bool> used(n, false); auto dfs = [&](int v, auto self) -> bool { st.push(v); vi ers; bool flag = false; for(auto e : g[v]) if(!used[e%n]) { used[e%n] = true; if(self(e, self)) { b[e]--; if(b[e] == 0) { ers.push_back(e); } flag = true; break; }else { ers.push_back(e); } used[e%n]; } for(auto e : ers) g[v].erase(e); if(decode(v).first == n-1 || flag) { return true; }else { st.pop(); return false; } }; vvi perm; rep(i, n) { while(b[i] > 0) { rep(j, n) used[j] = (j == i); dfs(i, dfs); perm.push_back({}); while(!st.empty()) { // cout << decode(st.top()).first << " " << decode(st.top()).second << endl; perm.back().push_back(st.top()); st.pop(); } b[i]--; } } assert(perm.size() == m); for(auto e : perm) { vi p(n); for(auto f : e) { pii now = decode(f); p[now.first] = now.second; } for(auto f : p) cout << f+1 << " "; cout << "\n"; } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }