結果

問題 No.90 品物の並び替え
ユーザー alpha_virginisalpha_virginis
提出日時 2015-09-14 01:31:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,674 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 145,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 11:48:32
合計ジャッジ時間 1,844 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

const unsigned long mod = 1000000007;
const double EPS = 0.00000001;
const int INF = (1 << 29);

typedef std::pair<int, int> P;

template<typename T>
void print_array(T *A_, s32 size) {
  printf("%d\n", size);
  if( size != 0 ) {
    for(int i = 0; i < size - 1; ++i) {
      printf("%d ", A_[i]);
    }
    printf("%d\n", A_[size - 1]);
  }
}

template<typename T>
inline std::istream& operator >> (std::istream& is, std::complex<T>& C) {
  T R, I;
  std::cin >> R >> I;
  C = std::complex<T>(R, I);
  return is;
}

int A[10];

int n, m;
int score[16][16];

int calc(void) {
  int res = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      res += score[A[i]][A[j]];
    }
  }
  return res;
}

void rand_swap(void) {
  std::swap(A[rand() % n], A[rand() % n]);
}

int main() {

  std::cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int a, b, s;
    std::cin >> a >> b >> s;
    score[a][b] = s;
  }

  for(int i = 0; i < n; ++i) {
    A[i] = i;
  }
  
  int res = -1;
  int times = 300;
  int temp;

  srand(time(NULL));

  for(int i = 0; i < times; ++i) {
    int res2 = -1;
    for(int j = 0; j < 8; ++j) {
      rand_swap();
    }
    for(int p = 0; p < n; ++p) {
      for(int q = p + 1; q < n; ++q) {
        std::swap(A[p], A[q]);
        temp = calc();
        std::swap(A[p], A[q]);
        if( res2 < temp ) {
          res2 = temp;
        }
      }
    }
    res = std::max(res, res2);
  }

  std::cout << res << std::endl;
  
  return 0;
}
0