結果
| 問題 | No.90 品物の並び替え |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2014-12-07 19:37:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 159 ms / 5,000 ms |
| コード長 | 1,360 bytes |
| 記録 | |
| コンパイル時間 | 654 ms |
| コンパイル使用メモリ | 65,672 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 16:11:07 |
| 合計ジャッジ時間 | 1,326 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:58:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d %d %d", &a, &b, &score);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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));
}
norioc