結果
問題 | No.370 道路の掃除 |
ユーザー | dgd1724 |
提出日時 | 2016-10-24 18:25:52 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,220 bytes |
コンパイル時間 | 1,580 ms |
コンパイル使用メモリ | 164,192 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-05-03 05:26:39 |
合計ジャッジ時間 | 5,254 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,624 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | TLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
ソースコード
#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; }