結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 22:18:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 975 bytes |
| コンパイル時間 | 1,623 ms |
| コンパイル使用メモリ | 171,048 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-10-03 13:43:38 |
| 合計ジャッジ時間 | 23,560 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 14 WA * 15 TLE * 1 -- * 8 |
コンパイルメッセージ
main.cpp: In function 'char target_char(int, int)':
main.cpp:14:1: warning: control reaches end of non-void function [-Wreturn-type]
14 | }
| ^
ソースコード
#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 '#';
}
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;
}