結果

問題 No.2673 A present from B
ユーザー RubikunRubikun
提出日時 2024-03-15 22:58:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,363 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 204,840 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 22:58:41
合計ジャッジ時間 3,914 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=505,INF=1<<30;

int dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<int> A(M);
    for(int i=0;i<M;i++){
        int x;cin>>x;x--;
        A[i]=x;
    }
    reverse(all(A));
    
    for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) dp[i][j]=INF;
    
    dp[0][0]=0;
    
    for(int i=0;i<=M;i++){
        for(int a=0;a<N;a++){
            for(int b=0;b<N;b++){
                chmin(dp[i][a],dp[i][b]+abs(a-b));
            }
        }
        if(i==M) break;
        for(int a=0;a<N;a++){
            if(a==A[i]){
                dp[i+1][a]=dp[i][a+1];
            }else if(a==A[i]+1){
                dp[i+1][a]=dp[i][a-1];
            }else{
                dp[i+1][a]=dp[i][a];
            }
        }
    }
    
    for(int i=1;i<N;i++){
        if(i>1) cout<<" ";
        cout<<dp[M][i];
    }
    cout<<endl;
}

0