結果

問題 No.1078 I love Matrix Construction
ユーザー yukudoyukudo
提出日時 2020-06-12 23:15:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,678 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 172,000 KB
実行使用メモリ 49,204 KB
最終ジャッジ日時 2023-09-06 11:19:14
合計ジャッジ時間 7,153 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
29,848 KB
testcase_01 AC 15 ms
29,764 KB
testcase_02 WA -
testcase_03 AC 59 ms
36,732 KB
testcase_04 AC 99 ms
39,744 KB
testcase_05 WA -
testcase_06 AC 28 ms
32,524 KB
testcase_07 AC 20 ms
30,800 KB
testcase_08 AC 92 ms
38,268 KB
testcase_09 WA -
testcase_10 AC 205 ms
49,204 KB
testcase_11 AC 104 ms
40,408 KB
testcase_12 AC 161 ms
45,364 KB
testcase_13 WA -
testcase_14 AC 120 ms
41,956 KB
testcase_15 AC 174 ms
46,696 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 24 ms
31,884 KB
testcase_19 AC 44 ms
34,508 KB
testcase_20 AC 40 ms
34,428 KB
testcase_21 AC 15 ms
30,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main2()’ 内:
main.cpp:83:8: 警告: ‘a’ may be used uninitialized [-Wmaybe-uninitialized]
   83 |     g[a^1].push_back(b);
      |       ~^~
main.cpp:66:9: 備考: ‘a’ はここで宣言されています
   66 |     int a, b;
      |         ^

ソースコード

diff #

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_V = 500 * 500 * 2 + 10;
vector<int> g[MAX_V];
vector<int> r[MAX_V];


const int MAX_N = 505;
int A[MAX_N][MAX_N];
int N;
int nodeId(int r, int c, int f) {
  return (r * N + c) * 2 + f;
}

int sccid[MAX_V];
int sccnum;
void dfs(int p, vector<int>& order) {
  if (sccid[p] != 0) return;
  sccid[p] = 1;
  for (int i : g[p]) dfs(i, order);
  order.push_back(p);
}
void rdfs(int p, int id) {
  if (sccid[p] != -1) return;
  sccid[p] = id;
  for (int i : r[p]) rdfs(i, id);
}
void scc() {
  vector<int> order;
  CLR(sccid, 0);
  REP(i, N) dfs(i, order);
  CLR(sccid, -1);
  sccnum = 0;
  for (int i = (int)order.size() - 1; i >= 0; i--) if (sccid[order[i]] == -1) {
    rdfs(order[i], sccnum);
    sccnum++;
  }
}


int main2() {
  REP(i, MAX_V) g[i].clear();
  REP(i, MAX_V) r[i].clear();

  N = nextLong();

  vector<int> S(N), T(N), U(N);
  REP(i, N) S[i] = nextLong()-1;
  REP(i, N) T[i] = nextLong()-1;
  REP(i, N) U[i] = nextLong();


  REP(i, N) REP(j, N) {
    int a, b;
    if (U[i] == 0) {
      a = nodeId(S[i], j, 0);
      b = nodeId(j, T[i], 0);
    }
    if (U[i] == 1) {
      a = nodeId(S[i], j, 1);
      b = nodeId(j, T[i], 0);
    }
    if (U[i] == 2) {
      a = nodeId(S[i], j, 0);
      b = nodeId(j, T[i], 1);
    }
    if (U[i] == 3) {
      a = nodeId(S[i], j, 1);
      b = nodeId(j, T[i], 1);
    }
    g[a^1].push_back(b);
    g[b^1].push_back(a);

    r[b].push_back(a^1);
    r[a].push_back(b^1);
  }

  scc();

  // REP(i, N*N) cout << sccid[i * 2] << " "; cout << endl;
  // REP(i, N*N) cout << sccid[i * 2 + 1] << " "; cout << endl;

  bool ng = false;
  REP(i, N*N) {
    if (sccid[i * 2] != -1 && sccid[i * 2] == sccid[i * 2 + 1]) {
      ng = true;
    }
  }
  if (ng) {
    cout << -1 << endl;
  } else {

    REP(i, N*N) {
      int r = i / N;
      int c = i % N;
      A[r][c] = sccid[i * 2 + 1] > sccid[i * 2] ? 1 : 0;
    }

    REP(r, N) {
      REP(c, N) {
        if (c) cout << ' ';
        cout << A[r][c];
      }
      cout << '\n';
    }
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
0