結果

問題 No.270 next_permutation (1)
ユーザー y_mazuny_mazun
提出日時 2015-08-21 23:23:11
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 860 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 48,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 15:28:52
合計ジャッジ時間 1,466 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdlib>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

struct t{
  int i;
  t(){}
};

int p[100000];
int b[100000];
t idx[100000];
ll ans;

bool operator < (t i, t j){
  return p[i.i] < p[j.i];
}

void swap(t i, t j){
  ans -= std::abs(b[i.i] - p[i.i]);
  ans -= std::abs(b[j.i] - p[j.i]);
  swap(i.i, j.i);
  ans += std::abs(b[i.i] - p[j.i]);
  ans += std::abs(b[j.i] - p[i.i]);
}

int main(){
  const int n = getInt();
  const int k = getInt();

  REP(i,n) p[i] = getInt();
  REP(i,n) b[i] = getInt();
  REP(i,n) idx[i].i = i;
  REP(i,n) ans += (ll)k * std::abs(p[i] - b[i]);

  REP(i,k-1){
    next_permutation(idx, idx + n);
  }

  printf("%lld\n", ans);
  return 0;
}
0