結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-15 21:51:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 286 ms / 5,000 ms |
| コード長 | 932 bytes |
| コンパイル時間 | 716 ms |
| コンパイル使用メモリ | 80,604 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 12:11:44 |
| 合計ジャッジ時間 | 1,703 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:33:13: warning: 'bpos' may be used uninitialized [-Wmaybe-uninitialized]
33 | if(apos < bpos) candidate += s;
| ^~
main.cpp:20:24: note: 'bpos' was declared here
20 | int a, b, s, apos, bpos, candidate;
| ^~~~
main.cpp:33:13: warning: 'apos' may be used uninitialized [-Wmaybe-uninitialized]
33 | if(apos < bpos) candidate += s;
| ^~
main.cpp:20:18: note: 'apos' was declared here
20 | int a, b, s, apos, bpos, candidate;
| ^~~~
ソースコード
#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;
}