結果

問題 No.1078 I love Matrix Construction
ユーザー 37zigen37zigen
提出日時 2020-06-12 22:42:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,228 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 208,000 KB
実行使用メモリ 43,456 KB
最終ジャッジ日時 2023-09-06 10:51:32
合計ジャッジ時間 7,252 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
27,932 KB
testcase_01 AC 11 ms
28,124 KB
testcase_02 AC 19 ms
29,912 KB
testcase_03 AC 36 ms
32,972 KB
testcase_04 AC 54 ms
35,300 KB
testcase_05 WA -
testcase_06 AC 18 ms
29,764 KB
testcase_07 AC 13 ms
28,704 KB
testcase_08 AC 41 ms
34,024 KB
testcase_09 WA -
testcase_10 AC 99 ms
43,456 KB
testcase_11 AC 58 ms
35,864 KB
testcase_12 AC 79 ms
41,204 KB
testcase_13 AC 92 ms
42,592 KB
testcase_14 AC 62 ms
38,968 KB
testcase_15 AC 87 ms
41,796 KB
testcase_16 WA -
testcase_17 AC 11 ms
27,932 KB
testcase_18 AC 17 ms
29,208 KB
testcase_19 AC 26 ms
31,360 KB
testcase_20 AC 24 ms
31,124 KB
testcase_21 AC 11 ms
28,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

vector<int> g[1010000]; int res[1010000]={},c=0;
stack<int> s; bool used[1010000]={};
vector<int> low,val; int idx=0;
void dfs(int v){
   low[v]=val[v]=++idx; s.push(v); used[v]=1;
   for(int to:g[v]){
      if(val[to]==0){dfs(to); chmin(low[v],low[to]);}
      else if(used[to])chmin(low[v],val[to]);
   }
   if(low[v]==val[v]){ c++;
      while(1){
         int to=s.top(); s.pop();
         used[to]=0; res[to]=c;
         if(v==to)break;
      }
   }
}
void scc(int n){
   low.resize(2*n+1,0); val.resize(2*n+1,0);
   rep(i,0,2*n+1)if(i!=n&&val[i]==0)dfs(i);
}

int main(){
  int N,n;
  scanf("%d",&N);
  n=N*N;
  int S[N];
  int T[N];
  int U[N];
  int mat[N][N];
  for (int i=0;i<N;++i) {
    cin>>S[i];
    --S[i];
  }
  for (int i=0;i<N;++i) {
    cin>>T[i];
    --T[i];
  }
  for (int i=0;i<N;++i) {
    cin>>U[i];
  }

  for (int i=0;i<N;++i) {
    for (int j=0;j<N;++j) {
      int a=S[i]+j*N+1;
      int b=j+T[i]*N+1;
      if (U[i]==0) {
      } else if (U[i]==1) {
        a*=-1;
        b=a;
      } else if (U[i]==2) {
        b*=-1;
        a=b;
      } else if (U[i]==3) {
        a*=-1;
        b*=-1;
      }
      g[n-a].push_back(n+b); g[n-b].push_back(n+a);
    }
  }
  scc(n);
  vector<int> buf(n+1);
  rep(i,0,n){
    if(res[i]==res[2*n-i]){
      std::cout<<-1<<std::endl;
      return 0;
    }
    buf[n-i]=(res[i]<res[2*n-i]?i-n:n-i);
  }
  rep(i,1,n+1) {
    int id=i-1;
    mat[id%N][id/N]=buf[i]<0?0:1;
  }
  for (int i=0;i<N;++i) {
    for (int j=0;j<N;++j) {
      std::cout<<mat[i][j];
      if (j==N-1) {
        std::cout<<"\n";
      } else {
        std::cout<<" ";
      }
    }
  }
  return 0;
}
0