結果
| 問題 | No.270 next_permutation (1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-15 22:17:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 878 bytes |
| コンパイル時間 | 816 ms |
| コンパイル使用メモリ | 73,296 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-26 01:54:26 |
| 合計ジャッジ時間 | 16,764 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 5 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
typedef long long ll;
using namespace std;
int main() {
int n, k; cin >> n >> k;
vector<int> a(n); repeat (i,n) cin >> a[i];
vector<int> b(n); repeat (i,n) cin >> b[i];
ll ans = 0;
int l = n; // TLE
ll base = 0; repeat (i,l) base += abs(a[i] - b[i]);
while (k --) {
ans += base;
repeat_from (i,l,n) ans += abs(a[i] - b[i]);
bool is_not_overflow = next_permutation(a.begin() + l, a.end());
if (not is_not_overflow) {
prev_permutation(a.begin() + l, a.end());
next_permutation(a.begin(), a.end());
base = 0; repeat (i,l) base += abs(a[i] - b[i]);
}
}
cout << ans << endl;
return 0;
}