結果

問題 No.90 品物の並び替え
ユーザー eQeeQe
提出日時 2019-02-18 11:55:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,333 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 14:46:45
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 17 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll N, M;
    cin >> N >> M;
    ll i, j, k;
    ll g[11][11]={};
    vector<ll> v;
    ll fa[11]={};
    fa[0]=1;
    for(i=1; i<=N; i++) fa[i]=fa[i-1]*i;
    
    for(i=0; i<N; i++) v.pb(i);
    
    for(i=0; i<M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        g[a][b]=c;
    }
    
    ll ans=0;
    for(k=0; k<fa[N]; k++) {
        ll t=0;
        for(i=0; i<v.size(); i++) {
            for(j=i+1; j<v.size(); j++) {
                t+=g[v[i]][v[j]];
            }
        }
        chmax(ans, t);
        next_permutation(v.begin(), v.end());
    }
    pt(ans);
}



0