提出 #23252700


ソースコード 拡げる

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

struct Edge {
    int to;
    long long C, D;
};
typedef vector<vector<Edge>> Graph;

void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B, std::vector<long long> C,
           std::vector<long long> D) {
    Graph G(N);
    for (int i = 0; i < M; i++) {
        G[A[i] - 1].emplace_back(Edge{B[i] - 1, C[i], D[i]});
    }

    std::vector<long long> dist(N, numeric_limits<long long>::max());
    priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                   greater<pair<long long, int>>>
        queue;
    queue.push({0, 0});
    while (!queue.empty()) {
        auto p = queue.top();
        queue.pop();
        if (dist[p.second] <= p.first) continue;
        dist[p.second] = p.first;

        for (const auto e : G[p.second]) {
            double low = p.first;
            double high = numeric_limits<long long>::max() / 100;
            for (int i = 0; i < 500; i++) {
                double c1 = (low * 2 + high) / 3;
                double c2 = (low + high * 2) / 3;

                double y1 = c1 + e.C + (long long)(e.D / (c1 + 1));
                double y2 = c2 + e.C + (long long)(e.D / (c2 + 1));
                if (y1 > y2)
                    low = c1;
                else
                    high = c2;
            }
            // printf("low = %lf d = %lf high = %lf d = %lf\n", low,
            //        low + e.C + e.D / (low + 1), high,
            //        high + e.C + e.D / (high + 1));
            long long t = std::max(p.first, (long long)low);
            long long d = t + e.C + e.D / (t + 1);
            t++;
            d = min(d, t + e.C + e.D / (t + 1));
            queue.push({d, e.to});
        }
    }
    if (dist[N - 1] != numeric_limits<long long>::max()) {
        printf("%lld\n", dist[N - 1]);
    } else {
        printf("-1\n");
    }
}

// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
    long long N;
    std::scanf("%lld", &N);
    long long M;
    std::scanf("%lld", &M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    std::vector<long long> D(M);
    for (int i = 0; i < M; i++) {
        std::scanf("%lld", &A[i]);
        std::scanf("%lld", &B[i]);
        std::scanf("%lld", &C[i]);
        std::scanf("%lld", &D[i]);
    }
    solve(N, M, std::move(A), std::move(B), std::move(C), std::move(D));
    return 0;
}

提出情報

提出日時
問題 E - Rush Hour 2
ユーザ a_kawashiro
言語 C++ (GCC 9.2.1)
得点 0
コード長 2910 Byte
結果 WA
実行時間 1060 ms
メモリ 12756 KiB

コンパイルエラー

./Main.cpp: In function ‘void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)’:
./Main.cpp:33:44: warning: narrowing conversion of ‘(B.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i)) - 1)’ from ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’} to ‘int’ [-Wnarrowing]
   33 |         G[A[i] - 1].emplace_back(Edge{B[i] - 1, C[i], D[i]});
./Main.cpp: In function ‘int main()’:
./Main.cpp:83:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   83 |     std::scanf("%lld", &N);
      |     ~~~~~~~~~~^~~~~~~~~~~~
./Main.cpp:85:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   85 |     std::scanf("%lld", &M);
      |     ~~~~~~~~~~^~~~~~~~~~~~
./Main.cpp:91:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   91 |         std::scanf("%lld", &A[i]);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~
./Main.cpp:92:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   92 |         std::scanf("%lld", &B[i]);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~
./Main.cpp:93:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   93 |         std::scanf("%lld", &C[i]);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~
./Main.cpp:94:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   94 |         std::scanf("%lld", &D[i]);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 500
結果
AC × 4
AC × 18
WA × 18
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hack_01.txt, hack_02.txt, hack_03.txt, hand_01.txt, hand_02.txt, hand_03.txt, max_01.txt, random_01.txt, random_02.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, special_01.txt, special_02.txt, special_03.txt, special_04.txt, special_05.txt, special_06.txt, tester_hack_01.txt
ケース名 結果 実行時間 メモリ
hack_01.txt AC 1021 ms 12152 KiB
hack_02.txt WA 88 ms 12056 KiB
hack_03.txt AC 12 ms 3680 KiB
hand_01.txt WA 2 ms 3644 KiB
hand_02.txt WA 2 ms 3736 KiB
hand_03.txt AC 2 ms 3660 KiB
max_01.txt AC 1060 ms 12756 KiB
random_01.txt WA 55 ms 11888 KiB
random_02.txt AC 45 ms 10808 KiB
random_11.txt WA 1037 ms 12568 KiB
random_12.txt WA 884 ms 11464 KiB
random_13.txt AC 560 ms 8012 KiB
random_14.txt WA 763 ms 10092 KiB
random_15.txt AC 931 ms 12020 KiB
random_16.txt WA 1036 ms 12484 KiB
random_17.txt AC 1007 ms 12188 KiB
random_18.txt WA 744 ms 9756 KiB
random_21.txt WA 1057 ms 12516 KiB
random_22.txt WA 1056 ms 12756 KiB
random_23.txt AC 1056 ms 12656 KiB
random_24.txt AC 1056 ms 12660 KiB
random_31.txt AC 1037 ms 12228 KiB
random_32.txt WA 1037 ms 12236 KiB
random_33.txt WA 1037 ms 12288 KiB
random_34.txt AC 1036 ms 12128 KiB
sample_01.txt AC 2 ms 3588 KiB
sample_02.txt AC 2 ms 3712 KiB
sample_03.txt AC 2 ms 3608 KiB
sample_04.txt AC 2 ms 3724 KiB
special_01.txt AC 316 ms 5824 KiB
special_02.txt AC 315 ms 5928 KiB
special_03.txt WA 316 ms 5772 KiB
special_04.txt WA 318 ms 5824 KiB
special_05.txt WA 313 ms 5736 KiB
special_06.txt WA 315 ms 5660 KiB
tester_hack_01.txt WA 1027 ms 11276 KiB