結果
問題 | No.1029 JJOOII 3 |
ユーザー |
|
提出日時 | 2020-04-17 22:19:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 982 bytes |
コンパイル時間 | 1,436 ms |
コンパイル使用メモリ | 172,864 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-03 13:46:37 |
合計ジャッジ時間 | 23,150 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 TLE * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll INF = 1e17; inline char target_char(int nexi, int K) { if (nexi < K) return 'J'; if (nexi < 2 * K) return 'O'; if (nexi < 3 * K) return 'I'; else return '#'; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, K; cin >> n >> K; vector<string> s(n); vector<ll> c(n); for (int i = 0; i < n; ++i) { cin >> s[i] >> c[i]; } vector<ll> dp(3 * K + 1, INF); dp[0] = 0; for (int i = 0; i < 3 * K; ++i) { if (dp[i] >= INF) continue; for (int j = 0; j < n; ++j) { int nexi = i; for (char ch : s[j]) { char tar = target_char(nexi, K); if (tar == ch) ++nexi; } if (nexi == i) continue; dp[nexi] = min(dp[nexi], dp[i] + c[j]); } } cout << (dp[3 * K] >= INF ? -1 : dp[3 * K]) << "\n"; return 0; }