結果

問題 No.90 品物の並び替え
ユーザー KotRmKotRm
提出日時 2019-03-18 03:53:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,008 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 59,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 19:15:49
合計ジャッジ時間 1,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define print(x) cout << x << endl;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    
    /*next_permutation用の要素配列*/
    int arr[N];
    int A, B, S;
    REP(i, N){
        arr[i] = i;
    }
    
    /*P[item1][item2]=Scoreとして格納*/
    int P[9][9];
    Fill(P, 0);
    REP(i, M){
        cin >> A >> B >> S;
        P[A][B] = S;
    }
    
    int ans = 0;
    int sum;
    do{
        sum = 0;
        FOR(i,0, N){
            FOR(j,i+1,N){
                sum += P[arr[i]][arr[j]];
            }
        }
        ans = max(ans, sum);
    }while(next_permutation(arr, arr + N));
    
    print(ans);
    return 0;
}
0