Submission #1250747

#TimeUsernameProblemLanguageResultExecution timeMemory
1250747DangKhoizzzzMarathon Race 2 (JOI24_ho_t3)C++20
24 / 100
66 ms2240 KiB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair <int , int>
#define arr3 array <int , 3>

using namespace std;

const int INF = 1e17;
const int maxn = 5e5 + 7;

int n , L , q , x[maxn] , dp[(1 << 14)][14];

void solve()
{
    cin >> n >> L;
    for(int i = 1; i <= n; i++) cin >> x[i];
    sort(x+1,x+n+1);

    cin >> q;
    while(q--)
    {
        int l , r , t; cin >> l >> r >> t;

        for(int i = 0; i < (1 << n); i++)
        {
            for(int j = 0; j < n; j++) dp[i][j] = INF;
        }

        for(int mask = 1; mask < (1 << n); mask++)
        {
            int k = __builtin_popcount(mask);

            if(k == 1)
            {
                int j = 0;
                while(mask != (1 << j)) j++;
                dp[mask][j] = abs(l - x[j+1]) + 1;
                continue;
            }

            for(int i = 0; i < n; i++)
            {
                if((mask >> i)&1)
                {
                    for(int j = 0; j < n; j++)
                    {
                        if(i != j && ((mask >> j)&1))
                        {
                            dp[mask][i] = min(dp[mask][i] , dp[mask^(1 << i)][j] + k*abs(x[i+1] - x[j+1]) + 1);
                        }
                    }
                }
            }
        }
        int ans = INF;
        for(int i = 0; i < n; i++)
        {
            ans = min(ans , dp[(1 << n)-1][i] + abs(x[i+1] - r)*(n+1));
        }

        if(ans <= t) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...