# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024092 |
2024-07-15T11:52:25 Z |
caterpillow |
Burza (COCI16_burza) |
C++17 |
|
485 ms |
410764 KB |
#include <bits/stdc++.h>
#include <random>
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;
using uc = unsigned char;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
int n, k, t;
vt<vt<int>> adj;
vt<int> depth, pos, jump, rpos;
vt<uc> 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;
uc dp[401][1 << mxk];
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;
ROF (i, 0, n) {
int u = rpos[i];
F0R (msk, 1 << mxk) {
dp[i][msk] = dp[i + 1][msk];
if (depth[u] <= k && (1 & (msk >> depth[u]))) {
if (dp[i][msk] < val[u] + dp[jump[u]][msk ^ (1 << depth[u])]) dp[i][msk] = val[u] + dp[jump[u]][msk ^ (1 << depth[u])];
}
}
}
uc target = 0;
F0R (i, n) if (depth[i] == k) target += val[i];
if (dp[0][(1 << mxk) - 2] == target) cout << "DA\n";
else cout << "NE\n";
}
Compilation message
burza.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
320364 KB |
Output is correct |
2 |
Correct |
468 ms |
410744 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
454 ms |
393300 KB |
Output is correct |
6 |
Correct |
120 ms |
93568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
436 ms |
390228 KB |
Output is correct |
2 |
Correct |
466 ms |
392276 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
485 ms |
397436 KB |
Output is correct |
6 |
Correct |
455 ms |
406728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
478 ms |
395388 KB |
Output is correct |
2 |
Correct |
438 ms |
395344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
349 ms |
318340 KB |
Output is correct |
6 |
Correct |
104 ms |
100972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
436 ms |
386000 KB |
Output is correct |
2 |
Correct |
472 ms |
410764 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
311 ms |
273292 KB |
Output is correct |
6 |
Correct |
85 ms |
83536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
377960 KB |
Output is correct |
2 |
Correct |
429 ms |
390224 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
461 ms |
394248 KB |
Output is correct |
6 |
Correct |
324 ms |
278328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
393324 KB |
Output is correct |
2 |
Correct |
426 ms |
387152 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
386 ms |
364504 KB |
Output is correct |
6 |
Correct |
283 ms |
245588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
455 ms |
400468 KB |
Output is correct |
2 |
Correct |
465 ms |
389164 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
457 ms |
390324 KB |
Output is correct |
6 |
Correct |
364 ms |
322408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
395 ms |
345164 KB |
Output is correct |
2 |
Correct |
454 ms |
402528 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
279 ms |
245604 KB |
Output is correct |
6 |
Correct |
457 ms |
400468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
286576 KB |
Output is correct |
2 |
Correct |
468 ms |
406608 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
283 ms |
247640 KB |
Output is correct |
6 |
Correct |
403 ms |
368720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
341072 KB |
Output is correct |
2 |
Correct |
432 ms |
405580 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
383 ms |
345180 KB |
Output is correct |
6 |
Correct |
175 ms |
175696 KB |
Output is correct |