結果

問題 No.918 LISGRID
ユーザー やむなくやむなく
提出日時 2019-10-25 23:01:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 2,405 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 186,068 KB
実行使用メモリ 13,468 KB
最終ジャッジ日時 2023-10-11 07:52:50
合計ジャッジ時間 5,754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 28 ms
9,316 KB
testcase_02 AC 10 ms
5,356 KB
testcase_03 AC 14 ms
6,436 KB
testcase_04 AC 11 ms
5,464 KB
testcase_05 AC 35 ms
10,772 KB
testcase_06 AC 32 ms
10,072 KB
testcase_07 AC 46 ms
12,960 KB
testcase_08 AC 28 ms
9,056 KB
testcase_09 AC 36 ms
10,828 KB
testcase_10 AC 35 ms
10,860 KB
testcase_11 AC 36 ms
10,812 KB
testcase_12 AC 39 ms
11,480 KB
testcase_13 AC 31 ms
10,128 KB
testcase_14 AC 43 ms
12,384 KB
testcase_15 AC 48 ms
13,468 KB
testcase_16 AC 18 ms
7,452 KB
testcase_17 AC 19 ms
7,488 KB
testcase_18 AC 18 ms
7,216 KB
testcase_19 AC 7 ms
4,556 KB
testcase_20 AC 26 ms
8,576 KB
testcase_21 AC 8 ms
4,928 KB
testcase_22 AC 6 ms
4,352 KB
testcase_23 AC 16 ms
6,544 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1 ms
4,480 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 25 ms
8,572 KB
testcase_38 AC 17 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by yamunaku on 2019/10/25.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int h, w;
    cin >> h >> w;
    vi a(h), b(w);
    rep(i, h) cin >> a[i], a[i]--;
    rep(j, w) cin >> b[j], b[j]--;
    sort(all(a),greater<int>()), sort(all(b),greater<int>());
    vector<vector<vector<pair<int, int>>>> e(h, vector<vector<pair<int, int>>>(w));
    vector<vector<int>> deg(h, vector<int>(w, 0));
    rep(i, h){
        rep(j, w){
            if(i>0){
                if(i<=b[j]){
                    e[i][j].push_back({i-1, j});
                    deg[i-1][j]++;
                }
            }
            if(i<h-1){
                if(i>=b[j]){
                    e[i][j].push_back({i+1, j});
                    deg[i+1][j]++;
                }
            }
            if(j>0){
                if(j<=a[i]){
                    e[i][j].push_back({i, j-1});
                    deg[i][j-1]++;
                }
            }
            if(j<w-1){
                if(j>=a[i]){
                    e[i][j].push_back({i, j+1});
                    deg[i][j+1]++;
                }
            }
        }
    }
    int t = h * w;
    mti ans(h, vi(w, -1));
    queue<pair<int, int>> q;
    rep(i,h){
        rep(j,w){
            if(deg[i][j]==0) q.push({i,j});
        }
    }
    while(!q.empty()){
        auto now = q.front();
        q.pop();
        ans[now.first][now.second] = t;
        t--;
        for(auto &nx:e[now.first][now.second]){
            deg[nx.first][nx.second]--;
            if(deg[nx.first][nx.second] == 0) q.push(nx);
        }
    }
    rep(i, h){
        rep(j, w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
0