結果

問題 No.90 品物の並び替え
ユーザー nenuonnenuon
提出日時 2017-03-01 22:28:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,404 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 77,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 17:11:28
合計ジャッジ時間 1,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//方針
//Nが小さいので順列を全探索しても9!=362880パターン=4*10^5くらい
//得られる点数は2重ループで計算する0(M*M/2)
//ギリギリ?

int main(){
    int N, M;
    cin >> N >> M;

    //点数を保存score[後][前]
    int score[N][N];
    //memset(score, 0, sizeof(score));
    FOR(i, 0, N) FOR(j, 0, N) score[i][j] = 0;
    FOR(i, 0, M){
        int item1, item2, tmpscore;
        cin >> item1 >> item2 >> tmpscore;
        score[item2][item1] = tmpscore;
    }

    //全探索0~N-1の並び替え
    vector<int> v;
    FOR(i, 0, N) v.push_back(i);
    int ans = 0;
    do{
        int ret = 0;
        //v[usiro]が後ろにある数字v[mae]が前にある数字
        //なのでそれをscoreの配列に入れて点数を調べる
        FOR(usiro, 1, N){
            FOR(mae, 0, usiro){
                ret += score[v[usiro]][v[mae]];
            }
        }
        ans = max(ans, ret);
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}
0