結果

問題 No.918 LISGRID
ユーザー beetbeet
提出日時 2019-10-25 22:06:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,171 bytes
コンパイル時間 2,682 ms
コンパイル使用メモリ 225,052 KB
実行使用メモリ 27,760 KB
最終ジャッジ日時 2023-10-11 04:37:26
合計ジャッジ時間 13,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 57 ms
18,052 KB
testcase_02 AC 18 ms
8,120 KB
testcase_03 AC 26 ms
10,292 KB
testcase_04 AC 20 ms
8,564 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 RE -
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 RE -
testcase_33 AC 1 ms
4,352 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0