結果

問題 No.918 LISGRID
ユーザー face4face4
提出日時 2019-12-14 15:08:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 12,600 KB
最終ジャッジ日時 2023-09-10 11:52:01
合計ジャッジ時間 8,570 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 25 ms
8,956 KB
testcase_02 AC 9 ms
5,324 KB
testcase_03 AC 12 ms
6,000 KB
testcase_04 AC 9 ms
5,448 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 WA -
testcase_30 AC 1 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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.rbegin(), b.rend());
    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