結果

問題 No.90 品物の並び替え
ユーザー CleyLCleyL
提出日時 2020-02-05 19:35:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 778 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 74,252 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 04:22:21
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 15 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 17 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 171 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct nya{
    int pv,nx,scr;
};
int main(){
    int n,m;cin>>n>>m;
    vector<int> A(n);
    for(int i = 0; n > i; i++){
        A[i] = i;
    }
    vector<nya> Z(m);
    for(int i = 0; m > i; i++){
        cin>>Z[i].pv>>Z[i].nx>>Z[i].scr;
    }
    int ans = 0;
    do{
        int tmp = 0;
        for(int i = 0; m > i; i++){
            for(int j = 0; n > j; j++){
                if(A[j] == Z[i].pv){
                    tmp += Z[i].scr;
                    break;
                }
                if(A[j] == Z[i].nx){
                    break;
                }
            }
        }
        ans = max(ans,tmp);
    }while(next_permutation(A.begin(),A.end()));
    cout << ans << endl;
}
0