結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2020-04-20 01:50:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,147 bytes |
| コンパイル時間 | 2,600 ms |
| コンパイル使用メモリ | 210,436 KB |
| 最終ジャッジ日時 | 2025-01-09 21:48:22 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 23 TLE * 10 MLE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T>
struct ShortestPath
{
int V, E;
int INVALID = -1;
std::vector<std::vector<std::pair<int, T>>> to;
ShortestPath() = default;
ShortestPath(int V) : V(V), E(0), to(V) {}
void add_edge(int s, int t, T len) {
assert(0 <= s and s < V);
assert(0 <= t and t < V);
to[s].emplace_back(t, len);
E++;
}
std::vector<T> dist;
std::vector<int> prev;
// Dijkstra algorithm
// Complexity: O(E log E)
void Dijkstra(int s) {
assert(0 <= s and s < V);
dist.assign(V, std::numeric_limits<T>::max());
dist[s] = 0;
prev.assign(V, INVALID);
using P = std::pair<T, int>;
std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
pq.emplace(0, s);
while(!pq.empty()) {
T d;
int v;
std::tie(d, v) = pq.top();
pq.pop();
if (dist[v] < d) continue;
for (auto nx : to[v]) {
T dnx = d + nx.second;
if (dist[nx.first] > dnx) {
dist[nx.first] = dnx, prev[nx.first] = v;
pq.emplace(dnx, nx.first);
}
}
}
}
};
int main()
{
int N, K;
cin >> N >> K;
ShortestPath<lint> graph(K * 3 + 1);
while (N--)
{
string S;
lint C;
cin >> S >> C;
REP(i, K * 3)
{
int now = i;
for (auto c : S)
{
if (now < K and c == 'J') now++;
if (now >= K and now < K * 2 and c == 'O') now++;
if (now >= K * 2 and now < K * 3 and c == 'I') now++;
}
graph.add_edge(i, now, C);
}
}
graph.Dijkstra(0);
cout << (graph.dist.back() > 4e18 ? -1 : graph.dist.back()) << '\n';
}
hitonanode