結果

問題 No.3252 Constrained Moving
ユーザー Anh Nguyễn Ngọc Tuấn
提出日時 2025-09-05 21:29:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 206,580 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-05 21:30:00
合計ジャッジ時間 4,984 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:17: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:20:17: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>

using namespace std;

const int N = 5 + 1e5;
const int inf = 7 + 1e9;

int main() {
#define TASKNAME ""
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int n, s, t, k;
    cin >> n >> s >> t >> k;
    vector <int> a(n + 1, 0);
    vector <II> b;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        b.push_back({a[i], i});
    }
    sort(b.begin(), b.end(), greater <> ());
    vector <int> ans(n + 1, inf);
    ans[s] = 1;
    queue <int> q;
    q.push(s);
    ans[s] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        int val = k - a[u];
        while (!b.empty() && b.back().st <= val) {
            int v = b.back().nd;
            b.pop_back();
            q.push(v);
            ans[v] = ans[u] + 1;
        }
    }
    cout << (ans[t] < inf ? ans[t] : -1);
    return 0;
}
0