結果

問題 No.90 品物の並び替え
ユーザー naimonon77naimonon77
提出日時 2015-11-25 16:52:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 1,231 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 64,264 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 18:31:04
合計ジャッジ時間 1,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
int kaizyou(int n)
{
  int rep = n;
  while(--n) rep *= n;
  return rep;
}
int e_cnt(int e[],int n)
{
  int i;
  int cnt = 0;
  for(i=0; ;i++) {
    if(e[i]) cnt++;
    if(cnt == n+1) break;
  }
  return i;
}
/* break -> i++しない?*/
int main(void)
{
  int i,j,k;
  int e[9];
  int f[9];
  int n,m;
  int a,b,c;
  int cnt;
  int kaizyou_now;
  int score[100][100] = {0};
  int rep = 0;
  scanf("%d %d",&n,&m);
  rep(i,m) {
    scanf("%d %d %d",&a,&b,&c);
    score[a][b] = c;
  }
  kaizyou_now = kaizyou(n);
  for(i = 0; i < kaizyou_now; i++) {
    for(j=0; j<n; j++) {
      e[j] = 1;
    }
    int num = n;
    int num2 = i;
    while(num) {
      f[num-1] = e_cnt(e,num2%num);
      e[e_cnt(e,num2%num)] = 0;
      num2 /= num;
      num--;
    }
    int tmp = 0;
    for(j=0;j<n;j++) {
      for(k=j+1;k<n;k++) {
        tmp += score[f[j]][f[k]];
      }
    }
    if(rep < tmp) rep = tmp;
  }
  printf("%d\n",rep);
  return 0;
}
0