結果

問題 No.918 LISGRID
ユーザー chocoruskchocorusk
提出日時 2019-10-26 00:28:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,973 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 114,404 KB
実行使用メモリ 24,560 KB
最終ジャッジ日時 2023-10-11 12:39:11
合計ジャッジ時間 5,303 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,880 KB
testcase_01 AC 43 ms
19,804 KB
testcase_02 AC 19 ms
15,784 KB
testcase_03 AC 22 ms
16,820 KB
testcase_04 AC 20 ms
15,972 KB
testcase_05 AC 57 ms
21,348 KB
testcase_06 AC 53 ms
20,628 KB
testcase_07 AC 76 ms
23,892 KB
testcase_08 AC 45 ms
19,596 KB
testcase_09 AC 56 ms
21,412 KB
testcase_10 AC 59 ms
21,364 KB
testcase_11 AC 59 ms
21,488 KB
testcase_12 AC 60 ms
21,996 KB
testcase_13 AC 54 ms
20,436 KB
testcase_14 AC 74 ms
23,620 KB
testcase_15 AC 80 ms
24,560 KB
testcase_16 AC 31 ms
17,544 KB
testcase_17 AC 32 ms
17,936 KB
testcase_18 AC 32 ms
17,492 KB
testcase_19 AC 13 ms
15,168 KB
testcase_20 AC 42 ms
19,124 KB
testcase_21 AC 15 ms
15,388 KB
testcase_22 AC 11 ms
14,812 KB
testcase_23 AC 27 ms
16,932 KB
testcase_24 AC 7 ms
13,868 KB
testcase_25 AC 6 ms
13,636 KB
testcase_26 AC 5 ms
13,792 KB
testcase_27 AC 5 ms
13,600 KB
testcase_28 AC 5 ms
13,672 KB
testcase_29 AC 5 ms
13,588 KB
testcase_30 AC 5 ms
13,676 KB
testcase_31 AC 5 ms
13,800 KB
testcase_32 AC 5 ms
13,724 KB
testcase_33 AC 5 ms
13,608 KB
testcase_34 AC 7 ms
13,912 KB
testcase_35 AC 8 ms
14,284 KB
testcase_36 AC 6 ms
13,736 KB
testcase_37 AC 41 ms
19,076 KB
testcase_38 AC 26 ms
17,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int h, w;
int a[404], b[404];
int n;
bool used[200020];
int cmp[200020];
vector<int> g[200020], gr[200020];
vector<int> vs;
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
	vs.push_back(x);
}
void rdfs(int v, int k){
	used[v]=1;
	cmp[v]=k;
	for(auto y:gr[v]){
		if(!used[y]) rdfs(y, k);
	}
}
int scc(){
	fill(used, used+n, 0);
	vs.clear();
	for(int i=0; i<n; i++){
		if(!used[i]) dfs(i);
	}
	fill(used, used+n, 0);
	int k=0;
	for(int i=vs.size()-1; i>=0; i--){
		if(!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}
void add(int x, int y){
    g[x].push_back(y);
    gr[y].push_back(x);
}
int main()
{
	cin>>h>>w;
    n=h*w;
    for(int i=0; i<h; i++){
        cin>>a[i];
    }
    for(int i=0; i<w; i++){
        cin>>b[i];
    }
    sort(a, a+h);
    sort(b, b+w);
    for(int i=0; i<h; i++){
        for(int j=0; j<a[i]-1; j++){
            add(i*w+j, i*w+j+1);
        }
        for(int j=w-1; j>=a[i]+1; j--){
            add(i*w+j, i*w+j-1);
        }
        if(a[i]<w) add(i*w+a[i], i*w);
    }
    for(int i=0; i<w; i++){
        for(int j=0; j<b[i]-1; j++){
            add(j*w+i, (j+1)*w+i);
        }
        for(int j=h-1; j>=b[i]+1; j--){
            add(j*w+i, (j-1)*w+i);
        }
        if(b[i]<h) add(b[i]*w+i, i);
    }
    int k=scc();
    assert(k==h*w);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout<<cmp[i*w+j]+1<<" ";
        }
        cout<<endl;
    }
    return 0;
}
0