結果

問題 No.918 LISGRID
ユーザー face4face4
提出日時 2019-12-14 15:09:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,318 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 13,108 KB
最終ジャッジ日時 2023-09-10 11:52:07
合計ジャッジ時間 4,627 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 26 ms
8,872 KB
testcase_02 AC 9 ms
5,256 KB
testcase_03 AC 13 ms
5,912 KB
testcase_04 AC 9 ms
5,256 KB
testcase_05 AC 35 ms
10,424 KB
testcase_06 AC 32 ms
9,748 KB
testcase_07 AC 45 ms
12,472 KB
testcase_08 AC 27 ms
8,688 KB
testcase_09 AC 34 ms
10,400 KB
testcase_10 AC 35 ms
10,368 KB
testcase_11 AC 36 ms
10,504 KB
testcase_12 AC 36 ms
11,236 KB
testcase_13 AC 28 ms
9,576 KB
testcase_14 AC 40 ms
11,996 KB
testcase_15 AC 47 ms
13,108 KB
testcase_16 AC 17 ms
6,928 KB
testcase_17 AC 19 ms
7,388 KB
testcase_18 AC 16 ms
6,880 KB
testcase_19 AC 6 ms
4,588 KB
testcase_20 AC 24 ms
8,404 KB
testcase_21 AC 7 ms
5,000 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 14 ms
6,432 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 24 ms
8,184 KB
testcase_38 AC 15 ms
6,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<int> a(h), b(w);
    for(int i = 0; i < h; i++)  cin >> a[i];
    for(int i = 0; i < w; i++)  cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<int> v[h*w], indeg(h*w, 0);
    for(int i = 0; i < h; i++){
        for(int j = 0; j+1 < w; j++){
            int x = i*w+j, y = i*w+j+1;
            if(j+1 < a[i])  v[y].push_back(x), indeg[x]++;
            else            v[x].push_back(y), indeg[y]++;
        }
    }
    for(int j = 0; j < w; j++){
        for(int i = 0; i+1 < h; i++){
            int x = i*w+j, y = (i+1)*w+j;
            if(i+1 < b[j])  v[y].push_back(x), indeg[x]++;
            else            v[x].push_back(y), indeg[y]++;
        }
    }
    queue<int> q;
    for(int i = 0; i < h*w; i++)    if(indeg[i]==0) q.push(i);
    int ans[h][w], val = h*w;
    while(!q.empty()){
        int x = q.front();  q.pop();
        ans[x/w][x%w] = val--;
        for(int next : v[x]){
            indeg[next]--;
            if(indeg[next] == 0)    q.push(next);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans[i][j] << " \n"[j==w-1];
        }
    }
    return 0;
}
0