結果

問題 No.2673 A present from B
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2024-03-15 23:49:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,712 bytes
コンパイル時間 3,612 ms
コンパイル使用メモリ 267,640 KB
実行使用メモリ 32,640 KB
最終ジャッジ日時 2024-03-15 23:50:45
合計ジャッジ時間 6,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 11 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Edge{
    int ton,tom,cost;
};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n,m;
    cin >> n >> m;
    vector<int> A(m);
    for (auto &a: A) cin >> a;
    const int INF = 1e9;

    vector<vector<vector<Edge>>> e(m+1,vector<vector<Edge>>(n));

    for (int i = 0; i < m+1; i++){
        int a = A[i];
        a--;
 
        for (int j = 0; j < n; j++){
            if (i < m){
                if (j == a){
                e[i][j].push_back({i+1,j+1,0});
                e[i][j+1].push_back({i+1,j,0});
            } else{
                e[i][j].push_back({i+1,j,0});
            }

            }
            
            if (j < n-1){
                e[i][j].push_back({i,j+1,1});
                e[i][j+1].push_back({i,j,1});
            }
            
        }
    }
    for (int i = 1; i < n; i++){
        vector<vector<int>> dist(m+1,vector<int>(n,INF));
        dist[0][i] = 0;

        using pos = pair<int,pair<int,int>>;
        priority_queue<pos,vector<pos>,greater<pos>> h;
        h.push({0,{0,i}});

        while (!h.empty()){
            pos now = h.top(); h.pop();

            int x = now.second.first;
            int y = now.second.second;
            int d = now.first;
            if (dist[x][y] != d) continue;

            for (auto& nex: e[x][y]){
                int nx = nex.ton;
                int ny = nex.tom;
                int nd = d + nex.cost;
                if (dist[nx][ny] > nd){
                    dist[nx][ny] = nd;
                    h.push({nd,{nx,ny}});
                }
            }
        }

        cout << dist[m][0] << " ";
    }

    cout << endl;

    return 0;
}
0