結果

問題 No.1078 I love Matrix Construction
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-06-12 23:55:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,631 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 210,464 KB
実行使用メモリ 32,760 KB
最終ジャッジ日時 2023-09-06 11:30:15
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 9 ms
17,952 KB
testcase_02 AC 32 ms
23,772 KB
testcase_03 AC 87 ms
32,760 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 31 ms
23,436 KB
testcase_07 AC 16 ms
20,016 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 27 ms
22,084 KB
testcase_19 AC 47 ms
27,588 KB
testcase_20 AC 46 ms
27,360 KB
testcase_21 AC 10 ms
18,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define ZERO(a) memset(a,0,sizeof(a))
class SCC {
public:
	static const int MV = 201010; // ここをしっかり変えること!!!
	vector<vector<int> > SC; int NV, GR[MV], rev[MV];
private:
	vector<int> E[MV], RE[MV], NUM; int vis[MV];
public:
	void init(int NV) { this->NV = NV; for (int i = 0; i<MV; i++) { E[i].clear(); RE[i].clear(); } }
	void add_edge(int x, int y) { E[x].push_back(y); RE[y].push_back(x); }
	void dfs(int cu) { vis[cu] = 1; for (int i = 0; i<E[cu].size(); i++) if (!vis[E[cu][i]]) dfs(E[cu][i]); NUM.push_back(cu); }
	void revdfs(int cu, int ind) {
		int i; vis[cu] = 1; GR[cu] = ind; SC[ind].push_back(cu); rev[cu] = ind;
		rep(i, 0, RE[cu].size()) if (!vis[RE[cu][i]]) revdfs(RE[cu][i], ind);
	}
	void scc() {
		int c = 0; SC.clear(); SC.resize(MV); NUM.clear();
		ZERO(vis); for (int i = 0; i<NV; i++) if (!vis[i]) dfs(i);
		ZERO(vis); for (int i = NUM.size() - 1; i >= 0; i--) if (!vis[NUM[i]]) {
			SC[c].clear(); revdfs(NUM[i], c); sort(SC[c].begin(), SC[c].end()); c++;
		}
		SC.resize(c);
	}
};
class TwoSat {
	int NV;
	SCC sc;
public:
	vector<int> val;
	void init(int NV) { this->NV = NV * 2; sc.init(NV * 2); val.resize(NV); }
	void add_edge(int x, int y) { // k+0:normal k+NV:inverse
		sc.add_edge((x + NV / 2) % NV, y);
		sc.add_edge((y + NV / 2) % NV, x);
	}
	bool sat() { // empty:false 
		sc.scc();
		for (int i = 0; i<NV / 2; i++) if (sc.GR[i] == sc.GR[i + NV / 2]) return false;
		for (int i = 0; i<NV / 2; i++) val[i] = sc.GR[i]>sc.GR[i + NV / 2];
		return true;
	}
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/









int N, S[501], T[501], U[501];
TwoSat ts;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> S[i];
	rep(i, 0, N) cin >> T[i];
	rep(i, 0, N) cin >> U[i];

	ts.init(N * N);

	rep(i, 0, N) rep(j, 0, N) {
		int a = (S[i] - 1) * N + j;
		int b = j * N + (T[i] - 1);
		rep(x, 0, 2) rep(y, 0, 2) {
			if (x + y * 2 == U[i]) {
				int aa = a;
				if (x == 0) aa += N * N;

				int bb = b;
				if (y == 0) bb += N * N;

				ts.add_edge(aa, bb);
			}
		}
	}

	auto res = ts.sat();
	if (!res) {
		printf("-1\n");
		return;
	}

	rep(y, 0, N) {
		rep(x, 0, N) {
			if(x) printf(" ");
			if(ts.val[y * N + x]) printf("1");
			else printf("0");
		}
		printf("\n");
	}
}





0