結果

問題 No.90 品物の並び替え
ユーザー noriocnorioc
提出日時 2014-12-07 19:37:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 172 ms / 5,000 ms
コード長 1,360 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 66,532 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 09:23:47
合計ジャッジ時間 1,502 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define For(i,x) for (int i=0; i<(int)(x); i++)

typedef vector<int> vi;

struct Score {
    int item1;
    int item2;
    int score;
};

int calc(int n, const std::vector<Score>& scores) {
    int maxscore = 0;

    vi v;
    For(i, n) v.push_back(i);
    
    do {
        vi indexes;
        for (int i = 0; i < v.size(); i++) {
            for (int j = 0; j < v.size(); j++) {
                if (i == v[j]) {
                    indexes.push_back(j);
                    break;
                }
            }
        }

        int score = 0;
        for (int i = 0; i < scores.size(); i++) {
            int item1 = scores[i].item1;
            int item2 = scores[i].item2;
            
            if (indexes[item1] < indexes[item2]) {
                score += scores[i].score;
            }
        }

        if (maxscore < score)
            maxscore = score;

    } while (next_permutation(v.begin(), v.end()));

    return maxscore;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    vector<Score> v;
    For(i, m) {
        int a, b, score;
        scanf("%d %d %d", &a, &b, &score);

        v.push_back((Score){ a, b, score });
    }

    printf("%d\n", calc(n, v));
}
0