# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
294067 | 2020-09-08T14:49:54 Z | BThero | Power Plant (JOI20_power) | C++17 | 1500 ms | 16120 KB |
// chrono::system_clock::now().time_since_epoch().count() #include<bits/stdc++.h> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << " = " << x << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = (int)2e3 + 5; int dist[MAXN][MAXN]; vector<int> adj[MAXN]; int state[MAXN], broken[MAXN]; int can[MAXN]; int n; bool bit(int x, int p) { return (x >> p) & 1; } void dfs(int d[], int v, int pr = -1) { for (int to : adj[v]) { if (to != pr) { d[to] = d[v] + 1; dfs(d, to, v); } } } void solve() { scanf("%d", &n); for (int i = 1; i < n; ++i) { int u, v; scanf("%d %d", &u, &v); adj[u].pb(v); adj[v].pb(u); } for (int i = 1; i <= n; ++i) { char c; scanf(" %c", &c); can[i] = c - '0'; } for (int i = 1; i <= n; ++i) { dfs(dist[i], i); } int ans = 0; for (int mask = 0; mask < (1 << n); ++mask) { bool ok = 1; for (int i = 1; i <= n; ++i) { state[i] = bit(mask, i - 1); broken[i] = 0; if (state[i] > can[i]) { ok = 0; } } if (!ok) { continue; } for (int x = 1; x <= n; ++x) { if (!state[x]) { continue; } for (int y = 1; y <= n; ++y) { if (!can[y] || x == y) { continue; } for (int z = 1; z <= n; ++z) { if (!state[z]) { continue; } if (y != z && x != z && dist[x][y] + dist[y][z] == dist[x][z]) { broken[y] = 1; } } } } int cur = 0; for (int i = 1; i <= n; ++i) { if (state[i] == 1 && !broken[i]) { ++cur; } cur -= broken[i]; } ans = max(ans, cur); } printf("%d\n", ans); } int main() { int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 21 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 541 ms | 488 KB | Output is correct |
8 | Correct | 603 ms | 484 KB | Output is correct |
9 | Correct | 248 ms | 504 KB | Output is correct |
10 | Correct | 7 ms | 500 KB | Output is correct |
11 | Correct | 585 ms | 488 KB | Output is correct |
12 | Correct | 20 ms | 384 KB | Output is correct |
13 | Correct | 20 ms | 384 KB | Output is correct |
14 | Correct | 20 ms | 504 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 401 ms | 504 KB | Output is correct |
18 | Correct | 170 ms | 488 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 496 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 21 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 541 ms | 488 KB | Output is correct |
8 | Correct | 603 ms | 484 KB | Output is correct |
9 | Correct | 248 ms | 504 KB | Output is correct |
10 | Correct | 7 ms | 500 KB | Output is correct |
11 | Correct | 585 ms | 488 KB | Output is correct |
12 | Correct | 20 ms | 384 KB | Output is correct |
13 | Correct | 20 ms | 384 KB | Output is correct |
14 | Correct | 20 ms | 504 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 401 ms | 504 KB | Output is correct |
18 | Correct | 170 ms | 488 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 496 ms | 384 KB | Output is correct |
22 | Execution timed out | 1593 ms | 16120 KB | Time limit exceeded |
23 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 21 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 541 ms | 488 KB | Output is correct |
8 | Correct | 603 ms | 484 KB | Output is correct |
9 | Correct | 248 ms | 504 KB | Output is correct |
10 | Correct | 7 ms | 500 KB | Output is correct |
11 | Correct | 585 ms | 488 KB | Output is correct |
12 | Correct | 20 ms | 384 KB | Output is correct |
13 | Correct | 20 ms | 384 KB | Output is correct |
14 | Correct | 20 ms | 504 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 401 ms | 504 KB | Output is correct |
18 | Correct | 170 ms | 488 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 496 ms | 384 KB | Output is correct |
22 | Execution timed out | 1593 ms | 16120 KB | Time limit exceeded |
23 | Halted | 0 ms | 0 KB | - |