답안 #952948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952948 2024-03-25T07:00:08 Z koukirocks Paths (BOI18_paths) C++17
100 / 100
205 ms 78680 KB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
 
namespace{using namespace std;}
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=3e5+10+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
 
int n,m,k;
int clr[MAX];
vector<int> G[MAX];
ll dp[MAX][(1<<4)+10];

int main() {
	speed;
	cin>>n>>m>>k;
	for (int i=1;i<=n;i++) {
		cin>>clr[i];
		clr[i]--;
	}
	for (int i=0;i<m;i++) {
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	memset(dp,0,sizeof(dp));
	for (int i=1;i<=n;i++) {
		for (int j:G[i]) {
			if (clr[i]==clr[j]) continue;
			dp[i][(1<<clr[j])]++;
		}
	}
	for (int i=1;i<=n;i++) {
		for (int j:G[i]) {
			if (clr[i]==clr[j]) continue;
			for (int c=0;c<k;c++) {
				if (clr[i]==c) continue;
				dp[i][(1<<c)|(1<<clr[j])]+=dp[j][(1<<c)];
			}
		}
	}
//	for (int i=1;i<=n;i++) {
//		for (int s=0;s<(1<<k);s++) {
//			cout<<i<<" -> ";
//			for (int j=0;j<k;j++) {
//				if (s&(1<<j)) cout<<j<<" ";
//			}
//			cout<<"-> "<<dp[i][s]<<"\n";
//		}
//	}
	ll ans=0;
	if (k>=2) {
		for (int i=1;i<=n;i++) {
			for (int c=0;c<k;c++) {
				if (c==clr[i]) continue;
				ans+=dp[i][(1<<c)];
			}
		}
	}
//	cout<<ans<<"\n";
	if (k>=3) {
		for (int i=1;i<=n;i++) {
			for (int c1=0;c1<k;c1++) {
				if (c1==clr[i]) continue;
				for (int c2=c1+1;c2<k;c2++) {
					if (c2==clr[i]) continue;
					ans+=dp[i][(1<<c1)|(1<<c2)];
				}
			}
		}
	}
//	cout<<ans<<"\n";
	if (k>=4) {
		for (int i=1;i<=n;i++) {
			for (int s=7;s<(1<<k);s++) {
				if (__builtin_popcount(s)!=3) continue;
				if (s&(1<<clr[i])) continue;
				for (int c1=0;c1<k;c1++) {
					if (c1==clr[i]) continue;
					if (!(s&(1<<c1))) continue;
					ans+=dp[i][(1<<c1)]*dp[i][s^(1<<c1)];
				}
			}
		}
	}
//	cout<<ans<<"\n";
	if (k>=5) {
		for (int i=1;i<=n;i++) {
			int s=((1<<k)-1)^(1<<clr[i]);
			for (int c1=0;c1<k;c1++) {
				if (c1==clr[i]) continue;
				for (int c2=c1+1;c2<k;c2++) {
					if (c2==clr[i]) continue;
					ans+=dp[i][s^(1<<c1)^(1<<c2)]*dp[i][(1<<c1)|(1<<c2)];
//					cout<<i<<" "<<c1<<" "<<c2<<" "<<dp[i][s^(1<<c1)^(1<<c2)]<<" "<<dp[i][(1<<c1)|(1<<c2)]<<"\n";
				}
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 68440 KB Output is correct
2 Correct 13 ms 68444 KB Output is correct
3 Correct 13 ms 68444 KB Output is correct
4 Correct 15 ms 68440 KB Output is correct
5 Correct 10 ms 68440 KB Output is correct
6 Correct 10 ms 68444 KB Output is correct
7 Correct 10 ms 68500 KB Output is correct
8 Correct 11 ms 68440 KB Output is correct
9 Correct 10 ms 68440 KB Output is correct
10 Correct 10 ms 68464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 72080 KB Output is correct
2 Correct 49 ms 72096 KB Output is correct
3 Correct 193 ms 78028 KB Output is correct
4 Correct 75 ms 73040 KB Output is correct
5 Correct 71 ms 72892 KB Output is correct
6 Correct 141 ms 76256 KB Output is correct
7 Correct 187 ms 77960 KB Output is correct
8 Correct 174 ms 78680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 68440 KB Output is correct
2 Correct 13 ms 68444 KB Output is correct
3 Correct 13 ms 68444 KB Output is correct
4 Correct 15 ms 68440 KB Output is correct
5 Correct 10 ms 68440 KB Output is correct
6 Correct 10 ms 68444 KB Output is correct
7 Correct 10 ms 68500 KB Output is correct
8 Correct 11 ms 68440 KB Output is correct
9 Correct 10 ms 68440 KB Output is correct
10 Correct 10 ms 68464 KB Output is correct
11 Correct 69 ms 72080 KB Output is correct
12 Correct 49 ms 72096 KB Output is correct
13 Correct 193 ms 78028 KB Output is correct
14 Correct 75 ms 73040 KB Output is correct
15 Correct 71 ms 72892 KB Output is correct
16 Correct 141 ms 76256 KB Output is correct
17 Correct 187 ms 77960 KB Output is correct
18 Correct 174 ms 78680 KB Output is correct
19 Correct 59 ms 72060 KB Output is correct
20 Correct 47 ms 72016 KB Output is correct
21 Correct 205 ms 77868 KB Output is correct
22 Correct 74 ms 73080 KB Output is correct
23 Correct 68 ms 73040 KB Output is correct
24 Correct 134 ms 76344 KB Output is correct
25 Correct 199 ms 78288 KB Output is correct
26 Correct 190 ms 78572 KB Output is correct
27 Correct 50 ms 72020 KB Output is correct
28 Correct 60 ms 72788 KB Output is correct
29 Correct 202 ms 77948 KB Output is correct
30 Correct 155 ms 74748 KB Output is correct
31 Correct 144 ms 74932 KB Output is correct
32 Correct 195 ms 77904 KB Output is correct
33 Correct 10 ms 68440 KB Output is correct
34 Correct 10 ms 68444 KB Output is correct
35 Correct 10 ms 68444 KB Output is correct
36 Correct 10 ms 68540 KB Output is correct
37 Correct 10 ms 68444 KB Output is correct
38 Correct 11 ms 68444 KB Output is correct
39 Correct 10 ms 68444 KB Output is correct
40 Correct 10 ms 68696 KB Output is correct
41 Correct 11 ms 68440 KB Output is correct
42 Correct 10 ms 68440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 68444 KB Output is correct
2 Correct 23 ms 69464 KB Output is correct
3 Correct 23 ms 70332 KB Output is correct
4 Correct 53 ms 73044 KB Output is correct
5 Correct 45 ms 73672 KB Output is correct
6 Correct 72 ms 73040 KB Output is correct
7 Correct 22 ms 70228 KB Output is correct
8 Correct 65 ms 73076 KB Output is correct
9 Correct 50 ms 73620 KB Output is correct
10 Correct 56 ms 73456 KB Output is correct
11 Correct 44 ms 71628 KB Output is correct
12 Correct 55 ms 72752 KB Output is correct
13 Correct 61 ms 71920 KB Output is correct
14 Correct 71 ms 73076 KB Output is correct
15 Correct 70 ms 73316 KB Output is correct
16 Correct 10 ms 68440 KB Output is correct
17 Correct 10 ms 68440 KB Output is correct
18 Correct 10 ms 68444 KB Output is correct
19 Correct 10 ms 68444 KB Output is correct
20 Correct 10 ms 68568 KB Output is correct
21 Correct 10 ms 68696 KB Output is correct
22 Correct 10 ms 68440 KB Output is correct
23 Correct 10 ms 68440 KB Output is correct
24 Correct 10 ms 68440 KB Output is correct
25 Correct 10 ms 68444 KB Output is correct