結果
| 問題 |
No.918 LISGRID
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2019-10-26 08:34:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,949 bytes |
| コンパイル時間 | 2,096 ms |
| コンパイル使用メモリ | 203,972 KB |
| 最終ジャッジ日時 | 2025-01-08 01:49:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 24 WA * 12 |
ソースコード
#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 + H, 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;
ts.sort(ord);
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");
}
}
はまやんはまやん