結果
問題 | No.1029 JJOOII 3 |
ユーザー |
![]() |
提出日時 | 2020-04-17 22:19:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 894 bytes |
コンパイル時間 | 3,062 ms |
コンパイル使用メモリ | 198,576 KB |
最終ジャッジ日時 | 2025-01-09 20:14:47 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 TLE * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; string t = string(k, 'J') + string(k, 'O') + string(k, 'I'); int m = t.size(); vector dp(m + 1, inf<long long>); dp[m] = 0; vector<string> s(n); vector<int> cost(n); for (int i = 0; i < n; ++i) { cin >> s[i] >> cost[i]; } for (int j = m; j--; ) { for (int i = 0; i < n; ++i) { int ptr = j; for (char c : s[i]) { if (ptr < m) { ptr += c == t[ptr]; } } chmin(dp[j], cost[i] + dp[ptr]); } } if (dp[0] >= inf<long long>) { dp[0] = -1; } cout << dp[0] << '\n'; }