結果
問題 | No.1029 JJOOII 3 |
ユーザー | QCFium |
提出日時 | 2020-04-17 22:00:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,115 bytes |
コンパイル時間 | 1,474 ms |
コンパイル使用メモリ | 172,676 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-03 12:55:18 |
合計ジャッジ時間 | 22,076 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,820 KB |
testcase_01 | AC | 4 ms
6,816 KB |
testcase_02 | AC | 6 ms
6,816 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 527 ms
6,816 KB |
testcase_16 | AC | 512 ms
6,820 KB |
testcase_17 | AC | 503 ms
6,816 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 562 ms
6,816 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | AC | 4 ms
6,816 KB |
testcase_38 | WA | - |
testcase_39 | AC | 5 ms
6,816 KB |
testcase_40 | AC | 5 ms
6,820 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:47, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In member function '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+(difference_type) const [with _Iterator = int*; _Container = std::vector<int>]', inlined from 'int main()' at main.cpp:67:26: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_iterator.h:1144:47: warning: 'right' may be used uninitialized [-Wmaybe-uninitialized] 1144 | { return __normal_iterator(_M_current + __n); } | ^~~ main.cpp: In function 'int main()': main.cpp:67:29: note: 'right' was declared here 67 | int right = std::count(s[i].begin() + right, s[i].end(), 2); | ^~~~~
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int need = ri(); std::vector<int> s[n]; int cost[n]; for (int i = 0; i < n; i++) { std::string tmp; std::cin >> tmp; for (auto j : tmp) s[i].push_back(j == 'J' ? 0 : j == 'O' ? 1 : 2); cost[i] = ri(); } int64_t dp[3][100001]; for (auto &i : dp) for (auto &j : i) j = 1000000000000000000; for (int i = 0; i < 3; i++) { dp[i][0] = 0; for (int j = 0; j < n; j++) { int cnt = std::count(s[j].begin(), s[j].end(), i); for (int k = 100000; k >= 0; k--) dp[i][std::min(100000, k + cnt)] = std::min(dp[i][std::min(100000, k + cnt)], dp[i][k] + cost[j]); } for (int j = 100000; j; j--) dp[i][j - 1] = std::min(dp[i][j - 1], dp[i][j]); } // two int64_t res = 1000000000000000000; for (int i = 0; i < n; i++) { for (int j = 0; j <= (int) s[i].size(); j++) { int left0 = std::count(s[i].begin(), s[i].begin() + j, 0); int right0 = std::count(s[i].begin() + j, s[i].end(), 1); for (int k = 0; k < n; k++) { for (int l = 0; l <= (int) s[k].size(); l++) { int left1 = std::count(s[k].begin(), s[k].begin() + l, 1); int right1 = std::count(s[k].begin() + l, s[k].end(), 2); int need0 = std::max(0, need - left0); int need1 = std::max(0, need - right0 - left1); int need2 = std::max(0, need - right1); res = std::min(res, dp[0][need0] + dp[1][need1] + dp[2][need2] + cost[i] + cost[k]); } } } } // one for (int i = 0; i < n; i++) { for (int j = 0; j < (int) s[i].size(); j++) { int left = std::count(s[i].begin(), s[i].begin() + j, 0); int head = s[i].size(); int cnt = 0; for (int k = j; k < (int) s[i].size(); k++) { if (s[i][k] == 1) cnt++; if (cnt >= need) { head = k; break; } } if (head == (int) s[i].size()) break; head++; int right = std::count(s[i].begin() + right, s[i].end(), 2); res = std::min(res, cost[i] + dp[0][std::max(0, need - left)] + dp[2][std::max(0, need - right)]); } } printf("%" PRId64 "\n", res == 1000000000000000000 ? -1 : res); return 0; }