結果
| 問題 |
No.918 LISGRID
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-10-25 22:06:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,171 bytes |
| コンパイル時間 | 2,503 ms |
| コンパイル使用メモリ | 219,332 KB |
| 最終ジャッジ日時 | 2025-01-08 01:15:50 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 2 RE * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct TopologicalSort{
vector< set<int> > G;
vector<int> used,indeg,ps;
TopologicalSort(){}
TopologicalSort(int n):G(n),used(n,0),indeg(n,0){}
void add_edge(int s,int t){
G[s].emplace(t);
indeg[t]++;
}
void bfs(int s){
queue<int> que;
que.emplace(s);
used[s]=1;
while(!que.empty()){
int v=que.front();que.pop();
ps.emplace_back(v);
for(int u:G[v]){
indeg[u]--;
if(indeg[u]==0&&!used[u]){
used[u]=1;
que.emplace(u);
}
}
}
}
vector<int> build(){
int n=G.size();
for(int i=0;i<n;i++)
if(indeg[i]==0&&!used[i]) bfs(i);
return ps;
}
};
//INSERT ABOVE HERE
signed main(){
int h,w;
cin>>h>>w;
vector<int> as(h),bs(w);
for(int i=0;i<h;i++) cin>>as[i];
for(int i=0;i<w;i++) cin>>bs[i];
sort(as.begin(),as.end());
sort(bs.begin(),bs.end());
TopologicalSort G(h*w);
auto idx=[&](int y,int x){return y*w+x;};
for(int i=0;i<h;i++){
vector<int> vs(w);
for(int j=0;j<w;j++) vs[j]=w-(j+1);
for(int j=w-as[i],k=0;j<w;j++) vs[j]=k++;
using P = pair<int, int>;
vector<P> vp;
for(int j=0;j<w;j++)
vp.emplace_back(vs[j],j);
sort(vp.begin(),vp.end());
for(int j=0;j+1<w;j++)
G.add_edge(idx(i,vp[j].second),idx(i,vp[j+1].second));
}
for(int j=0;j<w;j++){
vector<int> vs(h);
for(int i=0;i<h;i++) vs[i]=h-(i+1);
for(int i=h-bs[j],k=0;i<h;i++) vs[i]=k++;
using P = pair<int, int>;
vector<P> vp;
for(int i=0;i<h;i++)
vp.emplace_back(vs[i],i);
sort(vp.begin(),vp.end());
for(int i=0;i+1<h;i++)
G.add_edge(idx(vp[i].second,j),idx(vp[i+1].second,j));
}
auto ps=G.build();
vector< vector<int> > ans(h,vector<int>(w,0));
for(int i=0;i<h*w;i++)
ans[ps[i]/w][ps[i]%w]=i+1;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(j) cout<<" ";
cout<<ans[i][j];
}
cout<<endl;
}
return 0;
}
beet