結果

問題 No.90 品物の並び替え
コンテスト
ユーザー Ilag
提出日時 2020-06-15 21:13:44
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 674 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 957 ms
コンパイル使用メモリ 181,456 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-24 19:42:50
合計ジャッジ時間 1,632 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    int item1[m], item2[m], score[m];
    for (int i = 0; i < m; i++) {
        cin >> item1[i] >> item2[i] >> score[i];
    }
    int nums[n];
    for (int i = 0; i < n; i++) nums[i] = i;
    int ans = 0;
    do {
        int place[n];
        for (int i = 0; i < n; i++) place[nums[i]] = i;
        int cnt = 0;
        for (int i = 0; i < m; i++) {
            if (place[item1[i]] < place[item2[i]]) cnt += score[i];
        }
        ans = max(ans, cnt);
    } while (next_permutation(nums, nums + n));
    cout << ans << endl;
}
0