From 939dc609f8f2cbd128ccb370d03b839cda635b35 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 13 Sep 2022 20:46:39 +0800 Subject: [PATCH] =?UTF-8?q?#6009.=20=E3=80=8C=E7=BD=91=E7=BB=9C=E6=B5=81?= =?UTF-8?q?=2024=20=E9=A2=98=E3=80=8D=E8=BD=AF=E4=BB=B6=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1578956 --- LibreOJ/6009/6009.cpp | 90 +++++++++++++++++++++++++++++++++++++ LibreOJ/6009/data/bug1.in | 3 ++ LibreOJ/6009/data/bug1.out | 3 ++ LibreOJ/6009/data/bug10.in | 3 ++ LibreOJ/6009/data/bug10.out | 3 ++ LibreOJ/6009/data/bug2.in | 3 ++ LibreOJ/6009/data/bug2.out | 3 ++ LibreOJ/6009/data/bug3.in | 3 ++ LibreOJ/6009/data/bug3.out | 3 ++ LibreOJ/6009/data/bug4.in | 3 ++ LibreOJ/6009/data/bug4.out | 3 ++ LibreOJ/6009/data/bug5.in | 3 ++ LibreOJ/6009/data/bug5.out | 3 ++ LibreOJ/6009/data/bug6.in | 3 ++ LibreOJ/6009/data/bug6.out | 3 ++ LibreOJ/6009/data/bug7.in | 3 ++ LibreOJ/6009/data/bug7.out | 3 ++ LibreOJ/6009/data/bug8.in | 3 ++ LibreOJ/6009/data/bug8.out | 3 ++ LibreOJ/6009/data/bug9.in | 3 ++ LibreOJ/6009/data/bug9.out | 3 ++ 21 files changed, 150 insertions(+) create mode 100644 LibreOJ/6009/6009.cpp create mode 100644 LibreOJ/6009/data/bug1.in create mode 100644 LibreOJ/6009/data/bug1.out create mode 100644 LibreOJ/6009/data/bug10.in create mode 100644 LibreOJ/6009/data/bug10.out create mode 100644 LibreOJ/6009/data/bug2.in create mode 100644 LibreOJ/6009/data/bug2.out create mode 100644 LibreOJ/6009/data/bug3.in create mode 100644 LibreOJ/6009/data/bug3.out create mode 100644 LibreOJ/6009/data/bug4.in create mode 100644 LibreOJ/6009/data/bug4.out create mode 100644 LibreOJ/6009/data/bug5.in create mode 100644 LibreOJ/6009/data/bug5.out create mode 100644 LibreOJ/6009/data/bug6.in create mode 100644 LibreOJ/6009/data/bug6.out create mode 100644 LibreOJ/6009/data/bug7.in create mode 100644 LibreOJ/6009/data/bug7.out create mode 100644 LibreOJ/6009/data/bug8.in create mode 100644 LibreOJ/6009/data/bug8.out create mode 100644 LibreOJ/6009/data/bug9.in create mode 100644 LibreOJ/6009/data/bug9.out diff --git a/LibreOJ/6009/6009.cpp b/LibreOJ/6009/6009.cpp new file mode 100644 index 00000000..296b9b58 --- /dev/null +++ b/LibreOJ/6009/6009.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 25, + M = 105; +const int INF = 0x3f3f3f3f; + +int n, m; +std::array a, b1, b2, f1, f2; +std::array dist; +std::array vis; + +bool check(int s, int i) { + if ((b1[i] | s) != s) return false; + if (b2[i] & s) return false; + + return true; +} + +void spfa(int s) { + std::fill(dist.begin(), dist.end(), INF); + + std::queue q; + q.push(s); + dist[s] = 0; + vis[s] = true; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + for (int i = 1; i <= m; i++) { + if (!check(u, i)) continue; + + int v = u ^ (u & f1[i]) | f2[i]; + + if (dist[u] + a[i] < dist[v]) { + dist[v] = dist[u] + a[i]; + + if (!vis[v]) { + q.push(v); + vis[v] = true; + } + } + } + + vis[u] = false; + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= m; i++) { + std::string b, f; + + cin >> a[i] >> b >> f; + + for (int j = 0; j < b.size(); j++) { + if (b[j] == '+') { + b1[i] = b1[i] | 1 << j; + } else if (b[j] == '-') { + b2[i] = b2[i] | 1 << j; + } + } + + for (int j = 0; j < f.size(); j++) { + if (f[j] == '-') { + f1[i] = f1[i] | 1 << j; + } else if (f[j] == '+') { + f2[i] = f2[i] | 1 << j; + } + } + } + + spfa((1 << n) - 1); + + cout << (dist[0] == INF ? 0 : dist[0]) << endl; + + return 0; +} diff --git a/LibreOJ/6009/data/bug1.in b/LibreOJ/6009/data/bug1.in new file mode 100644 index 00000000..cc9ec7dc --- /dev/null +++ b/LibreOJ/6009/data/bug1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30e2fa5d178b454a0ed39fd05a026400ebaca17c42d6bf68b11554b97a345114 +size 38 diff --git a/LibreOJ/6009/data/bug1.out b/LibreOJ/6009/data/bug1.out new file mode 100644 index 00000000..8bc2838d --- /dev/null +++ b/LibreOJ/6009/data/bug1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0c18a6a8d48da87994c100bbb324c758d413e95f0fa5135bd0738a692b4d56f +size 3 diff --git a/LibreOJ/6009/data/bug10.in b/LibreOJ/6009/data/bug10.in new file mode 100644 index 00000000..ac1c50af --- /dev/null +++ b/LibreOJ/6009/data/bug10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c64e23e1ab54931d0cfdb5bd5f8f75e5150d81b1d2b4d34ffa68c6222fde6c27 +size 4703 diff --git a/LibreOJ/6009/data/bug10.out b/LibreOJ/6009/data/bug10.out new file mode 100644 index 00000000..eb255f14 --- /dev/null +++ b/LibreOJ/6009/data/bug10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0209560c0238a2500a4bf731d2a3a7c7efe7891aa794b3fc045689500f37428 +size 6 diff --git a/LibreOJ/6009/data/bug2.in b/LibreOJ/6009/data/bug2.in new file mode 100644 index 00000000..879e3b24 --- /dev/null +++ b/LibreOJ/6009/data/bug2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5107b834b604d5453ec99b8642603ac5cd8e7238160b691e1df581be142c6e75 +size 38 diff --git a/LibreOJ/6009/data/bug2.out b/LibreOJ/6009/data/bug2.out new file mode 100644 index 00000000..9b23e792 --- /dev/null +++ b/LibreOJ/6009/data/bug2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bf7b3039c63bf5a50491fa3cfd8eb4e699d1ba1436315aef9cbe5711530354 +size 3 diff --git a/LibreOJ/6009/data/bug3.in b/LibreOJ/6009/data/bug3.in new file mode 100644 index 00000000..96fc4ab5 --- /dev/null +++ b/LibreOJ/6009/data/bug3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7893a75affc18a2bcbf567cd662571633da4f60852abb129e5f3b734c2a08502 +size 257 diff --git a/LibreOJ/6009/data/bug3.out b/LibreOJ/6009/data/bug3.out new file mode 100644 index 00000000..ca4cae92 --- /dev/null +++ b/LibreOJ/6009/data/bug3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92961e9752250efa971147344b22295db32d7b75e940e0971e5fb34f21d0bc67 +size 3 diff --git a/LibreOJ/6009/data/bug4.in b/LibreOJ/6009/data/bug4.in new file mode 100644 index 00000000..b179e241 --- /dev/null +++ b/LibreOJ/6009/data/bug4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f64fe701d58d0b8f95e2861882c47961e7a0759cc05051bd600435534803428 +size 80 diff --git a/LibreOJ/6009/data/bug4.out b/LibreOJ/6009/data/bug4.out new file mode 100644 index 00000000..9d49f52c --- /dev/null +++ b/LibreOJ/6009/data/bug4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69fa4dd4fdc0b43ba7ca7c997539c4500f03ab9b220228e2b1e97bd305397806 +size 3 diff --git a/LibreOJ/6009/data/bug5.in b/LibreOJ/6009/data/bug5.in new file mode 100644 index 00000000..cbe78194 --- /dev/null +++ b/LibreOJ/6009/data/bug5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf91edc0204d5946f85389f5ebc8a943223bea5ebd186e7622e04d98256656e8 +size 292 diff --git a/LibreOJ/6009/data/bug5.out b/LibreOJ/6009/data/bug5.out new file mode 100644 index 00000000..1975e331 --- /dev/null +++ b/LibreOJ/6009/data/bug5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fb2aaeaf3eef66b52db104118c30f62899f5f0df520350a94a8fcb843c0dfdf +size 3 diff --git a/LibreOJ/6009/data/bug6.in b/LibreOJ/6009/data/bug6.in new file mode 100644 index 00000000..c89b2a1c --- /dev/null +++ b/LibreOJ/6009/data/bug6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:076882132980b25f4936adf1874cd5a807c741cbb32224bffca4d017f00c2a74 +size 639 diff --git a/LibreOJ/6009/data/bug6.out b/LibreOJ/6009/data/bug6.out new file mode 100644 index 00000000..c4982cec --- /dev/null +++ b/LibreOJ/6009/data/bug6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2bb232cac786f7284bb237d193407e94f32ee0fbf64d27d0ae8b1642de44923 +size 4 diff --git a/LibreOJ/6009/data/bug7.in b/LibreOJ/6009/data/bug7.in new file mode 100644 index 00000000..53856617 --- /dev/null +++ b/LibreOJ/6009/data/bug7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e3cdbb265dc2050373bcfe35ee5265181b5a49b31a93cdc4ab76e11d3124aae +size 578 diff --git a/LibreOJ/6009/data/bug7.out b/LibreOJ/6009/data/bug7.out new file mode 100644 index 00000000..14b541dc --- /dev/null +++ b/LibreOJ/6009/data/bug7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12d3a4efa6646b3ece4782f70033b9785bf0d167b553c43e22579b031cea5c4d +size 4 diff --git a/LibreOJ/6009/data/bug8.in b/LibreOJ/6009/data/bug8.in new file mode 100644 index 00000000..f9737ffb --- /dev/null +++ b/LibreOJ/6009/data/bug8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0451f458a016a50c5c61621ab57c5246f87e328592cc14c464148fa981e180d6 +size 1307 diff --git a/LibreOJ/6009/data/bug8.out b/LibreOJ/6009/data/bug8.out new file mode 100644 index 00000000..929c46cd --- /dev/null +++ b/LibreOJ/6009/data/bug8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ddb5c6d217ea442d92dcdead04dade6263ea482787904ab5c50a86d142b3c07d +size 4 diff --git a/LibreOJ/6009/data/bug9.in b/LibreOJ/6009/data/bug9.in new file mode 100644 index 00000000..6fbccb06 --- /dev/null +++ b/LibreOJ/6009/data/bug9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b637211b0384eeaeb49ee1c58479e4d2432c66fc5cd890320eb23e5246a5220b +size 2964 diff --git a/LibreOJ/6009/data/bug9.out b/LibreOJ/6009/data/bug9.out new file mode 100644 index 00000000..82c9a7a1 --- /dev/null +++ b/LibreOJ/6009/data/bug9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a381d17a98b3ee89289225390d9f4c100bab8fabeb0c4cdc830b5a271303672a +size 5