From fa53c652503f5243238930e79632d4b6374ec96b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 12 Nov 2022 15:45:01 +0800 Subject: [PATCH] =?UTF-8?q?#742.=20=E3=80=90IOI1998=E3=80=91Polygon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/64190 --- S2OJ/742/742.cpp | 67 ++++++++++++++++++++++++++++++++++++++ S2OJ/742/data/data1.in | 3 ++ S2OJ/742/data/data1.out | 3 ++ S2OJ/742/data/data2.in | 3 ++ S2OJ/742/data/data2.out | 3 ++ S2OJ/742/data/data3.in | 3 ++ S2OJ/742/data/data3.out | 3 ++ S2OJ/742/data/data4.in | 3 ++ S2OJ/742/data/data4.out | 3 ++ S2OJ/742/data/data5.in | 3 ++ S2OJ/742/data/data5.out | 3 ++ S2OJ/742/data/problem.conf | 3 ++ 12 files changed, 100 insertions(+) create mode 100644 S2OJ/742/742.cpp create mode 100644 S2OJ/742/data/data1.in create mode 100644 S2OJ/742/data/data1.out create mode 100644 S2OJ/742/data/data2.in create mode 100644 S2OJ/742/data/data2.out create mode 100644 S2OJ/742/data/data3.in create mode 100644 S2OJ/742/data/data3.out create mode 100644 S2OJ/742/data/data4.in create mode 100644 S2OJ/742/data/data4.out create mode 100644 S2OJ/742/data/data5.in create mode 100644 S2OJ/742/data/data5.out create mode 100644 S2OJ/742/data/problem.conf diff --git a/S2OJ/742/742.cpp b/S2OJ/742/742.cpp new file mode 100644 index 00000000..902f0f7e --- /dev/null +++ b/S2OJ/742/742.cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 55 << 1; + +int n, w[N], f[N][N], g[N][N], ans; +char op[N]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> op[i] >> w[i]; + w[n + i] = w[i]; + op[n + i] = op[i]; + } + + for (int i = 1; i <= (n << 1); i++) { + f[i][i] = g[i][i] = w[i]; + } + for (int len = 2; len <= n; len++) { + for (int l = 1, r = len; r <= n * 2; l++, r++) { + f[l][r] = std::numeric_limits::min(); + g[l][r] = std::numeric_limits::max(); + + for (int k = l; k < r; k++) { + int maxl = f[l][k], maxr = f[k + 1][r]; + int minl = g[l][k], minr = g[k + 1][r]; + + if (op[k + 1] == 't') { + f[l][r] = std::max(f[l][r], maxl + maxr); + g[l][r] = std::min(g[l][r], minl + minr); + } else { + int x1 = minl * minr, + x2 = minl * maxr, + x3 = maxl * minr, + x4 = maxl * maxr; + f[l][r] = std::max({f[l][r], x1, x2, x3, x4}); + g[l][r] = std::min({g[l][r], x1, x2, x3, x4}); + } + } + } + } + + ans = std::numeric_limits::min(); + for (int i = 1; i <= n; i++) { + ans = std::max(ans, f[i][n + i - 1]); + } + + cout << ans << endl; + + for (int i = 1; i <= n; i++) { + if (ans == f[i][i + n - 1]) { + cout << i << ' '; + } + } + + cout << endl; + + return 0; +} diff --git a/S2OJ/742/data/data1.in b/S2OJ/742/data/data1.in new file mode 100644 index 00000000..7e3c972b --- /dev/null +++ b/S2OJ/742/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d03f81b3dbaa354449308cd8fb51e87c0095caeb4d7d2557a51d39d66e43c10d +size 23 diff --git a/S2OJ/742/data/data1.out b/S2OJ/742/data/data1.out new file mode 100644 index 00000000..d3c2e8de --- /dev/null +++ b/S2OJ/742/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99e7ed897fe929f3b55a6fe16040f27e6b19b8094c2e3680ebb99b84f2862d3e +size 6 diff --git a/S2OJ/742/data/data2.in b/S2OJ/742/data/data2.in new file mode 100644 index 00000000..5fc2b82b --- /dev/null +++ b/S2OJ/742/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2df00d7063f9799a44973bc7416620fcede5c18097968f35928970f6b2d06eec +size 28 diff --git a/S2OJ/742/data/data2.out b/S2OJ/742/data/data2.out new file mode 100644 index 00000000..27e96c30 --- /dev/null +++ b/S2OJ/742/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79f32449ee9943aa13e957a364cdfdbf41f273c13505507f55056f2d3e0c98ef +size 7 diff --git a/S2OJ/742/data/data3.in b/S2OJ/742/data/data3.in new file mode 100644 index 00000000..ad8893f6 --- /dev/null +++ b/S2OJ/742/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c0c4971fccb40ce12f07f369a3651ae883891cd431dcf87840d1e9a820278aa +size 16 diff --git a/S2OJ/742/data/data3.out b/S2OJ/742/data/data3.out new file mode 100644 index 00000000..a5c4cf65 --- /dev/null +++ b/S2OJ/742/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82c1315e6c757f33c4a77ca58b2a184f5a88614470c05ec77f3d28918db6b8ae +size 4 diff --git a/S2OJ/742/data/data4.in b/S2OJ/742/data/data4.in new file mode 100644 index 00000000..ac0e8c39 --- /dev/null +++ b/S2OJ/742/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12fb94044ba0655a7f77a69322ecd1102fb95b513d926e606d8245fb2fc36d66 +size 124 diff --git a/S2OJ/742/data/data4.out b/S2OJ/742/data/data4.out new file mode 100644 index 00000000..ce071789 --- /dev/null +++ b/S2OJ/742/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6193558301505410613b4b739d76eef7d748e47f1c03e9154c02dca90f859464 +size 62 diff --git a/S2OJ/742/data/data5.in b/S2OJ/742/data/data5.in new file mode 100644 index 00000000..dad18898 --- /dev/null +++ b/S2OJ/742/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5edce7451d8d5542fd8d4751e2ac68560496021cd785e8175c16e75241a4a288 +size 208 diff --git a/S2OJ/742/data/data5.out b/S2OJ/742/data/data5.out new file mode 100644 index 00000000..9289f7de --- /dev/null +++ b/S2OJ/742/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac461cd93efe19adf6fb32cef1ca895a31660234a37bc75e47443101b7d7c94f +size 9 diff --git a/S2OJ/742/data/problem.conf b/S2OJ/742/data/problem.conf new file mode 100644 index 00000000..7624a79e --- /dev/null +++ b/S2OJ/742/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:baf0902e1fab7279f7568dc3e26d89dc98c4b94c2c581bc472d02ae17b08aca1 +size 192