結果

問題 No.90 品物の並び替え
ユーザー ikdikd
提出日時 2016-07-29 21:14:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 475 ms / 5,000 ms
コード長 713 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 64,348 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 10:52:47
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 35 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 38 ms
6,944 KB
testcase_06 AC 27 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 475 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#define pb push_back

using namespace std;

int main(){

    int N, M;
    cin>> N>> M;
    vector<int> o1, o2, s;
    for(int i=0; i<M; i++){
        int x, y, z;
        cin>> x>> y>> z;
        o1.pb(x); o2.pb(y); s.pb(z);
    }

    vector<int> id;
    for(int i=0; i<N; i++){
        id.pb(i);
    }
    int ans=-1;
    do{
        int sum=0;
        for(int i=0; i<M; i++){
            auto it1=find(id.begin(), id.end(), o1[i]);
            auto it2=find(id.begin(), id.end(), o2[i]);
            if(it1<it2) sum+=s[i];
        }
        ans=max(ans, sum);
    }while(next_permutation(id.begin(), id.end()));

    cout<< ans<< endl;

    return 0;
}
0