# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
73010 |
2018-08-27T13:13:55 Z |
IvanC |
None (JOI16_snowy) |
C++17 |
|
32 ms |
13312 KB |
#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int L_SZ = 1000;
const int MOD = 12;
static int dp[MAXN][MOD][2];
static vector<int> grafo[MAXN];
static int N,lastPtr,e1[MAXN],e2[MAXN],custo[MAXN];
static int resposta[MAXN],pai[MAXN],especial[MAXN],ini[MAXN],fim[MAXN];
static void dfs_build(int v,int p){
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
pai[u] = i;
dfs_build(u,v);
}
}
static void dfs_calculate(int v,int p,int dist){
if(especial[v]){
for(int i = ini[v], j = 0;i <= fim[v];i++,j++){
if(dist & (1 << j)) resposta[i] = 1;
else resposta[i] = 0;
}
}
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
dfs_calculate(u,v,dist + custo[i]);
}
}
static int solve(int v,int p,int depth,int cor){
if(dp[v][depth][cor] != -1) return dp[v][depth][cor];
int tot = cor;
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
if(depth == 1){
tot += solve(u,v,0,1);
}
else{
tot += min(solve(u,v,depth+1,0), solve(u,v,0,1) );
}
}
return dp[v][depth][cor] = tot;
}
static void recover_dp(int v,int p,int depth,int cor){
if(cor == 1 && v != 0){
especial[v] = 1;
ini[v] = lastPtr;
fim[v] = lastPtr + 8;
lastPtr += 9;
}
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
if(depth == 11){
recover_dp(u,v,0,1);
}
else{
if(solve(u,v,depth+1,0) <= solve(u,v,0,1)) recover_dp(u,v,depth+1,0);
else recover_dp(u,v,0,1);
}
}
}
void InitAnya(int n , int A[] , int B[]) {
memset(dp,-1,sizeof(dp));
N = n;
for(int i = 0;i<N-1;i++){
grafo[A[i]].push_back(i);
grafo[B[i]].push_back(i);
e1[i] = A[i];
e2[i] = B[i];
}
lastPtr = N - 1;
dfs_build(0,-1);
solve(0,-1,1,0);
recover_dp(0,-1,1,0);
especial[0] = 0;
}
void Anya(int C[]){
for(int i = 0;i<N-1;i++) custo[i] = C[i];
for(int i = 0;i<N-1;i++) resposta[i] = C[i];
dfs_calculate(0,-1,0);
for(int i = 0 ; i < 1000 ; i++) Save(i , resposta[i]);
}
#include "Borislib.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int L_SZ = 1000;
const int MOD = 12;
static int dp[MAXN][MOD][2];
static vector<int> grafo[MAXN];
static int N,lastPtr,e1[MAXN],e2[MAXN];
static int pai[MAXN],especial[MAXN],ini[MAXN],fim[MAXN];
static void dfs_build(int v,int p){
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
pai[u] = i;
dfs_build(u,v);
}
}
static int solve(int v,int p,int depth,int cor){
if(dp[v][depth][cor] != -1) return dp[v][depth][cor];
int tot = cor;
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
if(depth == 1){
tot += solve(u,v,0,1);
}
else{
tot += min(solve(u,v,depth+1,0), solve(u,v,0,1) );
}
}
return dp[v][depth][cor] = tot;
}
static void recover_dp(int v,int p,int depth,int cor){
if(cor == 1 && v != 0){
especial[v] = 1;
ini[v] = lastPtr;
fim[v] = lastPtr + 8;
lastPtr += 9;
}
for(int i : grafo[v]){
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
if(u == p) continue;
if(depth == 11){
recover_dp(u,v,0,1);
}
else{
if(solve(u,v,depth+1,0) <= solve(u,v,0,1)) recover_dp(u,v,depth+1,0);
else recover_dp(u,v,0,1);
}
}
}
static int doQuery(int v){
if(v == 0) return 0;
if(especial[v]){
int numero = 0;
for(int i = ini[v],j = 0;i <= fim[v];i++,j++){
if(Ask(i)) numero += (1 << j);
}
return numero;
}
else{
int i = pai[v];
int u = (e1[i] != v) ? (e1[i]) : (e2[i]);
return Ask(i) + doQuery(u);
}
}
void InitBoris(int n , int A[] , int B[]) {
memset(dp,-1,sizeof(dp));
N = n;
for(int i = 0;i<N-1;i++){
grafo[A[i]].push_back(i);
grafo[B[i]].push_back(i);
e1[i] = A[i];
e2[i] = B[i];
}
lastPtr = N - 1;
dfs_build(0,-1);
solve(0,-1,1,0);
recover_dp(0,-1,1,0);
}
int Boris(int city) {
return doQuery(city);
}
Compilation message
Anya.cpp: In function 'void Anya(int*)':
Anya.cpp:116:38: warning: iteration 510 invokes undefined behavior [-Waggressive-loop-optimizations]
for(int i = 0 ; i < 1000 ; i++) Save(i , resposta[i]);
~~~~^~~~~~~~~~~~~~~~~
Anya.cpp:116:20: note: within this loop
for(int i = 0 ; i < 1000 ; i++) Save(i , resposta[i]);
~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
876 KB |
Output is correct |
2 |
Correct |
4 ms |
1120 KB |
Output is correct |
3 |
Correct |
7 ms |
1560 KB |
Output is correct |
4 |
Correct |
9 ms |
1752 KB |
Output is correct |
5 |
Correct |
16 ms |
1864 KB |
Output is correct |
6 |
Correct |
13 ms |
2152 KB |
Output is correct |
7 |
Correct |
11 ms |
2208 KB |
Output is correct |
8 |
Correct |
13 ms |
2240 KB |
Output is correct |
9 |
Correct |
12 ms |
2272 KB |
Output is correct |
10 |
Correct |
18 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2336 KB |
Output is correct |
2 |
Correct |
16 ms |
2336 KB |
Output is correct |
3 |
Correct |
24 ms |
2432 KB |
Output is correct |
4 |
Correct |
16 ms |
2672 KB |
Output is correct |
5 |
Correct |
13 ms |
2816 KB |
Output is correct |
6 |
Correct |
18 ms |
2816 KB |
Output is correct |
7 |
Correct |
17 ms |
2880 KB |
Output is correct |
8 |
Correct |
16 ms |
2992 KB |
Output is correct |
9 |
Correct |
14 ms |
3104 KB |
Output is correct |
10 |
Correct |
19 ms |
3216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3584 KB |
Output is correct |
2 |
Correct |
24 ms |
4096 KB |
Output is correct |
3 |
Correct |
23 ms |
4608 KB |
Output is correct |
4 |
Correct |
24 ms |
5120 KB |
Output is correct |
5 |
Correct |
22 ms |
5632 KB |
Output is correct |
6 |
Correct |
21 ms |
6144 KB |
Output is correct |
7 |
Correct |
24 ms |
6656 KB |
Output is correct |
8 |
Correct |
26 ms |
7152 KB |
Output is correct |
9 |
Correct |
27 ms |
7680 KB |
Output is correct |
10 |
Correct |
25 ms |
8200 KB |
Output is correct |
11 |
Correct |
25 ms |
8712 KB |
Output is correct |
12 |
Correct |
27 ms |
9216 KB |
Output is correct |
13 |
Correct |
30 ms |
9720 KB |
Output is correct |
14 |
Correct |
32 ms |
10240 KB |
Output is correct |
15 |
Correct |
28 ms |
10736 KB |
Output is correct |
16 |
Correct |
26 ms |
11272 KB |
Output is correct |
17 |
Correct |
26 ms |
11784 KB |
Output is correct |
18 |
Correct |
24 ms |
12520 KB |
Output is correct |
19 |
Correct |
22 ms |
12800 KB |
Output is correct |
20 |
Correct |
24 ms |
13312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
13312 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |