結果
問題 | No.1024 Children in a Row |
ユーザー | 👑 emthrm |
提出日時 | 2020-04-15 00:09:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 532 ms / 2,000 ms |
コード長 | 3,022 bytes |
コンパイル時間 | 2,599 ms |
コンパイル使用メモリ | 221,948 KB |
実行使用メモリ | 70,888 KB |
最終ジャッジ日時 | 2024-10-01 18:27:21 |
合計ジャッジ時間 | 14,085 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 423 ms
42,612 KB |
testcase_11 | AC | 379 ms
37,872 KB |
testcase_12 | AC | 406 ms
39,796 KB |
testcase_13 | AC | 423 ms
41,036 KB |
testcase_14 | AC | 440 ms
39,920 KB |
testcase_15 | AC | 436 ms
42,060 KB |
testcase_16 | AC | 421 ms
39,096 KB |
testcase_17 | AC | 410 ms
43,620 KB |
testcase_18 | AC | 333 ms
39,968 KB |
testcase_19 | AC | 505 ms
52,884 KB |
testcase_20 | AC | 519 ms
53,008 KB |
testcase_21 | AC | 503 ms
53,000 KB |
testcase_22 | AC | 507 ms
53,016 KB |
testcase_23 | AC | 516 ms
52,124 KB |
testcase_24 | AC | 520 ms
52,124 KB |
testcase_25 | AC | 532 ms
52,128 KB |
testcase_26 | AC | 489 ms
54,568 KB |
testcase_27 | AC | 411 ms
50,584 KB |
testcase_28 | AC | 452 ms
69,624 KB |
testcase_29 | AC | 192 ms
70,888 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m), k(m); REP(i, m) cin >> a[i] >> b[i] >> k[i], --a[i], --b[i]; vector<vector<vector<pair<int, int>>>> graph(n, vector<vector<pair<int, int>>>(1)); vector<int> dst(m); REP(i, m) { dst[i] = graph[a[i]].size(); graph[a[i]].emplace_back(); graph[b[i]].back().emplace_back(a[i], dst[i]); } // REP(i, m) cout << dst[i] << " \n"[i + 1 == m]; vector<vector<int>> l(n), r(n); REP(i, n) { l[i].resize(graph[i].size()); r[i].resize(graph[i].size()); } vector<int> children; function<void(int, int)> dfs = [&](int src1, int src2) { l[src1][src2] = children.size(); children.emplace_back(src1); reverse(ALL(graph[src1][src2])); for (auto [dst1, dst2] : graph[src1][src2]) dfs(dst1, dst2); r[src1][src2] = children.size(); }; REP(i, n) dfs(i, 0); // REP(i, n + m) cout << children[i] << " \n"[i + 1 == n + m]; // REP(i, n) REP(j, graph[i].size()) cout << i << ' ' << j << " : " << l[i][j] << ' ' << r[i][j] << '\n'; vector<int> latest(n); REP(i, n) latest[i] = l[i][graph[i].size() - 1]; sort(ALL(latest)); // REP(i, n) cout << latest[i] << " \n"[i + 1 == n]; function<bool(int, int, int&)> solve = [&](int left, int right, int &k) { // cout << left << ' ' << right << '\n'; int cnt = upper_bound(ALL(latest), right) - lower_bound(ALL(latest), left); if (cnt < k) { k -= cnt; return false; } int idx = lower_bound(ALL(latest), left) - latest.begin(); cout << children[latest[idx + k - 1]] + 1 << '\n'; return true; }; REP(i, m) { if (l[a[i]][dst[i] - 1] < l[a[i]][dst[i]]) { assert(solve(0, l[a[i]][dst[i] - 1], k[i]) || solve(l[a[i]][dst[i]], r[a[i]][dst[i]] - 1, k[i]) || solve(l[a[i]][dst[i] - 1] + 1, l[a[i]][dst[i]] - 1, k[i]) || solve(r[a[i]][dst[i]], n + m - 1, k[i])); } else { assert(solve(0, l[a[i]][dst[i]] - 1, k[i]) || solve(r[a[i]][dst[i]], l[a[i]][dst[i] - 1], k[i]) || solve(l[a[i]][dst[i]], r[a[i]][dst[i]] - 1, k[i]) || solve(l[a[i]][dst[i] - 1] + 1, n + m - 1, k[i])); } } return 0; }