結果
| 問題 |
No.918 LISGRID
|
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2019-10-26 19:20:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 2,000 ms |
| コード長 | 1,647 bytes |
| コンパイル時間 | 1,839 ms |
| コンパイル使用メモリ | 179,040 KB |
| 実行使用メモリ | 16,512 KB |
| 最終ジャッジ日時 | 2024-09-14 16:12:02 |
| 合計ジャッジ時間 | 6,473 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end
vector<P> edge[410][410]; int cnt[410][410]={};
int ans[410][410];
int main(){
int h,w; scanf("%d%d",&h,&w);
vector<int> a(h),b(w);
rep(i,0,h)scanf("%d",&a[i]);
rep(i,0,w)scanf("%d",&b[i]);
sort(ALL(a)); sort(ALL(b));
rep(i,0,h){
rep(j,0,w-a[i])edge[i][j].push_back({i,j+1}),cnt[i][j+1]++;
rep(j,w-a[i],w-1)edge[i][j+1].push_back({i,j}),cnt[i][j]++;
}
rep(j,0,w){
rep(i,0,h-b[j])edge[i][j].push_back({i+1,j}),cnt[i+1][j]++;
rep(i,h-b[j],h-1)edge[i+1][j].push_back({i,j}),cnt[i][j]++;
}
queue<P> q; int d=h*w;
rep(i,0,h)rep(j,0,w)if(!cnt[i][j])q.push({i,j});
while(!q.empty()){
auto now=q.front(); q.pop();
int x=now.first,y=now.second;
ans[x][y]=d; d--;
for(auto nxt:edge[x][y]){
cnt[nxt.first][nxt.second]--;
if(!cnt[nxt.first][nxt.second])q.push({nxt});
}
}
rep(i,0,h){
rep(j,0,w)printf("%d ",ans[i][j]);
puts("");
}
return 0;
}
tko919