답안 #951989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951989 2024-03-23T03:29:56 Z mocha Paths (BOI18_paths) C++14
70 / 100
225 ms 25524 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
using namespace std;
const int mx = 3e5+5;

int n, m, k;
int cnt[1<<5][mx];
int tmp[1<<5][mx];
int c[mx];
vector<pair<int, int>> e;
int ans1, ans2, ans3, ans4, ans5;
vector<int> nums[6];
int ans;

void init() {
	for (int i=0;i<1<<k;i++) {
		int ii=i, cnt=0;
		while (ii) {
			cnt += (ii&1);
			ii >>= 1;
		}
		nums[cnt].push_back(i);
	}
}

void get1() {
	for (auto [u, v]:e) {
		cnt[c[v]][u]++;
		cnt[c[u]][v]++;
	}
	for (int i=1;i<=n;i++) {
		for (int j:nums[1]) {	
			if (j == c[i]) continue;
			ans1 += cnt[j][i];
		}
	}
}

void get2() {
	for (int i=1;i<=n;i++) {
		for (int x = 1;x<1<<k;x<<=1) {
			if (x == c[i]) continue;
			for (int y = 1; y < 1<<k ; y<<=1) {
				if ( y == c[i] or x == y) continue;
				ans2 += cnt[x][i] * cnt[y][i];
			}
		}
	}
}

void get3() {
	for (auto [u, v]:e) {
		if (c[u] == c[v]) continue;
		for (int x = 1;x<1<<k;x<<=1) {
			if (x == c[u] or x == c[v]) continue;
			for (int y = 1; y < 1<<k ; y<<=1) {
				if (y == c[u] or y == c[v] or x == y) continue;
				ans2 += cnt[x][v] * cnt[y][u] * 2;
			}
		}
	}
}

void get4() {
	for (auto [u, v]:e) {	
		if (c[u] == c[v]) return;
		for (int i=1;i<1<<k;i<<=1) {
			if (i != c[u] and i != c[v]) {
				cnt[i|c[u]][v] += cnt[i][u];
				cnt[i|c[v]][u] += cnt[i][v];
			}
		}
	}
	int mask = 1<<5;
	mask--;
	for (int i=1;i<=n;i++) {
		for (int j:nums[2]) {
			if (j & c[i]) continue;
			int inv = (~(j&c[i])) & mask;
			ans3 += cnt[j][i] * cnt[inv][i] * 2;
		}
	}
}

signed main() {
	cin.tie(0);ios::sync_with_stdio(0);

	cin >> n >> m >> k;
	e.resize(m);
	init();
	for (int i=1;i<=n;i++) {
		int x;
		cin >> x; x--;
		c[i] = 1<<x;
	}
	for (int i=0;i<m;i++) {
		cin >> e[i].ff >> e[i].ss;
	}
	if (k == 1) {
		ans = 0;
	} else if (k == 2) {
		get1();
		ans = ans1;
	} else if (k == 3) {
		get1(); get2();
		ans = ans1 + ans2;
	} else if (k == 4) {
		get1(); get2(); get3();
		ans = ans1 + ans2 + ans3;
	} 
	cout << ans << "\n";
}

Compilation message

paths.cpp: In function 'void get1()':
paths.cpp:29:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |  for (auto [u, v]:e) {
      |            ^
paths.cpp: In function 'void get3()':
paths.cpp:54:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |  for (auto [u, v]:e) {
      |            ^
paths.cpp: In function 'void get4()':
paths.cpp:67:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |  for (auto [u, v]:e) {
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 7088 KB Output is correct
2 Correct 31 ms 6604 KB Output is correct
3 Correct 74 ms 16936 KB Output is correct
4 Correct 46 ms 7760 KB Output is correct
5 Correct 54 ms 7388 KB Output is correct
6 Correct 60 ms 13648 KB Output is correct
7 Correct 65 ms 17076 KB Output is correct
8 Correct 67 ms 17100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 35 ms 7088 KB Output is correct
12 Correct 31 ms 6604 KB Output is correct
13 Correct 74 ms 16936 KB Output is correct
14 Correct 46 ms 7760 KB Output is correct
15 Correct 54 ms 7388 KB Output is correct
16 Correct 60 ms 13648 KB Output is correct
17 Correct 65 ms 17076 KB Output is correct
18 Correct 67 ms 17100 KB Output is correct
19 Correct 55 ms 6732 KB Output is correct
20 Correct 36 ms 12572 KB Output is correct
21 Correct 66 ms 16952 KB Output is correct
22 Correct 54 ms 9928 KB Output is correct
23 Correct 58 ms 8000 KB Output is correct
24 Correct 57 ms 15360 KB Output is correct
25 Correct 95 ms 18236 KB Output is correct
26 Correct 71 ms 25524 KB Output is correct
27 Correct 38 ms 7260 KB Output is correct
28 Correct 74 ms 8140 KB Output is correct
29 Correct 225 ms 21004 KB Output is correct
30 Correct 96 ms 14904 KB Output is correct
31 Correct 66 ms 14972 KB Output is correct
32 Correct 90 ms 21224 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 0 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 2 ms 8800 KB Output is correct
41 Correct 1 ms 4560 KB Output is correct
42 Correct 0 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -