結果

問題 No.90 品物の並び替え
ユーザー face4face4
提出日時 2018-05-15 21:51:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 79,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 21:07:09
合計ジャッジ時間 2,767 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 23 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 27 ms
4,376 KB
testcase_06 AC 18 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 332 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:33:13: 警告: ‘bpos’ may be used uninitialized [-Wmaybe-uninitialized]
   33 |             if(apos < bpos) candidate += s;
      |             ^~
main.cpp:20:24: 備考: ‘bpos’ はここで定義されています
   20 |     int a, b, s, apos, bpos, candidate;
      |                        ^~~~
main.cpp:33:13: 警告: ‘apos’ may be used uninitialized [-Wmaybe-uninitialized]
   33 |             if(apos < bpos) candidate += s;
      |             ^~
main.cpp:20:18: 備考: ‘apos’ はここで定義されています
   20 |     int a, b, s, apos, bpos, candidate;
      |                  ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int arr[N];
    map<pair<int,int> , int> table;
    for(int i = 0; i < N; i++)  arr[i] = i;

    int item1, item2, score;
    for(int i = 0; i < M; i++){
        cin >> item1 >> item2 >> score;
        table[make_pair(item1,item2)] = score;
    }

    int res = 0;
    int a, b, s, apos, bpos, candidate;
    do{
        candidate = 0;
        for(auto it = table.begin(); it != table.end(); it++){
            a = it->first.first;
            b = it->first.second;
            s = it->second;

            for(int i = 0; i < N; i++){
                if(arr[i] == a) apos = i;
                if(arr[i] == b) bpos = i;
            }

            if(apos < bpos) candidate += s;
        }

        res = max(res, candidate);
    }while(next_permutation(arr, arr+N));

    cout << res << endl;

    return 0;
}
0