結果
問題 | No.1401 全自動マクロの作り方 |
ユーザー |
![]() |
提出日時 | 2021-02-19 23:29:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,569 bytes |
コンパイル時間 | 2,215 ms |
コンパイル使用メモリ | 204,908 KB |
最終ジャッジ日時 | 2025-01-19 01:48:42 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | WA * 3 RE * 4 |
ソースコード
// // Created by yamunaku on 2021/02/19. // #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for(int i = 0; i < (n); i++) #define repl(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD9 998244353 #define MOD1 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) #define CST(x) cout<<fixed<<setprecision(x) using ll = long long; using ld = long double; using vi = vector<int>; using mti = vector<vector<int>>; using vl = vector<ll>; using mtl = vector<vector<ll>>; using pi = pair<int, int>; using pl = pair<ll, ll>; template<typename T> using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>; int main() { //CFS; int n; cin >> n; mti s(n); int m = 2000; vi use(m); mti e(m); vi deg(m); mti id(m); rep(i, n) { int k; cin >> k; s[i] = vi(k); rep(j, k) cin >> s[i][j], s[i][j]--; use[s[i].back()] = true; id[s[i].back()].push_back(i); } rep(i, n) { if (s[i].front() != s[i].back()) { if (use[s[i].front()]) { e[s[i].front()].push_back(s[i].back()); deg[s[i].back()]++; } } } vi ord; queue<int> q; rep(i, m) { if (deg[i] == 0 && use[i]) q.push(i); } while (!q.empty()) { int now = q.front(); q.pop(); ord.push_back(now); for (auto &nx : e[now]) { deg[nx]--; if (deg[nx] == 0) q.push(nx); } } rep(i, m) { if (deg[i] > 0) { cout << 0 << endl; return 0; } } vi ans; for (int x : ord) { ans.push_back(x); for (auto &t : id[x]) { int idx = s[t].size() - 1; per(i, ans.size()) { if (idx >= 0) if (ans[i] == s[t][idx]) { idx--; } } vi tmp; rep(i, idx + 1) { tmp.push_back(s[t][i]); } for (auto &y : ans) tmp.push_back(y); ans = tmp; } } cout << ans.size() << endl; for (auto &x : ans) cout << x + 1 << " "; cout << endl; return 0; }