結果

問題 No.90 品物の並び替え
ユーザー kpinkcatkpinkcat
提出日時 2023-10-15 18:52:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 5,000 ms
コード長 883 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 109,412 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-15 18:52:50
合計ジャッジ時間 1,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;



int main(){
    ll n, m, ans = 0;
    cin >> n >> m;
    vector<vector<int>> list(m, vector<int>(3));
    vector<int> arr(n);
    for (int i = 0; i < n; i++) arr[i] = i;
    for (int i = 0; i < m; i++) cin >> list[i][0] >> list[i][1] >> list[i][2];
    
    do {
        ll tmp = 0;
        for (int i = 0; i < m; i++){
            int f = -1, b = -1;
            for (int j = 0; j < n; j++){
                if (arr[j] == list[i][0]) f = j;
                if (arr[j] == list[i][1]) b = j;
            }
            if (f < b) tmp += list[i][2];
        }
        ans = max(ans, tmp);
    }while (next_permutation(arr.begin(), arr.end()));
    cout << ans << endl;
}
0