結果

問題 No.918 LISGRID
ユーザー theory_and_metheory_and_me
提出日時 2019-10-26 02:46:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,305 bytes
コンパイル時間 3,259 ms
コンパイル使用メモリ 178,020 KB
実行使用メモリ 14,332 KB
最終ジャッジ日時 2023-10-11 15:37:19
合計ジャッジ時間 7,028 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 26 ms
10,176 KB
testcase_02 AC 11 ms
6,212 KB
testcase_03 AC 13 ms
7,132 KB
testcase_04 AC 11 ms
6,432 KB
testcase_05 AC 33 ms
11,412 KB
testcase_06 AC 30 ms
10,932 KB
testcase_07 AC 51 ms
13,720 KB
testcase_08 AC 26 ms
9,880 KB
testcase_09 AC 36 ms
11,796 KB
testcase_10 AC 36 ms
11,796 KB
testcase_11 AC 34 ms
11,688 KB
testcase_12 AC 39 ms
12,396 KB
testcase_13 AC 31 ms
10,652 KB
testcase_14 AC 44 ms
13,300 KB
testcase_15 AC 57 ms
14,332 KB
testcase_16 AC 18 ms
7,992 KB
testcase_17 AC 19 ms
8,332 KB
testcase_18 AC 18 ms
8,060 KB
testcase_19 AC 7 ms
5,400 KB
testcase_20 AC 24 ms
9,296 KB
testcase_21 AC 9 ms
5,976 KB
testcase_22 AC 6 ms
5,092 KB
testcase_23 AC 15 ms
7,572 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,372 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 3 ms
4,352 KB
testcase_28 AC 2 ms
4,364 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 4 ms
4,756 KB
testcase_35 AC 5 ms
4,872 KB
testcase_36 AC 3 ms
4,352 KB
testcase_37 AC 24 ms
9,432 KB
testcase_38 AC 16 ms
7,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

typedef vector<ll> Edges;
typedef vector<Edges> Graph;

const ll V_MAX = 160005; // !! SHOULD BE EDITTED !!
vector<ll> ts(V_MAX, -1);

bool topologicalSort(Graph &G){
	ll V = G.size();
	vector<ll> indeg(V, 0);
	queue<ll> qu;

	REP(i, V){
		REP(j, G[i].size()){
			indeg[G[i][j]]++;
		}
	}
	REP(i, V){
		if(!indeg[i]) qu.push(i);
	}

	ll idx = 0;
	while(!qu.empty()){
		ll s = qu.size();
		REP(i, s){
			ll now = qu.front();qu.pop();
			ts[now] = idx;
			idx++;
			REP(j, G[now].size()){
				ll next = G[now][j];
				indeg[next]--;
				if(!indeg[next]) qu.push(next);
			}
		}
	}

	return (idx == V);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W;
    cin >> H >> W;
    vector<ll> A(H), B(W);
    REP(i, H) cin >> A[i];
    REP(j, W) cin >> B[j];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    Graph G(H*W);
    REP(i, H){
    	REP(j, W-1){
    		if(j<A[i]-1) G[W*i+j].push_back(W*i+j+1);
    		else G[W*i+j+1].push_back(W*i+j);
    	}
    }

    REP(j, W){
    	REP(i, H-1){
    		if(i<B[j]-1) G[W*i+j].push_back(W*i+j+W);
    		else G[W*i+j+W].push_back(W*i+j);
    	}
    }

    topologicalSort(G);

	/*    
    REP(i, H*W){
    	dump(i)
    	REP(j, G[i].size()){
    		cout << G[i][j] << " ";
    	}
    	cout << endl;
   	}
   	*/
   	

    REP(i, H){
    	REP(j, W){
    		cout << ts[W*i+j]+1 << " ";
    	}
    	cout << endl;
    }

    return 0;
}
0