# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
675484 | 2022-12-27T10:38:05 Z | messiuuuuu | Uzastopni (COCI15_uzastopni) | C++17 | 152 ms | 65536 KB |
/// #include<bits/stdc++.h> #define task "C" #define ll long long #define ld long double #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 1e4 + 5; const ll INF = 1e18 + 5; int n; int c[MAXN]; vector<int> Adj[MAXN]; void Input() { cin >> n; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; Adj[u].pb(v); Adj[v].pb(u); } } bitset<105> dp[MAXN][105], t[105]; vector<int> pl[MAXN][105], pr[MAXN][105]; void DFS(int u, int par) { for (int v : Adj[u]) { if (v == par) continue; DFS(v, u); for (int l = 1; l <= 100; l++) for (int r = l; r <= 100; r++) if (dp[v][l][r]) { pl[u][l].pb(r); pr[u][r].pb(l); } } for (int i = 1; i <= 100; i++) t[i].reset(); t[c[u] - 1][c[u]] = t[c[u] + 1][c[u]] = 1; for (int i = 100; i >= c[u] + 1; i--) { for (int j : pl[u][i]) { t[i][j] = 1; t[i] |= t[j + 1]; } } for (int i = 1; i <= c[u] - 1; i++) { for (int j : pr[u][i]) { t[i][j] = 1; t[i] |= t[j - 1]; } } for (int x = 1; x <= 100; x++) { if (t[c[u] - 1][x] == 0) continue; for (int y = x; y <= 100; y++) { if (t[c[u] + 1][y] == 0) continue; dp[u][x][y] = 1; } } } void Solve() { DFS(1, 0); int res = 0; for (int i = 1; i <= 100; i++) { for (int j = i; j <= 100; j++) { //if (dp[1][i][j]) // cout << i << ' ' << j << '\n'; res += dp[1][i][j]; } } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".INP","r")) { freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } Input(); Solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 23 ms | 49972 KB | Memory limit exceeded |
2 | Runtime error | 26 ms | 49976 KB | Memory limit exceeded |
3 | Runtime error | 24 ms | 50004 KB | Memory limit exceeded |
4 | Runtime error | 25 ms | 49996 KB | Memory limit exceeded |
5 | Runtime error | 25 ms | 50088 KB | Memory limit exceeded |
6 | Runtime error | 26 ms | 50004 KB | Memory limit exceeded |
7 | Runtime error | 26 ms | 50132 KB | Memory limit exceeded |
8 | Runtime error | 26 ms | 50020 KB | Memory limit exceeded |
9 | Runtime error | 25 ms | 49980 KB | Memory limit exceeded |
10 | Runtime error | 31 ms | 49976 KB | Memory limit exceeded |
11 | Runtime error | 133 ms | 65536 KB | Execution killed with signal 9 |
12 | Runtime error | 132 ms | 65536 KB | Execution killed with signal 9 |
13 | Runtime error | 131 ms | 65536 KB | Execution killed with signal 9 |
14 | Runtime error | 102 ms | 65536 KB | Execution killed with signal 9 |
15 | Runtime error | 101 ms | 65536 KB | Execution killed with signal 9 |
16 | Runtime error | 101 ms | 65536 KB | Execution killed with signal 9 |
17 | Runtime error | 134 ms | 65536 KB | Execution killed with signal 9 |
18 | Runtime error | 133 ms | 65536 KB | Execution killed with signal 9 |
19 | Runtime error | 152 ms | 65536 KB | Execution killed with signal 9 |
20 | Runtime error | 150 ms | 65536 KB | Execution killed with signal 9 |