답안 #725763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725763 2023-04-18T03:05:01 Z pavement Semafor (COI20_semafor) C++17
100 / 100
304 ms 940 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

using vv = vector<vector<int> >;

const int MOD = 1e9 + 7;
int M, N, K, X, Mpow = 1;

int msk[] = {0b01010, 0b01000, 0b10010, 0b11100, 0b01001, 0b10101, 0b00110, 0b11000, 0b10111, 0b11101};

vv mat_mul(vv a, vv b) {
	assert(a[0].size() == b.size());
	vv c(a.size(), vector<int>(b[0].size(), 0));
	for (int i = 0; i < (int)c.size(); i++)
		for (int j = 0; j < (int)c[0].size(); j++)
			for (int k = 0; k < (int)a[0].size(); k++)
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
	return c;
}

vv mat_exp(vv a, int k) {
	assert(a.size() == a[0].size());
	vv r(a.size(), vector<int>(a.size(), 0));
	for (int i = 0; i < (int)r.size(); i++) r[i][i] = 1;
	while (k) {
		if (k & 1ll) r = mat_mul(r, a);
		a = mat_mul(a, a);
		k >>= 1ll;
	}
	return r;
}

vector<int> get_ways(int k) {
	vv curr(5 * M + 1, vector<int>(5 * M + 1, 0));
	for (int i = 0; i <= 5 * M; i++) {
		if (i > 0) curr[i][i - 1] = i;
		if (i < 5 * M) curr[i][i + 1] = 5 * M - i;
	}
	auto res = mat_exp(curr, k);
	vector<int> ret(5 * M + 1, 0);
	for (int i = 0; i <= 5 * M; i++) ret[i] = res[i][0];
	return ret;
}

int diff(int x, int y) {
	int ret = 0;
	for (int k = 0; k < M; k++) {
		ret += __builtin_popcountll(msk[x % 10] ^ msk[y % 10]);
		x /= 10;
		y /= 10;
	}
	return ret;
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> M >> N >> K >> X;
	for (int i = 0; i < M; i++) Mpow *= 10;
	auto ways = get_ways(K);
	vv mat1(Mpow, vector<int>(Mpow, 0));
	for (int i = 0; i < Mpow; i++)
		for (int j = 0; j < Mpow; j++)
			mat1[i][j] = ways[diff(i, j)];
	auto adj = mat_exp(mat1, N / K);
	ways = get_ways(N % K);
	for (int i = 0; i < Mpow; i++) {
		int ans = 0;
		for (int j = 0; j < Mpow; j++)
			ans = (ans + adj[X][j] * ways[diff(i, j)]) % MOD;
		cout << ans << '\n';
	}
}

Compilation message

semafor.cpp:79:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   79 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 240 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 816 KB Output is correct
2 Correct 9 ms 784 KB Output is correct
3 Correct 9 ms 724 KB Output is correct
4 Correct 9 ms 724 KB Output is correct
5 Correct 9 ms 724 KB Output is correct
6 Correct 11 ms 724 KB Output is correct
7 Correct 10 ms 724 KB Output is correct
8 Correct 9 ms 724 KB Output is correct
9 Correct 9 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 844 KB Output is correct
2 Correct 154 ms 808 KB Output is correct
3 Correct 233 ms 804 KB Output is correct
4 Correct 304 ms 816 KB Output is correct
5 Correct 289 ms 940 KB Output is correct
6 Correct 271 ms 932 KB Output is correct
7 Correct 287 ms 820 KB Output is correct
8 Correct 278 ms 852 KB Output is correct
9 Correct 280 ms 772 KB Output is correct
10 Correct 274 ms 724 KB Output is correct
11 Correct 33 ms 724 KB Output is correct
12 Correct 13 ms 724 KB Output is correct
13 Correct 289 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 844 KB Output is correct
2 Correct 154 ms 808 KB Output is correct
3 Correct 233 ms 804 KB Output is correct
4 Correct 304 ms 816 KB Output is correct
5 Correct 289 ms 940 KB Output is correct
6 Correct 271 ms 932 KB Output is correct
7 Correct 287 ms 820 KB Output is correct
8 Correct 278 ms 852 KB Output is correct
9 Correct 280 ms 772 KB Output is correct
10 Correct 274 ms 724 KB Output is correct
11 Correct 33 ms 724 KB Output is correct
12 Correct 13 ms 724 KB Output is correct
13 Correct 289 ms 776 KB Output is correct
14 Correct 30 ms 724 KB Output is correct
15 Correct 115 ms 820 KB Output is correct
16 Correct 176 ms 724 KB Output is correct
17 Correct 233 ms 812 KB Output is correct
18 Correct 250 ms 788 KB Output is correct
19 Correct 212 ms 768 KB Output is correct
20 Correct 253 ms 900 KB Output is correct
21 Correct 278 ms 772 KB Output is correct
22 Correct 285 ms 812 KB Output is correct
23 Correct 230 ms 804 KB Output is correct
24 Correct 241 ms 780 KB Output is correct
25 Correct 239 ms 928 KB Output is correct
26 Correct 17 ms 820 KB Output is correct
27 Correct 26 ms 724 KB Output is correct
28 Correct 178 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 816 KB Output is correct
2 Correct 9 ms 784 KB Output is correct
3 Correct 9 ms 724 KB Output is correct
4 Correct 9 ms 724 KB Output is correct
5 Correct 9 ms 724 KB Output is correct
6 Correct 11 ms 724 KB Output is correct
7 Correct 10 ms 724 KB Output is correct
8 Correct 9 ms 724 KB Output is correct
9 Correct 9 ms 724 KB Output is correct
10 Correct 58 ms 844 KB Output is correct
11 Correct 154 ms 808 KB Output is correct
12 Correct 233 ms 804 KB Output is correct
13 Correct 304 ms 816 KB Output is correct
14 Correct 289 ms 940 KB Output is correct
15 Correct 271 ms 932 KB Output is correct
16 Correct 287 ms 820 KB Output is correct
17 Correct 278 ms 852 KB Output is correct
18 Correct 280 ms 772 KB Output is correct
19 Correct 274 ms 724 KB Output is correct
20 Correct 33 ms 724 KB Output is correct
21 Correct 13 ms 724 KB Output is correct
22 Correct 289 ms 776 KB Output is correct
23 Correct 30 ms 724 KB Output is correct
24 Correct 115 ms 820 KB Output is correct
25 Correct 176 ms 724 KB Output is correct
26 Correct 233 ms 812 KB Output is correct
27 Correct 250 ms 788 KB Output is correct
28 Correct 212 ms 768 KB Output is correct
29 Correct 253 ms 900 KB Output is correct
30 Correct 278 ms 772 KB Output is correct
31 Correct 285 ms 812 KB Output is correct
32 Correct 230 ms 804 KB Output is correct
33 Correct 241 ms 780 KB Output is correct
34 Correct 239 ms 928 KB Output is correct
35 Correct 17 ms 820 KB Output is correct
36 Correct 26 ms 724 KB Output is correct
37 Correct 178 ms 772 KB Output is correct
38 Correct 13 ms 828 KB Output is correct
39 Correct 9 ms 724 KB Output is correct
40 Correct 10 ms 712 KB Output is correct
41 Correct 10 ms 708 KB Output is correct
42 Correct 10 ms 788 KB Output is correct
43 Correct 10 ms 788 KB Output is correct
44 Correct 12 ms 824 KB Output is correct
45 Correct 277 ms 804 KB Output is correct
46 Correct 274 ms 788 KB Output is correct
47 Correct 14 ms 724 KB Output is correct
48 Correct 10 ms 780 KB Output is correct
49 Correct 10 ms 788 KB Output is correct
50 Correct 9 ms 704 KB Output is correct
51 Correct 9 ms 724 KB Output is correct
52 Correct 91 ms 772 KB Output is correct