結果

問題 No.2366 登校
ユーザー Rainer Evan RuslyRainer Evan Rusly
提出日時 2024-05-02 02:59:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,630 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 171,020 KB
実行使用メモリ 29,152 KB
最終ジャッジ日時 2024-05-02 02:59:45
合計ジャッジ時間 7,214 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
29,152 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
const ll MAXN = 2e4 + 5;
const ll LOG = 31;
#define vll vector <ll>
#define pll pair <ll, ll>
#define fi first
#define se second
#define endl '\n'

ll n, m, k, t;
pll a [MAXN], b [MAXN];
ll dp [MAXN][1000];

void solve(){
    cin >> n >> m >> k >> t;
    for(ll i = 1; i <= k; i++){
        cin >> a[i].fi >> a[i].se >> b[i].fi >> b[i].se;
    }
    ll tt = n+m-2;
    t = min(t, tt);
    a[0] = {1, 1};
    a[k+1] = {n, m};
    for(ll i = 0; i <= k+1; i++){
        for(ll j = 0; j <= 2*tt; j++){
            if(i == 0){
                if(j < tt) dp[i][j] = INF;
                continue;
            }
            dp[i][j] = INF;
            for(ll u = 0; u < i; u++){
                ll dis = abs(a[u].fi - a[i].fi) + abs(a[u].se - a[i].se);
                // cout << i << " " << u << " << " << dis << endl;
                if(dis <= j) dp[i][j] = min(dp[i][j], dp[u][j-dis]);
            }
        }
        for(ll j = 2*tt; j >= 0; j--){
            if(b[i].fi == 0) break;
            ll cnt = j+b[i].fi-1;
            dp[i][j] = min(dp[i][j], dp[i][min(2*tt, cnt)] + b[i].se);
        }
        // for(ll j = 0; j <= 2*tt; j++){
        //     cout << dp[i][j] << " ";
        // }cout << endl;
    }
    ll ans = dp[k+1][tt+t];
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // ll t; cin >> t;
    // while(t--){
        solve();
    // }
}
0