結果
問題 | No.1078 I love Matrix Construction |
ユーザー | snuke |
提出日時 | 2020-06-12 21:32:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,053 bytes |
コンパイル時間 | 2,858 ms |
コンパイル使用メモリ | 223,064 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 04:31:56 |
合計ジャッジ時間 | 8,691 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
ソースコード
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cout<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef tuple<int,int,int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; inline int getInt() { int x; scanf("%d",&x); return x;} template<typename T>inline istream& operator>>(istream&i,v(T)&v) {rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const v(T)&v) {stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v) {if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v) {return o<<v.fi<<","<<v.se;} template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;} const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} const int MX = 200005; // 2-SAT // SCC // upstream is smaller id struct scc { int n, k; vvi to, ot, d, gt; // to, rev_to, groups, group_to vi g, used, kv; // group, gomi, topo_ord scc(int n=0):n(n),to(n),ot(n){} int inc() { to.pb(vi()); ot.pb(vi()); return n++;} void add(int a, int b) { to[a].pb(b); ot[b].pb(a);} void dfs(int v) { if (used[v]) return; used[v] = 1; rep(i,sz(to[v])) dfs(to[v][i]); kv[--k] = v; } void rfs(int v) { if (g[v] != -1) return; g[v] = k; d[k].pb(v); rep(i,sz(ot[v])) rfs(ot[v][i]); } void init() { k = n; used = kv = vi(n); g = vi(n,-1); rep(i,n) dfs(i); rep(i,n) if (g[kv[i]] == -1) { d.pb(vi()); rfs(kv[i]); k++; } gt = vvi(k); rep(i,n)rep(j,sz(ot[i])) { int v = g[ot[i][j]], u = g[i]; if (v != u) gt[v].pb(u); } rep(i,k) { sort(rng(gt[i])); gt[i].erase(unique(rng(gt[i])),gt[i].end()); } } }; // struct sat { int n, n2; scc g; vi d; sat() {} sat(int n):n(n),n2(n*2),g(n2) {} int inv(int a) { return n2-1-a;} void add(int a, int b) { g.add(inv(a),b); g.add(inv(b),a); } void imply(int a, int b) { add(inv(a),b);} void must(int a, bool x=true) { if (x) add(a,a); else must(inv(a));} bool solve() { g.init(); rep(i,n) if (g.g[i] == g.g[inv(i)]) return false; d = vi(n2); rep(i,n2) d[i] = g.g[i] > g.g[inv(i)]; return true; } }; // int main() { int n; scanf("%d",&n); vi sa(n); vi sb(n); vi sc(n); cin>>sa>>sb>>sc; rep(i,n) sa[i]--; rep(i,n) sb[i]--; sat g(n*2); rep(i,n) { int a = sa[i]; int b = sb[i]; int c = sc[i]; int ca = c&1; int cb = c>>1; rep(j,n) { int va = a*n+j; int vb = j*n+b; if (ca) va = g.inv(va); if (cb) vb = g.inv(vb); g.add(va,vb); } } if (!g.solve()) dame; vvi ans(n,vi(n)); rep(i,n)rep(j,n) { int v = i*n+j; ans[i][j] = g.d[v]; } rep(i,n) cout<<ans[i]<<endl; return 0; }