結果
問題 | No.1078 I love Matrix Construction |
ユーザー |
|
提出日時 | 2020-06-13 02:59:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,632 bytes |
コンパイル時間 | 2,682 ms |
コンパイル使用メモリ | 136,792 KB |
最終ジャッジ日時 | 2025-01-11 03:26:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:102:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 102 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:104:60: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 104 | vector<int> s(n); for (int i = 0; i < n; i++) scanf("%d", &s[i]), s[i]--; | ~~~~~^~~~~~~~~~~~~ main.cpp:105:60: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 105 | vector<int> t(n); for (int i = 0; i < n; i++) scanf("%d", &t[i]), t[i]--; | ~~~~~^~~~~~~~~~~~~ main.cpp:106:60: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 106 | vector<int> u(n); for (int i = 0; i < n; i++) scanf("%d", &u[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio>#include <iostream>#include <string>#include <sstream>#include <stack>#include <algorithm>#include <cmath>#include <queue>#include <map>#include <set>#include <cstdlib>#include <bitset>#include <tuple>#include <assert.h>#include <deque>#include <bitset>#include <iomanip>#include <limits>#include <chrono>#include <random>#include <array>#include <unordered_map>#include <functional>#include <complex>#include <numeric>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; }constexpr long long MAX = 5100000;constexpr long long INF = 1LL << 60;constexpr int inf = 1000000007;constexpr long long mod = 1000000007LL;//constexpr long long mod = 998244353LL;const long double PI = acos((long double)(-1));using namespace std;typedef unsigned long long ull;typedef long long ll;typedef long double ld;template< typename G >struct StronglyConnectedComponents {const G& g;vector<vector<int>> gg, rg;vector< int > comp, order, used;StronglyConnectedComponents(G& g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {for (int i = 0; i < g.size(); i++) {for (auto e : g[i]) {gg[i].emplace_back((int)e);rg[(int)e].emplace_back(i);}}}int operator[](int k) {return comp[k];}void dfs(int idx) {if (used[idx]) return;used[idx] = true;for (int to : gg[idx]) dfs(to);order.push_back(idx);}void rdfs(int idx, int cnt) {if (comp[idx] != -1) return;comp[idx] = cnt;for (int to : rg[idx]) rdfs(to, cnt);}void build(vector<vector<int>>& t) {for (int i = 0; i < gg.size(); i++) dfs(i);reverse(begin(order), end(order));int ptr = 0;for (int i : order) if (comp[i] == -1) rdfs(i, ptr), ptr++;t.resize(ptr);for (int i = 0; i < g.size(); i++) {for (auto& to : g[i]) {int x = comp[i], y = comp[to];if (x == y) continue;t[x].push_back(y);}}}};int n;int cnv(int i, int j, int k) {int res = i * n + j;if (k) res += n * n;return res;}int main(){/*cin.tie(nullptr);ios::sync_with_stdio(false);*/scanf("%d", &n);vector<vector<int>> g(n * n * 2);vector<int> s(n); for (int i = 0; i < n; i++) scanf("%d", &s[i]), s[i]--;vector<int> t(n); for (int i = 0; i < n; i++) scanf("%d", &t[i]), t[i]--;vector<int> u(n); for (int i = 0; i < n; i++) scanf("%d", &u[i]);for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (u[i] == 0) {g[cnv(s[i], j, 0)].emplace_back(cnv(j, t[i], 1));g[cnv(j, t[i], 0)].emplace_back(cnv(s[i], j, 1));}if (u[i] == 1) {g[cnv(s[i], j, 1)].emplace_back(cnv(j, t[i], 1));g[cnv(j, t[i], 0)].emplace_back(cnv(s[i], j, 0));}if (u[i] == 2) {g[cnv(s[i], j, 0)].emplace_back(cnv(j, t[i], 0));g[cnv(j, t[i], 1)].emplace_back(cnv(s[i], j, 1));}if (u[i] == 3) {g[cnv(s[i], j, 1)].emplace_back(cnv(j, t[i], 0));g[cnv(j, t[i], 1)].emplace_back(cnv(s[i], j, 0));}}}StronglyConnectedComponents<vector<vector<int>>> scc(g);vector<vector<int>> tmp; scc.build(tmp);for (int i = 0; i < n * n; i++) if (scc[i] == scc[i + n * n]) { puts("-1"); return 0; };vector<vector<int>> a(n, vector<int>(n));for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {int s = i * n + j;int t = s + n * n;if (scc[s] < scc[t]) {a[i][j] = 0;}else {a[i][j] = 1;}}}for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) printf("%d%c", a[i][j], " \n"[j + 1 == n]);return 0;}