結果
問題 | No.1078 I love Matrix Construction |
ユーザー | LayCurse |
提出日時 | 2020-06-12 21:48:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,703 bytes |
コンパイル時間 | 3,337 ms |
コンパイル使用メモリ | 219,892 KB |
実行使用メモリ | 28,748 KB |
最終ジャッジ日時 | 2024-06-24 04:49:07 |
合計ジャッジ時間 | 7,858 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
11,720 KB |
testcase_01 | AC | 4 ms
11,720 KB |
testcase_02 | AC | 6 ms
14,156 KB |
testcase_03 | AC | 10 ms
16,596 KB |
testcase_04 | AC | 13 ms
20,816 KB |
testcase_05 | WA | - |
testcase_06 | AC | 5 ms
11,980 KB |
testcase_07 | AC | 4 ms
11,852 KB |
testcase_08 | AC | 12 ms
24,776 KB |
testcase_09 | WA | - |
testcase_10 | AC | 29 ms
25,856 KB |
testcase_11 | AC | 12 ms
20,944 KB |
testcase_12 | AC | 18 ms
26,576 KB |
testcase_13 | AC | 23 ms
28,748 KB |
testcase_14 | AC | 16 ms
25,164 KB |
testcase_15 | AC | 27 ms
27,600 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 5 ms
11,856 KB |
testcase_19 | AC | 7 ms
14,028 KB |
testcase_20 | AC | 8 ms
20,284 KB |
testcase_21 | AC | 4 ms
9,680 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void *wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } a[k] = aval; } template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } for(i=sz-1;i>k;i--){ b[i] = b[i-1]; } a[k] = aval; b[k] = bval; } template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } for(i=sz-1;i>k;i--){ b[i] = b[i-1]; } for(i=sz-1;i>k;i--){ c[i] = c[i-1]; } a[k] = aval; b[k] = bval; c[k] = cval; } template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){ int i; sz++; for(i=sz-1;i>k;i--){ a[i] = a[i-1]; } for(i=sz-1;i>k;i--){ b[i] = b[i-1]; } for(i=sz-1;i>k;i--){ c[i] = c[i-1]; } for(i=sz-1;i>k;i--){ d[i] = d[i-1]; } a[k] = aval; b[k] = bval; c[k] = cval; d[k] = dval; } struct graph{ int N; int *es; int **edge; void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){ int i; N = N__; walloc1d(&es, N, mem); walloc1d(&edge, N, mem); for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ es[A[i]]++; es[B[i]]++; } for(i=(0);i<(N);i++){ walloc1d(&edge[i], es[i], mem); } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ edge[A[i]][es[A[i]]++] = B[i]; edge[B[i]][es[B[i]]++] = A[i]; } } int bipartite(int res[] = NULL, void *mem = wmem){ int i; int j; int k, s; int *st; int sts; if(res==NULL){ walloc1d(&res, N, &mem); } walloc1d(&st, N, &mem); for(i=(0);i<(N);i++){ res[i] = -1; } for(s=(0);s<(N);s++){ i = s; if(res[i]==-1){ res[i] = 0; sts = 0; st[sts++] = i; while(sts){ i = st[--sts]; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; if(res[k]==-1){ res[k] = 1 - res[i]; st[sts++] = k; } if(res[i] + res[k] != 1){ return 0; } } } } } return 1; } } ; int N; int S[500]; int T[500]; int U[500]; int n; int m; int a[1000000]; int b[1000000]; int res[1000000]; graph g; int main(){ int i; wmem = memarr; int x; int y; int z; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(S[Lj4PdHRW]);S[Lj4PdHRW] += (-1); } } { int e98WHCEY; for(e98WHCEY=(0);e98WHCEY<(N);e98WHCEY++){ rd(T[e98WHCEY]);T[e98WHCEY] += (-1); } } { int FmcKpFmN; for(FmcKpFmN=(0);FmcKpFmN<(N);FmcKpFmN++){ rd(U[FmcKpFmN]); } } n = 2*N*N; for(i=(0);i<(N);i++){ int j; for(j=(0);j<(N);j++){ x = S[i] * N + j; y = j * N + T[i]; z = U[i]; if(z%2==0){ if(z/2==0){ arrInsert(m, m, a, x +0, b, y +0); } else{ arrInsert(m, m, a, x +0, b, y +N*N); } } else{ if(z/2==0){ arrInsert(m, m, a, x +N*N, b, y +0); } else{ arrInsert(m, m, a, x +N*N, b, y +N*N); } } if(z%2==0){ if(z/2==0){ arrInsert(m, m, a, x +0, b, y +0); } else{ arrInsert(m, m, a, x +0, b, y +N*N); } } else{ if(z/2==0){ arrInsert(m, m, a, x +N*N, b, y +0); } else{ arrInsert(m, m, a, x +N*N, b, y +N*N); } } } } for(i=(0);i<(N*N);i++){ arrInsert(m, m, a, i, b, i + N*N); } g.setEdge(n, m, a, b); if(!g.bipartite(res)){ wt_L(-1); wt_L('\n'); return 0; } for(i=(0);i<(N);i++){ { int ZIeRIny5; if(N==0){ wt_L('\n'); } else{ for(ZIeRIny5=(0);ZIeRIny5<(N-1);ZIeRIny5++){ wt_L((res+N*i)[ZIeRIny5]); wt_L(' '); } wt_L((res+N*i)[ZIeRIny5]); wt_L('\n'); } } } return 0; } // cLay varsion 20200509-1 // --- original code --- // int N, S[500], T[500], U[500]; // int n, m, a[1d6], b[1d6]; // int res[1d6]; // graph g; // { // int x, y, z; // rd(N,(S--)(N),(T--)(N),U(N)); // n = 2*N*N; // rep(i,N) rep(j,N){ // x = S[i] * N + j; // y = j * N + T[i]; // z = U[i]; // arrInsert(m, m, a, x + if[z%2==0, 0, N*N], b, y + if[z/2==0, 0, N*N]); // arrInsert(m, m, a, x + if[z%2==0, 0, N*N], b, y + if[z/2==0, 0, N*N]); // } // rep(i,N*N) arrInsert(m, m, a, i, b, i + N*N); // g.setEdge(n, m, a, b); // if(!g.bipartite(res)) wt(-1), return 0; // wt(res(n)); // rep(i,N) wt(((res+N*i))(N)); // }