# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024008 |
2024-07-15T10:34:45 Z |
caterpillow |
Burza (COCI16_burza) |
C++17 |
|
1000 ms |
410964 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;
int n, k, t;
vt<vt<int>> adj;
vt<int> depth, pos, jump, rpos;
vt<char> val;
void dfs(int u, int p = -1) {
pos[u] = t++;
if (depth[u] == k) val[u] = 1;
for (int v : adj[u]) {
if (v == p) continue;
depth[v] = depth[u] + 1;
dfs(v, u);
val[u] += val[v];
}
jump[u] = t;
}
const int mxk = 20;
char memo[400][1 << mxk];
char dp(int i, int msk) {
if (i == n) return 0;
if (memo[i][msk] != -1) return memo[i][msk];
int u = rpos[i]; // get the actual node index at this position
char ans = 0;
if (1 & (msk >> depth[u])) { // allowed to take yourself
ans = val[u] + dp(jump[u], msk ^ (1 << depth[u]));
}
ans = max(ans, dp(i + 1, msk));
return memo[i][msk] = ans;
}
main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
if (k * k >= n) {
cout << "DA\n";
return 0;
}
adj.resize(n);
depth = pos = jump = rpos = vt<int>(n, 0);
val.resize(n);
F0R (i, n - 1) {
int u, v; cin >> u >> v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
dfs(0);
F0R (i, n) rpos[pos[i]] = i;
memset(memo, -1, sizeof(memo));
if (dp(0, (1 << mxk) - 2) == val[0]) cout << "DA\n";
else cout << "NE\n";
}
Compilation message
burza.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
410804 KB |
Output is correct |
2 |
Execution timed out |
1118 ms |
410824 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
410872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1120 ms |
410704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
432 ms |
410824 KB |
Output is correct |
2 |
Execution timed out |
1100 ms |
410708 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1103 ms |
410640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1119 ms |
410876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
959 ms |
410872 KB |
Output is correct |
2 |
Execution timed out |
1080 ms |
410964 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
432 ms |
410708 KB |
Output is correct |
2 |
Execution timed out |
1058 ms |
410708 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
410704 KB |
Output is correct |
2 |
Execution timed out |
1076 ms |
410824 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
665 ms |
410872 KB |
Output is correct |
2 |
Execution timed out |
1044 ms |
410808 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |