結果
問題 | No.1078 I love Matrix Construction |
ユーザー | snuke |
提出日時 | 2020-06-12 21:33:16 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 440 ms / 2,000 ms |
コード長 | 4,053 bytes |
コンパイル時間 | 2,678 ms |
コンパイル使用メモリ | 222,524 KB |
実行使用メモリ | 93,448 KB |
最終ジャッジ日時 | 2024-06-24 04:32:12 |
合計ジャッジ時間 | 8,755 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 42 ms
16,568 KB |
testcase_03 | AC | 133 ms
38,220 KB |
testcase_04 | AC | 197 ms
50,764 KB |
testcase_05 | AC | 163 ms
44,364 KB |
testcase_06 | AC | 39 ms
15,976 KB |
testcase_07 | AC | 14 ms
8,124 KB |
testcase_08 | AC | 171 ms
42,460 KB |
testcase_09 | AC | 7 ms
6,940 KB |
testcase_10 | AC | 440 ms
93,448 KB |
testcase_11 | AC | 223 ms
53,380 KB |
testcase_12 | AC | 361 ms
78,444 KB |
testcase_13 | AC | 403 ms
86,744 KB |
testcase_14 | AC | 267 ms
61,304 KB |
testcase_15 | AC | 397 ms
83,484 KB |
testcase_16 | AC | 12 ms
7,368 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 31 ms
13,084 KB |
testcase_19 | AC | 84 ms
25,364 KB |
testcase_20 | AC | 81 ms
24,800 KB |
testcase_21 | AC | 4 ms
6,940 KB |
ソースコード
#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*n); 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; }