結果

問題 No.918 LISGRID
ユーザー snow39snow39
提出日時 2019-10-26 13:10:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 101,728 KB
実行使用メモリ 13,252 KB
最終ジャッジ日時 2023-10-12 07:10:23
合計ジャッジ時間 7,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,156 KB
testcase_01 AC 27 ms
10,728 KB
testcase_02 AC 11 ms
8,372 KB
testcase_03 AC 14 ms
8,912 KB
testcase_04 AC 12 ms
8,264 KB
testcase_05 AC 33 ms
11,424 KB
testcase_06 AC 31 ms
10,920 KB
testcase_07 AC 44 ms
12,748 KB
testcase_08 AC 25 ms
10,464 KB
testcase_09 AC 32 ms
11,396 KB
testcase_10 AC 32 ms
11,340 KB
testcase_11 AC 33 ms
11,436 KB
testcase_12 AC 35 ms
12,048 KB
testcase_13 AC 29 ms
11,140 KB
testcase_14 AC 40 ms
12,644 KB
testcase_15 AC 47 ms
13,252 KB
testcase_16 AC 18 ms
9,268 KB
testcase_17 AC 19 ms
9,604 KB
testcase_18 AC 19 ms
9,560 KB
testcase_19 AC 8 ms
7,940 KB
testcase_20 AC 23 ms
10,216 KB
testcase_21 AC 9 ms
8,224 KB
testcase_22 AC 7 ms
7,728 KB
testcase_23 AC 16 ms
8,908 KB
testcase_24 AC 4 ms
7,220 KB
testcase_25 AC 3 ms
7,444 KB
testcase_26 AC 4 ms
7,220 KB
testcase_27 AC 4 ms
7,136 KB
testcase_28 AC 3 ms
7,132 KB
testcase_29 AC 4 ms
7,280 KB
testcase_30 AC 4 ms
7,220 KB
testcase_31 AC 3 ms
7,152 KB
testcase_32 AC 3 ms
7,104 KB
testcase_33 AC 4 ms
7,104 KB
testcase_34 AC 4 ms
7,308 KB
testcase_35 AC 5 ms
7,584 KB
testcase_36 AC 4 ms
7,192 KB
testcase_37 AC 24 ms
9,920 KB
testcase_38 AC 16 ms
9,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

vector<int> g[401*401];
int ind[401*401];

int main(){
  int H,W;
  cin>>H>>W;
  vector<int> A(H),B(W);
  rep(i,H) cin>>A[i];
  rep(i,W) cin>>B[i];

  sort(A.begin(),A.end());
  sort(B.begin(),B.end());

  for(int i=0;i<H;i++){
    for(int j=0;j<A[i]-1;j++){
      g[i*W+j].push_back(i*W+j+1);
      ind[i*W+j+1]++;
    }
    for(int j=A[i];j<W;j++){
      g[i*W+j].push_back(i*W+j-1);
      ind[i*W+j-1]++;
    }
  }

  for(int i=0;i<W;i++){
    for(int j=0;j<B[i]-1;j++){
      g[j*W+i].push_back((j+1)*W+i);
      ind[(j+1)*W+i]++;
    }
    for(int j=B[i];j<H;j++){
      g[j*W+i].push_back((j-1)*W+i);
      ind[(j-1)*W+i]++;
    }
  }

  queue<int> Q;
  for(int i=0;i<W*H;i++){
    if(ind[i]==0) Q.push(i);
  }

  int val=1;
  vector<int> ans(H*W,0);
  while(!Q.empty()){
    int tp=Q.front();
    Q.pop();

    ans[tp]=val++;
    for(auto nex:g[tp]){
      ind[nex]--;
      if(ind[nex]==0) Q.push(nex);
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<ans[i*W+j]<<" ";
    }
    cout<<endl;
  }

  return 0;
}
0