結果

問題 No.370 道路の掃除
ユーザー hanorverhanorver
提出日時 2016-05-13 23:00:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,449 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 69,524 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-15 16:48:32
合計ジャッジ時間 4,288 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,832 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 12 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>

std::vector<int> dist;
int ddist[1001][1001];

bool isCollect(long long cost, int n, int now, std::vector<bool> visited){
    if(cost < 0) return false;
    if(n == 0) return true;
    for(size_t i = 0; i < visited.size(); i++){
        if(visited[i] == false){
            visited[i] = true;
            bool result = isCollect(cost - ddist[now][i], n - 1, i, visited);
            if(result == true) return true;
            visited[i] = false;
        }
    }
    return false;
}

int main(){
    int n, m;
    std::cin >> n >> m;

    dist.resize(m);
    for(int i = 0; i < m; i++){
        std::cin >> dist[i];
    }
    dist.push_back(0);

    std::sort(dist.begin(), dist.end());

    for(size_t i = 0; i < dist.size(); i++){
        for(size_t j = 0; j < dist.size(); j++){
            ddist[i][j] = std::abs(dist[i] - dist[j]);
        }
    }

    std::vector<bool> visited(dist.size(), false);
    int start = 0;
    for(size_t i = 0; i < dist.size(); i++){
        if(dist[i] == 0){
            start = i;
            visited[i] = true;
            break;
        }
    }

    long long high = 100000000, low = 0;

    while(high - low > 1){
        long long mid = (high + low) / 2;
        if(isCollect(mid, n, start, visited)){
            high = mid;
        }else{
            low = mid;
        }
    }

    std::cout << high << std::endl;
    return 0;
}
0