結果

問題 No.270 next_permutation (1)
ユーザー keikei
提出日時 2016-09-08 16:09:14
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 617 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 65,292 KB
実行使用メモリ 12,576 KB
最終ジャッジ日時 2024-04-27 17:58:18
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long Ans = 0,Ans_1 = 0, Ans_2 = 0; // Ans_1 : /    Ans_2 : %
	long long N, K; cin >> N >> K;
	vector<long long> p(N),temp(N), B(N);
	for (long long i = 0; i < N; i++) {
		cin >> p[i];
	}
	temp = p;
	for (long long i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (long long i = 0; i < K; i++) {
		for (long long j = 0; j < N; j++) {
			Ans += (p[j] >= B[j]) ? p[j] - B[j] : B[j] - p[j];
		}
		if (!next_permutation(p.begin(), p.end())) {
			p = temp;
		}
	}
	cout << Ans << endl;
}
0