結果

問題 No.1029 JJOOII 3
ユーザー 👑 hitonanodehitonanode
提出日時 2020-04-20 01:50:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,147 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 210,160 KB
実行使用メモリ 597,136 KB
最終ジャッジ日時 2024-04-16 00:27:29
合計ジャッジ時間 39,397 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 163 ms
33,792 KB
testcase_04 AC 662 ms
128,664 KB
testcase_05 TLE -
testcase_06 AC 1,832 ms
381,696 KB
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 1,500 ms
325,400 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 1,691 ms
399,668 KB
testcase_16 AC 1,906 ms
482,176 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0