結果

問題 No.2673 A present from B
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2024-03-16 00:01:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,626 bytes
コンパイル時間 3,449 ms
コンパイル使用メモリ 266,872 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2024-03-16 00:01:15
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 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 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 29 ms
9,856 KB
testcase_13 WA -
testcase_14 AC 49 ms
13,952 KB
testcase_15 AC 17 ms
7,040 KB
testcase_16 AC 16 ms
6,912 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 37 ms
11,904 KB
testcase_21 AC 80 ms
20,864 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 WA -
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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+1][j+1].push_back({i,j,0});
                e[i+1][j].push_back({i,j+1,0});
            } else{
                e[i+1][j].push_back({i,j,0});
            }

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

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

    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}});
            }
        }
    }

    for (int i = 1; i < n; i++){
        cout << dist[0][i] << " ";
    }

    cout << endl;

    return 0;
}
0