結果
| 問題 |
No.370 道路の掃除
|
| コンテスト | |
| ユーザー |
dgd1724
|
| 提出日時 | 2016-10-24 18:25:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,220 bytes |
| コンパイル時間 | 1,721 ms |
| コンパイル使用メモリ | 164,852 KB |
| 実行使用メモリ | 19,912 KB |
| 最終ジャッジ日時 | 2024-11-24 02:46:43 |
| 合計ジャッジ時間 | 65,879 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 TLE * 21 |
ソースコード
#include <bits/stdc++.h>
//const static double de_PI = 3.14159265358979323846;
//const static int de_MOD = 1000000007;
const static int de_MAX = 999999999;
//const static int de_MIN = -999999999;
inline void Calc(const int &N, int &min, int &distance, const int &now, std::vector<bool> &flg, std::vector<std::vector<int>> &A) {
for (unsigned int i = 1; i < flg.size(); i++) {
if (!flg[i]) { continue; }
distance += A[now][i];
if (distance >= min) {
distance -= A[now][i];
continue;
}
flg[i] = false;
if (N > 1) { Calc(N - 1, min, distance, i, flg, A); }
else { if (distance < min) min = distance; }
flg[i] = true;
distance -= A[now][i];
}
}
int main(void) {
//std::ifstream in("123.txt"); std::cin.rdbuf(in.rdbuf());
int N = 0, M = 0;
std::cin >> N >> M;
std::vector<int> D(M + 1);
for (int i = 1; i < M + 1; i++) {
std::cin >> D[i];
}
std::vector<std::vector<int>> A(M + 1, std::vector<int>(M + 1, -1));
for (int i = 0; i < M + 1; i++) {
for (int j = i + 1; j < M + 1; j++) {
A[i][j] = A[j][i] = abs(D[j] - D[i]);
}
}
int min = de_MAX, distance = 0;
std::vector<bool> flg(M + 1, true);
Calc(N, min, distance, 0, flg, A);
std::cout << min << std::endl;
}
dgd1724