結果

問題 No.90 品物の並び替え
ユーザー nemunemunemunemu
提出日時 2024-01-13 16:37:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 705 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 75,204 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-13 16:37:54
合計ジャッジ時間 1,651 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// No.90 品物の並び替え
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> table(N, vector<int>(N, 0));
    for (int i = 0; i < M; ++i) {
        int a, b, s;
        cin >> a >> b >> s;
        table[a][b] = s;
    }
    vector<int> ord(N);
    for (int i = 0; i < N; ++i) ord[i] = i;
    int res = 0;
    do {
        int now = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = i + 1; j < N; ++j) {
                now += table[ord[i]][ord[j]];
            }
        }
        res = max(res, now);
    } while (next_permutation(ord.begin(), ord.end()));
    cout << res << endl;
}
0