結果

問題 No.1078 I love Matrix Construction
ユーザー tko919tko919
提出日時 2020-05-02 04:03:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,261 ms / 2,000 ms
コード長 2,290 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 177,432 KB
実行使用メモリ 68,644 KB
最終ジャッジ日時 2023-08-29 01:00:11
合計ジャッジ時間 15,439 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 171 ms
12,952 KB
testcase_03 AC 462 ms
28,284 KB
testcase_04 AC 648 ms
37,444 KB
testcase_05 AC 532 ms
31,668 KB
testcase_06 AC 165 ms
12,652 KB
testcase_07 AC 63 ms
6,760 KB
testcase_08 AC 534 ms
32,012 KB
testcase_09 AC 26 ms
4,680 KB
testcase_10 AC 1,261 ms
68,644 KB
testcase_11 AC 690 ms
39,316 KB
testcase_12 AC 1,025 ms
57,256 KB
testcase_13 AC 1,159 ms
63,828 KB
testcase_14 AC 797 ms
45,888 KB
testcase_15 AC 1,089 ms
60,840 KB
testcase_16 AC 48 ms
5,956 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 124 ms
10,232 KB
testcase_19 AC 288 ms
19,232 KB
testcase_20 AC 289 ms
18,920 KB
testcase_21 AC 11 ms
4,380 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 ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<typename T=int>inline T get(){
   char c=getchar(); bool neg=(c=='-');
   T res=neg?0:c-'0'; while(isdigit(c=getchar()))res=res*10+(c-'0');
   return neg?-res:res;
}
template<typename T=int>inline void put(T x,char c='\n'){
   if(x<0)putchar('-'),x*=-1; int d[20],i=0;
   do{d[i++]=x%10;}while(x/=10); while(i--)putchar('0'+d[i]);
   putchar(c);
}
//end

struct SCC{
    vector<vector<int>> g, gr;
    int n, k;
    vector<int> cmp, vs;
    vector<bool> used;
    void dfs(int x){
        used[x]=1;
        for(auto y:g[x]){
            if(!used[y]) dfs(y);
        }
        vs.push_back(x);
    }
    void rdfs(int v, int k){
        used[v]=1;
        cmp[v]=k;
        for(auto y:gr[v]){
            if(!used[y]) rdfs(y, k);
        }
    }
    SCC(const vector<vector<int>> &g):g(g), n(g.size()), cmp(n), used(n){
        gr.resize(n);
        for(int x=0; x<n; x++) for(auto y:g[x]) gr[y].push_back(x);
        for(int i=0; i<n; i++){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), 0);
        k=0;
        for(int i=vs.size()-1; i>=0; i--){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }
    }
};

int n,S[510],T[510],U[510]; bool a[250100];
int pos(int i,int j){return i*n+j;}

int main(){
   n=get();
   rep(i,0,n)S[i]=get(),S[i]--;
   rep(i,0,n)T[i]=get(),T[i]--;
   rep(i,0,n)U[i]=get();
   int m=n*n; vector<vector<int>> g(m*2+1);
   rep(i,0,n)rep(j,0,n){
      int x=pos(S[i],j)+1,y=pos(j,T[i])+1;
      if(U[i]&1)x*=-1; if(U[i]&2)y*=-1;
      cerr<<x<<y<<endl;
      g[m-x].push_back(m+y); g[m-y].push_back(m+x);
   } SCC scc(g);
   rep(i,1,m+1){
      if(scc.cmp[m-i]==scc.cmp[m+i]){
         put(-1); return 0;
      }
      a[i]=(scc.cmp[m-i]<scc.cmp[m+i]);
   }
   rep(i,0,n)rep(j,0,n){
      if(j!=n-1)put(a[pos(i,j)+1],' ');
      else put(a[pos(i,j)+1]);
   }
   return 0;
}
0