답안 #755928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755928 2023-06-10T17:50:05 Z vjudge1 Pinball (JOI14_pinball) C++17
29 / 100
1000 ms 15312 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9 + 7;
ll mod(ll x, ll m = MOD){return (x + m) % m;}

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

typedef vector<pair<int,int>> vpi;

#define pb push_back

#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()


const int nax = 2005;
const ll INF = 1e15;

int n, m;
int l[nax], r[nax], to[nax];
ll cost[nax];
int corl[nax], corr[nax];
indexed_set nidl, nidr;

void solve()
{
    cin >> m >> n;
    for(int i = m; i >= 1; i--)
    {
        cin >> l[i] >> r[i] >> to[i] >> cost[i];
        nidl.insert(l[i]);
        nidr.insert(r[i]);
        nidl.insert(to[i]);
        nidr.insert(to[i]);
    }
    int szl = nidl.size();
    int szr = nidr.size();
    ll dp[2][szl + 1][szr + 1];
    for(int i = 1; i <= m; i++)
    {
        l[i] = nidl.order_of_key(l[i]);
        r[i] = nidr.order_of_key(r[i]);
    }
    int cnt = 0;
    for(auto e: nidl)
    {
        corl[cnt++] = e;
    }
    cnt = 0;
    for(auto e: nidr)
        corr[cnt++] = e;
    if(corl[0] > 1 || corr[szr - 1] < n)
    {
        cout << -1;
        return ;
    }
    ll ans = INF;
    for(int i = m + 1; i >= 0; i--)
    {
        int b = (i & 1);
        for(int j = 0;j < szl; j++)
        {
            for(int k = 0; k < szr; k++)
            {
                if(i == m + 1)
                {
                    if(j == 0 && k == szr - 1)
                        dp[b][j][k] = 0ll;
                    else
                        dp[b][j][k] = INF;
                }
                else
                {
                    dp[b][j][k] = dp[1 - b][j][k];
                    if(i != 0 && to[i] >= corl[j] && to[i] <= corr[k])
                    {
                        dp[b][j][k] = min(dp[1 - b][j][k],
                                          dp[1 - b][min(j, l[i])][max(k, r[i])] + cost[i]);
                    }
                }
                if(i == 0 && corl[j] == corr[k])
                    ans = min(ans, dp[b][j][k]);
            }
        }
    }
    if(ans > (ll)(1e14))
        cout << -1;
    else
        cout << ans;
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int tt = 1; //cin >> tt;
    while(tt--)
        solve();

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 11 ms 712 KB Output is correct
11 Correct 15 ms 916 KB Output is correct
12 Correct 58 ms 2880 KB Output is correct
13 Correct 47 ms 2772 KB Output is correct
14 Correct 51 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 11 ms 712 KB Output is correct
11 Correct 15 ms 916 KB Output is correct
12 Correct 58 ms 2880 KB Output is correct
13 Correct 47 ms 2772 KB Output is correct
14 Correct 51 ms 2772 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 3668 KB Output is correct
17 Execution timed out 1076 ms 15312 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 11 ms 712 KB Output is correct
11 Correct 15 ms 916 KB Output is correct
12 Correct 58 ms 2880 KB Output is correct
13 Correct 47 ms 2772 KB Output is correct
14 Correct 51 ms 2772 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 3668 KB Output is correct
17 Execution timed out 1076 ms 15312 KB Time limit exceeded
18 Halted 0 ms 0 KB -