結果

問題 No.918 LISGRID
ユーザー tempura_pptempura_pp
提出日時 2019-06-29 14:12:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 104,960 KB
実行使用メモリ 13,140 KB
最終ジャッジ日時 2023-09-14 23:13:07
合計ジャッジ時間 5,166 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 26 ms
8,796 KB
testcase_02 AC 9 ms
5,636 KB
testcase_03 AC 12 ms
5,816 KB
testcase_04 AC 10 ms
5,196 KB
testcase_05 AC 32 ms
10,120 KB
testcase_06 AC 30 ms
9,708 KB
testcase_07 AC 45 ms
12,560 KB
testcase_08 AC 26 ms
8,716 KB
testcase_09 AC 33 ms
10,656 KB
testcase_10 AC 33 ms
10,500 KB
testcase_11 AC 33 ms
10,684 KB
testcase_12 AC 36 ms
11,164 KB
testcase_13 AC 29 ms
9,656 KB
testcase_14 AC 38 ms
11,896 KB
testcase_15 AC 45 ms
13,140 KB
testcase_16 AC 17 ms
6,996 KB
testcase_17 AC 18 ms
6,992 KB
testcase_18 AC 17 ms
6,736 KB
testcase_19 AC 6 ms
4,508 KB
testcase_20 AC 25 ms
8,388 KB
testcase_21 AC 8 ms
4,944 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 14 ms
6,276 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 25 ms
8,032 KB
testcase_38 AC 16 ms
6,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int h,w;
    cin>>h>>w;
    int a[h],b[w];
    rep(i,h)cin>>a[i];
    sort(a,a+h);
    rep(j,w)cin>>b[j];
    sort(b,b+w);
    vector<int> v[h*w];
    vector<int> cnt(h*w);
    rep(i,h){
        rep(j,a[i]-1){
            v[i*w+j].push_back(i*w+j+1);
            ++cnt[i*w+j+1];
        }
        REP(j,a[i]-1,w-1){
            v[i*w+j+1].push_back(i*w+j);
            ++cnt[i*w+j];

        }
    }
    rep(j,w){
        rep(i,b[j]-1){
            v[i*w+j].push_back((i+1)*w+j);
            ++cnt[(i+1)*w+j];

        }
        REP(i,b[j]-1,h-1){
            v[(i+1)*w+j].push_back(i*w+j);
            ++cnt[i*w+j];

        }
    }
    vector<int> ans(h*w);
    queue<int> q;
    int idx = 0;
    rep(i,h*w){
        if(cnt[i]==0){
            q.push(i);
        }
    }
    while(q.size()){
        int cur = q.front();q.pop();
        ans[cur]=++idx;
        for(auto to : v[cur]){
            if(--cnt[to]==0)q.push(to);
        }
    }
    rep(i,h){
        rep(j,w)cout<<ans[w*i+j]<<" ";
    }
    return 0;
}
0