結果
問題 |
No.918 LISGRID
|
ユーザー |
|
提出日時 | 2019-12-14 15:08:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,320 bytes |
コンパイル時間 | 927 ms |
コンパイル使用メモリ | 86,272 KB |
実行使用メモリ | 12,564 KB |
最終ジャッジ日時 | 2024-06-28 03:11:55 |
合計ジャッジ時間 | 6,996 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 26 |
ソースコード
#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.rbegin(), b.rend()); 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; }