Submission #10033340
Source Code Expand
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define INF (1e9) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() const long double PI = acos(-1.0L); const long long MOD = 1000000007LL; //const long long MOD = 998244353LL; typedef long long ll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; } template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,M,K; cin >> N >> M >> K; vector<vector<int>> G(N); int s; rep(i,N) { int p; cin >> p; p--; if (p < 0) { s = i; continue; } G[p].emplace_back(i); } vector<int> dist(N); queue<int> que; que.emplace(s); while (!que.empty()) { int v = que.front(); que.pop(); for (auto nv : G[v]) { dist[nv] = dist[v]+1; que.emplace(nv); } } if (K < M) { cout << -1 << endl; return 0; } K -= M; reverse(all(dist)); vector<bitset<100001>> dp(M+1); dp[0][0] = 1; rep(i,N) { for (int j = M; j > 0; --j) { dp[j] |= (dp[j-1]<<dist[i]); } } if (!dp[M].test(K)) { cout << -1 << endl; return 0; } reverse(all(dist)); vector<int> ans; rep(i,N) { if (M > 0 && K - dist[i] >= 0 && dp[M-1].test(K-dist[i])) { ans.emplace_back(i+1); K -= dist[i]; M--; } } for (auto i : ans) cout << i << " "; cout << endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Coins on the tree |
User | minato_ |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1925 Byte |
Status | WA |
Exec Time | 345 ms |
Memory | 3712 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | WA | 12 ms | 896 KB |
02.txt | AC | 2 ms | 384 KB |
03.txt | WA | 5 ms | 512 KB |
04.txt | WA | 11 ms | 768 KB |
05.txt | WA | 5 ms | 512 KB |
06.txt | WA | 20 ms | 512 KB |
07.txt | WA | 38 ms | 640 KB |
08.txt | WA | 80 ms | 1152 KB |
09.txt | WA | 59 ms | 896 KB |
10.txt | WA | 171 ms | 2048 KB |
11.txt | WA | 30 ms | 640 KB |
12.txt | WA | 95 ms | 1280 KB |
13.txt | WA | 136 ms | 1664 KB |
14.txt | WA | 117 ms | 1536 KB |
15.txt | WA | 32 ms | 640 KB |
16.txt | WA | 185 ms | 2176 KB |
17.txt | WA | 194 ms | 2304 KB |
18.txt | WA | 262 ms | 2816 KB |
19.txt | WA | 306 ms | 3456 KB |
20.txt | WA | 281 ms | 3072 KB |
21.txt | WA | 211 ms | 2432 KB |
22.txt | WA | 345 ms | 3712 KB |
23.txt | WA | 313 ms | 3328 KB |
24.txt | WA | 323 ms | 3584 KB |
25.txt | WA | 326 ms | 3584 KB |
26.txt | WA | 211 ms | 2432 KB |
27.txt | WA | 224 ms | 2432 KB |
28.txt | WA | 235 ms | 2688 KB |
29.txt | WA | 243 ms | 2688 KB |
30.txt | WA | 242 ms | 2688 KB |
31.txt | AC | 15 ms | 640 KB |
32.txt | AC | 3 ms | 512 KB |
33.txt | AC | 12 ms | 640 KB |
34.txt | AC | 3 ms | 512 KB |
35.txt | AC | 34 ms | 640 KB |
36.txt | WA | 14 ms | 512 KB |
37.txt | WA | 4 ms | 384 KB |
38.txt | WA | 2 ms | 384 KB |
39.txt | WA | 3 ms | 384 KB |
40.txt | WA | 4 ms | 384 KB |
s1.txt | AC | 1 ms | 384 KB |
s2.txt | AC | 1 ms | 384 KB |