답안 #743931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743931 2023-05-18T06:16:59 Z myrcella Cats or Dogs (JOI18_catdog) C++17
38 / 100
21 ms 4224 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

#include "catdog.h"

int x;

const int maxn  = 1010;
int dp[3][maxn];

int state[maxn];
vector <int> edge[maxn];

void initialize(int N, std::vector<int> A, std::vector<int> B) {
  rep(i,0,N-1) edge[A[i]].pb(B[i]), edge[B[i]].pb(A[i]);
}

void dfs(int u,int fa) {
	if (state[u]!=0) {
		int &ans = dp[state[u]][u];
		ans = 0;
		for (int v:edge[u]) {
			if (fa==v) continue;
			dfs(v,u);
			ans += min(dp[0][v],min(dp[state[u]][v],dp[3-state[u]][v]+1));
			ans = min(ans,mod);
		}
	}
	else {
		rep(i,0,3) dp[i][u] = 0;
		for (int v:edge[u]) {
			if (fa==v) continue;
			dfs(v,u);
			dp[0][u] += min(dp[0][v],min(dp[1][v],dp[2][v])+1);
			dp[1][u] += min(dp[0][v],min(dp[1][v],dp[2][v]+1));
			dp[2][u] += min(dp[0][v],min(dp[1][v]+1,dp[2][v]));
			rep(j,0,3) dp[j][u] = min(dp[j][u],mod);
		}
	}
	return;
}

int solve() {
	memset(dp,inf,sizeof(dp));
	dfs(1,-1);
	return min(dp[0][1],min(dp[1][1],dp[2][1]));
}

int cat(int v) {
	state[v] = 1;
	return solve();
}

int dog(int v) {
	state[v] = 2;
	return solve();
}

int neighbor(int v) {
	state[v] = 0;
	return solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 10 ms 388 KB Output is correct
18 Correct 12 ms 396 KB Output is correct
19 Correct 7 ms 388 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 18 ms 400 KB Output is correct
24 Correct 13 ms 340 KB Output is correct
25 Correct 7 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 19 ms 332 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 10 ms 388 KB Output is correct
18 Correct 12 ms 396 KB Output is correct
19 Correct 7 ms 388 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 18 ms 400 KB Output is correct
24 Correct 13 ms 340 KB Output is correct
25 Correct 7 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 19 ms 332 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Runtime error 21 ms 4224 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -