結果

問題 No.90 品物の並び替え
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-05-18 11:26:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 168,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 08:25:46
合計ジャッジ時間 2,231 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N, M;
    cin >> N >> M;
    vector<vector<int>> a(N, vector<int>(N, 0));
    rep(i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        a[x][y] = z;
    }

    vector<int> perm(N);
    iota(all(perm), 0);
    int ans = 0;
    do {
        int t = 0;
        rep(i, N) {
            rep2(j, i + 1, N) {
                t += a[perm[i]][perm[j]];
            }
        }
        ans = max(ans, t);
    } while( next_permutation(all(perm)) );

    cout << ans << endl;

}
0