結果

問題 No.90 品物の並び替え
ユーザー vintersn0wvintersn0w
提出日時 2018-05-13 21:43:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,620 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 73,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 19:32:45
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>

using namespace std;
typedef uint uint32_t;

int N, M;
int scores[9][9] = {};
int score_f[9] = {}, score_b[9] = {};

void debug_print() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << scores[i][j] << '\t';
        }
        cout << score_b[i] << endl;
    }
    for (int i = 0; i < N; i++) {
        cout << score_f[i] << '\t';
    }
    cout << '\n' << endl;
}

int main() {
    cin >> N >> M;
    int i,j,s;
    for (int k = 0; k < M; k++) {
        cin >> i >> j >> s;
        scores[i][j] = s;
        score_f[j] += s;
        score_b[i] += s;
    }

    
    int ans[9] = {};
    int used[9] = {};
    for (int i = 0; i < N; i++) {
        // debug_print();
        int v=-1000, id=-1;
        for (int j = 0; j < N; j++) {
            if (used[j]) continue;
            if (score_b[j] - score_f[j] > v) {
                v = score_b[i] - score_f[i];
                id = j;
            }
        }
        ans[i] = id;
        used[id] = 1;
        for (int j = 0; j < N; j++) {
            score_b[j] -= scores[j][id];
            score_f[j] -= scores[id][j];
            // scores[id][j] = 0;
            // scores[j][id] = 0;
        }
        score_f[id] = 0;
        score_b[id] = 0;
    }
    
    // for (int i = 0; i < N; i++) {
    //     cout << ans[i] << ' ';
    // }
    // cout << endl;
    s = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i+1; j < N; j++) {
            s += scores[ans[i]][ans[j]];
        }
    }
    cout << s << endl;
}
0