diff --git a/LibreOJ/10172/10172.cpp b/LibreOJ/10172/10172.cpp new file mode 100644 index 00000000..8b74613b --- /dev/null +++ b/LibreOJ/10172/10172.cpp @@ -0,0 +1,107 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 10005, + M = 6; + +const int mod = 1e6; + +int n, m, k, t, a[M], f[N][245], ans; +std::string ks; +std::vector r; + +void dfs(std::string s) { + if (s.size() >= m) { + if (s == ks) t = r.size(); + r.push_back(s); + + return; + } + + if (s.back() == '1') dfs(s + '2'), dfs(s + '3'); + else if (s.back() == '2') dfs(s + '1'), dfs(s + '3'); + else dfs(s + '1'), dfs(s + '2'); +} + +bool check(std::string s) { + for (int i = 1; i < s.size(); i++) { + if (s[i] == s[i - 1]) return false; + } + + return true; +} + +bool check(std::string s1, std::string s2) { + for (int i = 0; i < s1.size(); i++) { + if (s1[i] == s2[i]) return false; + } + + return true; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> k; + + for (int i = 1; i <= m; i++) { + cin >> a[i]; + ks.push_back(a[i] + '0'); + } + + if (!check(ks)) { + cout << 0 << endl; + + exit(0); + } + + dfs("1"); + dfs("2"); + dfs("3"); + + if (k == 1) { + f[1][t] = 1; + } else { + for (int i = 0; i < r.size(); i++) { + f[1][i] = 1; + } + } + + for (int i = 2; i <= n; i++) { + if (i == k) { + for (int j = 0; j < r.size(); j++) { + if (check(r[t], r[j])) { + f[i][t] = (f[i][t] + f[i - 1][j]) % mod; + } + } + } else { + for (int j = 0; j < r.size(); j++) { + if (i - 1 == k) { + if (check(r[t], r[j])) { + f[i][j] = (f[i][j] + f[i - 1][t]) % mod; + } + } else { + for (int k = 0; k < r.size(); k++) { + if (check(r[j], r[k])) { + f[i][j] = (f[i][j] + f[i - 1][k]) % mod; + } + } + } + } + } + } + + for (int i = 0; i < r.size(); i++) { + ans = (ans + f[n][i]) % mod; + } + + cout << ans << endl; + + return 0; +} diff --git a/LibreOJ/10172/data/paint1.in b/LibreOJ/10172/data/paint1.in new file mode 100644 index 00000000..884e8fa2 --- /dev/null +++ b/LibreOJ/10172/data/paint1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:328b581019b9cbe1cd53a60cb77173cb727008acc7a20a9e501c9eb3197b1450 +size 11 diff --git a/LibreOJ/10172/data/paint1.out b/LibreOJ/10172/data/paint1.out new file mode 100644 index 00000000..c60201c3 --- /dev/null +++ b/LibreOJ/10172/data/paint1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f1b2f662800122bed0ff255693df89c4487fbdcf453d3524a42d4ec20c3d9c04 +size 3 diff --git a/LibreOJ/10172/data/paint10.in b/LibreOJ/10172/data/paint10.in new file mode 100644 index 00000000..a7434072 --- /dev/null +++ b/LibreOJ/10172/data/paint10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ba9a37e38169822e636deea90cd1369161a9c4f15a7018f1d0cf59c07c7d32c +size 27 diff --git a/LibreOJ/10172/data/paint10.out b/LibreOJ/10172/data/paint10.out new file mode 100644 index 00000000..aca9d25e --- /dev/null +++ b/LibreOJ/10172/data/paint10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ab13bcf2eaaa82057f2b40abe4e230dcf8d3260e3987143f5579e186b5836c2 +size 8 diff --git a/LibreOJ/10172/data/paint2.in b/LibreOJ/10172/data/paint2.in new file mode 100644 index 00000000..e5e6d8c3 --- /dev/null +++ b/LibreOJ/10172/data/paint2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84697417c64e2029e3ce6f67179297556eff4ba065c6f02eeb5045c049675a7a +size 15 diff --git a/LibreOJ/10172/data/paint2.out b/LibreOJ/10172/data/paint2.out new file mode 100644 index 00000000..1e33e162 --- /dev/null +++ b/LibreOJ/10172/data/paint2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:795bf538674d285c2ed086effac6c17e132375d030b26c1553d1ae63ebd6d695 +size 6 diff --git a/LibreOJ/10172/data/paint3.in b/LibreOJ/10172/data/paint3.in new file mode 100644 index 00000000..731eb382 --- /dev/null +++ b/LibreOJ/10172/data/paint3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:26291540bb1480fc58fd368d0ad0cc24863110554953d099f42f128452ab9e05 +size 15 diff --git a/LibreOJ/10172/data/paint3.out b/LibreOJ/10172/data/paint3.out new file mode 100644 index 00000000..0c8475bb --- /dev/null +++ b/LibreOJ/10172/data/paint3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:668c1cfabe6968ca01f9cf58a6e36edbc533bb98ce10cb4970bf0c464c572c48 +size 7 diff --git a/LibreOJ/10172/data/paint4.in b/LibreOJ/10172/data/paint4.in new file mode 100644 index 00000000..b4f8c3fd --- /dev/null +++ b/LibreOJ/10172/data/paint4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d30f9aea5898597c39ef1ee8c6ecd5b7c9c7dc100e1ec4775cde652f6eb0cb7 +size 14 diff --git a/LibreOJ/10172/data/paint4.out b/LibreOJ/10172/data/paint4.out new file mode 100644 index 00000000..22a74dfe --- /dev/null +++ b/LibreOJ/10172/data/paint4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d15789b789e5b1aa77d1d690fa51e2e754b4f7e70a78b397bea6a374e3a910f +size 8 diff --git a/LibreOJ/10172/data/paint5.in b/LibreOJ/10172/data/paint5.in new file mode 100644 index 00000000..998a069c --- /dev/null +++ b/LibreOJ/10172/data/paint5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df2145f542ed244b5eb90985248415e1a8034c8c16c80763f7741fc440084934 +size 19 diff --git a/LibreOJ/10172/data/paint5.out b/LibreOJ/10172/data/paint5.out new file mode 100644 index 00000000..50a9816c --- /dev/null +++ b/LibreOJ/10172/data/paint5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50f23284e0ca4cb6ec430a540cd3f0f893f0e6fcb5da633e718537b635f94b5b +size 8 diff --git a/LibreOJ/10172/data/paint6.in b/LibreOJ/10172/data/paint6.in new file mode 100644 index 00000000..ee4a24a3 --- /dev/null +++ b/LibreOJ/10172/data/paint6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ba9b8e35ba95b4c87114690dd567a0e361c88a7beb5e37f4b54e9a243d12f97f +size 16 diff --git a/LibreOJ/10172/data/paint6.out b/LibreOJ/10172/data/paint6.out new file mode 100644 index 00000000..5cf19d70 --- /dev/null +++ b/LibreOJ/10172/data/paint6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e29d4a50eafbb55b6dd0129f9ecf639d79bb3906cf44ca25a61d0a5ae4463557 +size 8 diff --git a/LibreOJ/10172/data/paint7.in b/LibreOJ/10172/data/paint7.in new file mode 100644 index 00000000..0a657143 --- /dev/null +++ b/LibreOJ/10172/data/paint7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a77ddb73a2fecbb65c84ec263184cd35596b90342423a49cb9d32554d68b4b27 +size 23 diff --git a/LibreOJ/10172/data/paint7.out b/LibreOJ/10172/data/paint7.out new file mode 100644 index 00000000..f0bfc8a2 --- /dev/null +++ b/LibreOJ/10172/data/paint7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05a4d96e0da7b5dc3b09234b44f03b0a4d752aaa7da787d693b4532e0769feb3 +size 8 diff --git a/LibreOJ/10172/data/paint8.in b/LibreOJ/10172/data/paint8.in new file mode 100644 index 00000000..9878c609 --- /dev/null +++ b/LibreOJ/10172/data/paint8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ebeda37caec45e0564a61c2f27c1b87c139b6ead40121cf7ea757a3690b55ff +size 25 diff --git a/LibreOJ/10172/data/paint8.out b/LibreOJ/10172/data/paint8.out new file mode 100644 index 00000000..9b23e792 --- /dev/null +++ b/LibreOJ/10172/data/paint8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bf7b3039c63bf5a50491fa3cfd8eb4e699d1ba1436315aef9cbe5711530354 +size 3 diff --git a/LibreOJ/10172/data/paint9.in b/LibreOJ/10172/data/paint9.in new file mode 100644 index 00000000..81965de4 --- /dev/null +++ b/LibreOJ/10172/data/paint9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edd383595d199db6cb53b3f71cc2743576c36b58bb08109e41f0a85e40855cc8 +size 22 diff --git a/LibreOJ/10172/data/paint9.out b/LibreOJ/10172/data/paint9.out new file mode 100644 index 00000000..c6a60bfd --- /dev/null +++ b/LibreOJ/10172/data/paint9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33a4e87e1aaf85b251ea7d9231f755982b741a18840fded611d2b3b09df65d40 +size 8