結果

問題 No.1078 I love Matrix Construction
ユーザー leaf_1415leaf_1415
提出日時 2020-06-12 21:57:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,298 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 81,004 KB
実行使用メモリ 58,440 KB
最終ジャッジ日時 2023-09-06 10:21:43
合計ジャッジ時間 6,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
33,688 KB
testcase_01 AC 13 ms
33,732 KB
testcase_02 AC 28 ms
37,116 KB
testcase_03 AC 64 ms
42,696 KB
testcase_04 AC 86 ms
46,444 KB
testcase_05 AC 75 ms
44,664 KB
testcase_06 AC 28 ms
36,984 KB
testcase_07 AC 17 ms
35,016 KB
testcase_08 AC 70 ms
44,328 KB
testcase_09 WA -
testcase_10 AC 229 ms
58,440 KB
testcase_11 AC 84 ms
47,152 KB
testcase_12 AC 185 ms
53,644 KB
testcase_13 AC 195 ms
56,320 KB
testcase_14 AC 140 ms
49,452 KB
testcase_15 AC 196 ms
55,024 KB
testcase_16 AC 18 ms
35,120 KB
testcase_17 AC 13 ms
33,676 KB
testcase_18 AC 24 ms
36,204 KB
testcase_19 AC 43 ms
39,388 KB
testcase_20 AC 40 ms
39,300 KB
testcase_21 AC 14 ms
33,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint s[505], t[505], u[505];
vector<llint> G[600005], revG[600005];
vector<int> topo;
bool used[600005];
int scc[600005], pos[600005];
int ans[505][505];

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]) tpsort(G[v][i]);
	}
	topo.push_back(v);
}
void sccdfs(int v, int id)
{
	used[v] = true;
	scc[v] = id;
	for(int i = 0; i < revG[v].size(); i++){
		if(!used[revG[v][i]]) sccdfs(revG[v][i], id);
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> s[i];
	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 1; i <= n; i++) cin >> u[i];
	
	llint N = (n+1)*n;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			llint S = s[i]*n+j, T = j*n+t[i];
			llint a = u[i]%2, b = u[i]/2;
			G[a*N+S].push_back((1-b)*N+T);
			G[b*N+T].push_back((1-a)*N+S);
		}
	}
	
	for(int i = 1; i <= 2*N; i++){
		for(int j = 0; j < G[i].size(); j++){
			llint u = G[i][j];
			revG[u].push_back(i);
		}
	}
	
	for(int i = 1; i <= 2*N; i++) if(!used[i]) tpsort(i);
	reverse(topo.begin(), topo.end());
	
	int id = 0;
	for(int i = 1; i <= 2*N; i++) used[i] = false;
	for(int i = 0; i < topo.size(); i++) if(!used[topo[i]]) sccdfs(topo[i], id++);
	
	for(int i = 0; i < topo.size(); i++) pos[topo[i]] = i;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			int v = i*n+j;
			//cout << scc[v] << " " << scc[N+v] << endl;
			if(scc[v] == scc[N+v]){
				cout << -1 << endl;
				return 0;
			}
			if(pos[v] < pos[N+v]) ans[i][j] = 1;
			else ans[i][j] = 0;
		}
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	
	return 0;
}
0