結果
問題 | No.918 LISGRID |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2019-10-26 08:37:52 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 2,975 bytes |
コンパイル時間 | 2,401 ms |
コンパイル使用メモリ | 209,272 KB |
実行使用メモリ | 13,496 KB |
最終ジャッジ日時 | 2023-10-11 23:43:36 |
合計ジャッジ時間 | 6,353 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 25 ms
9,408 KB |
testcase_02 | AC | 10 ms
5,644 KB |
testcase_03 | AC | 13 ms
6,192 KB |
testcase_04 | AC | 11 ms
5,520 KB |
testcase_05 | AC | 36 ms
10,516 KB |
testcase_06 | AC | 33 ms
9,928 KB |
testcase_07 | AC | 46 ms
12,916 KB |
testcase_08 | AC | 27 ms
9,196 KB |
testcase_09 | AC | 34 ms
10,848 KB |
testcase_10 | AC | 34 ms
10,796 KB |
testcase_11 | AC | 34 ms
10,736 KB |
testcase_12 | AC | 39 ms
11,440 KB |
testcase_13 | AC | 34 ms
9,800 KB |
testcase_14 | AC | 44 ms
12,364 KB |
testcase_15 | AC | 48 ms
13,496 KB |
testcase_16 | AC | 17 ms
7,108 KB |
testcase_17 | AC | 19 ms
7,372 KB |
testcase_18 | AC | 17 ms
7,204 KB |
testcase_19 | AC | 6 ms
4,752 KB |
testcase_20 | AC | 25 ms
8,548 KB |
testcase_21 | AC | 7 ms
4,996 KB |
testcase_22 | AC | 5 ms
4,348 KB |
testcase_23 | AC | 15 ms
6,780 KB |
testcase_24 | AC | 2 ms
4,352 KB |
testcase_25 | AC | 1 ms
4,348 KB |
testcase_26 | AC | 2 ms
4,348 KB |
testcase_27 | AC | 2 ms
4,348 KB |
testcase_28 | AC | 1 ms
4,352 KB |
testcase_29 | AC | 1 ms
4,348 KB |
testcase_30 | AC | 2 ms
4,348 KB |
testcase_31 | AC | 1 ms
4,348 KB |
testcase_32 | AC | 2 ms
4,348 KB |
testcase_33 | AC | 2 ms
4,348 KB |
testcase_34 | AC | 3 ms
4,348 KB |
testcase_35 | AC | 4 ms
4,348 KB |
testcase_36 | AC | 2 ms
4,348 KB |
testcase_37 | AC | 26 ms
8,612 KB |
testcase_38 | AC | 17 ms
6,924 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- // トポロジカルソートする O(n) // 返り値が true の時のみ意味を持つ(false の場合は閉路) struct TopologicalSort { vector<vector<int>> E; TopologicalSort(int N) { E.resize(N); } void add_edge(int a, int b) { E[a].push_back(b); } bool visit(int v, vector<int>& order, vector<int>& color) { color[v] = 1; for (int u : E[v]) { if (color[u] == 2) continue; if (color[u] == 1) return false; if (!visit(u, order, color)) return false; } order.push_back(v); color[v] = 2; return true; } bool sort(vector<int>& order) { int n = E.size(); vector<int> color(n); for (int u = 0; u < n; u++) if (!color[u] && !visit(u, order, color)) return false; reverse(order.begin(), order.end()); return true; } }; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int H, W, A[404], B[404]; int ans[404][404]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> H >> W; rep(y, 0, H) cin >> A[y]; rep(x, 0, W) cin >> B[x]; sort(A, A + H, greater<int>()); sort(B, B + W, greater<int>()); TopologicalSort ts(H * W); rep(y, 0, H) { rep(x, 0, A[y] - 1) ts.add_edge(y * W + x, y * W + x + 1); rep(x, A[y] - 1, W - 1) ts.add_edge(y * W + x + 1, y * W + x); } rep(x, 0, W) { rep(y, 0, B[x] - 1) ts.add_edge(y * W + x, (y + 1) * W + x); rep(y, B[x] - 1, H - 1) ts.add_edge((y + 1) * W + x, y * W + x); } vector<int> ord; bool res = ts.sort(ord); assert(res); int num = 1; fore(i, ord) { int x = i % W; int y = i / W; ans[y][x] = num; num++; } rep(y, 0, H) { rep(x, 0, W) { if(x) printf(" "); printf("%d", ans[y][x]); } printf("\n"); } }