結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 27 ms
8,792 KB
testcase_02 AC 10 ms
5,312 KB
testcase_03 AC 13 ms
6,040 KB
testcase_04 AC 10 ms
5,196 KB
testcase_05 AC 36 ms
10,308 KB
testcase_06 AC 32 ms
9,596 KB
testcase_07 AC 46 ms
12,552 KB
testcase_08 AC 26 ms
8,864 KB
testcase_09 AC 37 ms
10,388 KB
testcase_10 AC 34 ms
10,332 KB
testcase_11 AC 34 ms
10,356 KB
testcase_12 AC 37 ms
11,460 KB
testcase_13 AC 30 ms
9,860 KB
testcase_14 AC 45 ms
12,088 KB
testcase_15 AC 48 ms
13,012 KB
testcase_16 AC 17 ms
6,708 KB
testcase_17 AC 20 ms
7,072 KB
testcase_18 AC 18 ms
6,744 KB
testcase_19 AC 6 ms
4,644 KB
testcase_20 AC 24 ms
8,416 KB
testcase_21 AC 7 ms
5,000 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 15 ms
6,212 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,384 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 24 ms
8,072 KB
testcase_38 AC 17 ms
6,476 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]<<" ";
        cout<<endl;
    }
    return 0;
}
0