# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
455134 |
2021-08-05T13:27:26 Z |
ljuba |
Burza (COCI16_burza) |
C++17 |
|
10 ms |
920 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
namespace debug {
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef ljuba
#define dbg(x...) cerr << "\e[91m" << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
}
using namespace debug;
const char nl = '\n';
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
/*
погледај сампле тестове, пре него што имплементираш (можда имаш погрешну идеју)
уместо да разматраш неке глупе случајеве на папиру, размишљај заправо о задатку
*/
const int mxN = 405;
vi adj[mxN];
int n, k;
int ima[mxN];
int prvi[mxN];
int dub[mxN];
bool vis[mxN];
int cnt = 0;
void dfs(int s, int p = -1, int dep = 0) {
vis[s] = 1;
dub[s] = dep;
if(dep == k) {
prvi[s] = cnt++;
ima[s] = 1;
return;
}
for(auto e : adj[s]) {
if(e == p)
continue;
dfs(e, s, dep+1);
ima[s] += ima[e];
if(prvi[s] == -1 && prvi[e] != -1) {
prvi[s] = prvi[e];
}
}
}
int dp[1<<21];
int sle[mxN][30];
void solve() {
cin >> n >> k;
for(int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
adj[u].pb(v);
adj[v].pb(u);
}
if(k >= 20) {
cout << "DA" << nl;
return;
}
for(int i = 0; i < mxN; ++i) {
prvi[i] = -1;
}
dfs(0);
for(int i = 0; i < n; ++i) {
--dub[i];
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < 25; ++j) {
sle[i][j] = -1;
}
}
for(int i = 1; i < n; ++i) {
if(vis[i] && prvi[i] != -1) {
sle[prvi[i]][dub[i]] = prvi[i] + ima[i];
}
}
dp[0] = 0;
for(int mask = 0; mask < (1<<k); ++mask) {
int tren = dp[mask];
if(tren == cnt) {
dp[(1<<k)-1] = cnt;
break;
}
for(int i = 0; i < k; ++i) {
if(!((mask>>i)&1)) {
//zapravo mora da postoji takav, nema veze
if(sle[tren][i] == -1)
continue;
int mask2 = mask ^ (1<<i);
ckmax(dp[mask2], sle[tren][i]);
}
}
}
cout << ((dp[(1<<k)-1] == cnt) ? "DA" : "NE") << nl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testCases = 1;
//cin >> testCases;
while(testCases--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
8 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
916 KB |
Output is correct |
2 |
Correct |
8 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
9 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
844 KB |
Output is correct |
2 |
Correct |
10 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
8 ms |
832 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
844 KB |
Output is correct |
2 |
Correct |
8 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
800 KB |
Output is correct |
2 |
Correct |
7 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
920 KB |
Output is correct |
2 |
Correct |
8 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
10 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
588 KB |
Output is correct |
2 |
Correct |
8 ms |
912 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
10 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
588 KB |
Output is correct |
2 |
Correct |
8 ms |
920 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |