結果

問題 No.90 品物の並び替え
ユーザー hiromi-mihiromi-mi
提出日時 2018-12-31 20:16:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,014 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 73,116 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:06:52
合計ジャッジ時間 1,322 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <numeric>
//#include <tuple>
#include <cstdio>

using namespace std;

typedef long long ll;


#define rep(i,b) for(ll i=0;i<(b);++i)
#define rep1(i,b) for(ll i=1;i<=(b);++i)
#define vec vector
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int N, M;

int item1[80];
int item2[80];
int score[80];

int main() {
   cin >> N >> M;
   rep(i, M) {
      cin >> item1[i] >> item2[i] >> score[i];
   }
   vector<int> v(N);
   iota(v.begin(), v.end(), 0);
   int maxval = 0;
   int dp[11]; // 数字からindex
   do {
      int points = 0;
      rep(i, N) {
         dp[v[i]] = i;
      }
      rep(i, M) {
         if (dp[item1[i]] < dp[item2[i]]) points += score[i];
      }
      maxval = max({maxval, points});
      // for (auto x: v) cout << x << " "; cout << "\n";
   } while ( next_permutation(v.begin(), v.end()));
   cout << maxval << endl;
}
0