| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 561240 | fatemetmhr | Chase (CEOI17_chase) | C++17 | 4070 ms | 9664 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
const int maxn5 = 1e5 + 10;
const int ssq = 320;
const ll inf = 1e18;
ll h[maxn5], have[maxn5];
ll a[maxn5], lim, ans = 0, av[maxn5];
vector <int> adj[maxn5], ver;
int par[maxn5];
inline void dfs(int v){
for(auto u : adj[v]) if(u != par[v]){
par[u] = v;
dfs(u);
}
return;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n >> lim;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n - 1; i++){
int a, b; cin >> a >> b;
a--; b--;
adj[a].pb(b);
adj[b].pb(a);
}
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
par[i] = -1;
dfs(i);
int v = j;
ver.clear();
while(v != -1){
ver.pb(v);
v = par[v];
}
reverse(all(ver));
for(int mask = 0; mask < (1 << ver.size()); mask++) if(__builtin_popcount(mask) <= lim){
ll jer = 0;
for(int i = 0; i < n; i++)
av[i] = a[i];
for(int k = 0; k < ver.size(); k++){
jer += av[ver[k]];
if((mask >> k)&1){
for(auto u : adj[ver[k]]){
av[ver[k]] += av[u];
av[u] = 0;
}
}
}
for(int k = 0; k < ver.size(); k++)
jer -= av[ver[k]];
assert(jer <= 0);
ans = max(ans, abs(jer));
}
}
cout << ans << endl;
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
