結果
問題 | No.1401 全自動マクロの作り方 |
ユーザー |
![]() |
提出日時 | 2021-02-19 23:29:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,569 bytes |
コンパイル時間 | 2,460 ms |
コンパイル使用メモリ | 213,884 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-16 23:12:31 |
合計ジャッジ時間 | 10,265 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | WA | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | WA | - |
ソースコード
// // 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; }