結果

問題 No.1078 I love Matrix Construction
ユーザー yukudo
提出日時 2020-06-12 23:27:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,679 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 174,932 KB
実行使用メモリ 49,476 KB
最終ジャッジ日時 2024-06-24 06:02:32
合計ジャッジ時間 8,024 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main2()':
main.cpp:83:8: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
   83 |     g[b].push_back(a^1);
      |     ~~~^
main.cpp:66:12: note: 'b' declared here
   66 |     int a, b;
      |            ^
main.cpp:83:21: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   83 |     g[b].push_back(a^1);
      |                    ~^~
main.cpp:66:9: note: 'a' declared here
   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[b].push_back(a^1);
g[a].push_back(b^1);
r[a^1].push_back(b);
r[b^1].push_back(a);
}
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0