結果
問題 | No.918 LISGRID |
ユーザー |
|
提出日時 | 2019-12-14 15:09:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 1,318 bytes |
コンパイル時間 | 985 ms |
コンパイル使用メモリ | 82,940 KB |
実行使用メモリ | 13,172 KB |
最終ジャッジ日時 | 2024-06-28 03:11:59 |
合計ジャッジ時間 | 4,166 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<queue> using namespace std; int main(){ int h, w; cin >> h >> w; vector<int> a(h), b(w); for(int i = 0; i < h; i++) cin >> a[i]; for(int i = 0; i < w; i++) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector<int> v[h*w], indeg(h*w, 0); for(int i = 0; i < h; i++){ for(int j = 0; j+1 < w; j++){ int x = i*w+j, y = i*w+j+1; if(j+1 < a[i]) v[y].push_back(x), indeg[x]++; else v[x].push_back(y), indeg[y]++; } } for(int j = 0; j < w; j++){ for(int i = 0; i+1 < h; i++){ int x = i*w+j, y = (i+1)*w+j; if(i+1 < b[j]) v[y].push_back(x), indeg[x]++; else v[x].push_back(y), indeg[y]++; } } queue<int> q; for(int i = 0; i < h*w; i++) if(indeg[i]==0) q.push(i); int ans[h][w], val = h*w; while(!q.empty()){ int x = q.front(); q.pop(); ans[x/w][x%w] = val--; for(int next : v[x]){ indeg[next]--; if(indeg[next] == 0) q.push(next); } } for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cout << ans[i][j] << " \n"[j==w-1]; } } return 0; }