Submission #868461

# Submission time Handle Problem Language Result Execution time Memory
868461 2023-10-31T13:45:38 Z phongcd Džumbus (COCI19_dzumbus) C++14
0 / 110
1000 ms 18248 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long  double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define ild pair <ld, ld>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 1e3 + 2;
const int M = 40;
const ll MOD = 1e9 + 7;
const ll INF = 3e18;
const ll base = 311;
const ll base2 = 1e4 + 7;
const int BLOCK_SIZE = 400;

int n, m;
ll d[N], f[N][N][2], dp[N];
vector <int> g[N];

void minimize(ll &a, ll b) {
    if (a > b) a = b;
}

void dfs(int u, int p) {
    f[u][0][0] = 0;
    for (int v: g[u]) if (v != p) {
        dfs(v, u);
        for (int j = 1000; j > 1; j --) {
            for (int k = 0; k <= j; k ++) {
                minimize(f[u][j][0], f[u][j - k][0] + min(f[v][k][0], f[v][k][1]));
                minimize(f[u][j][1], f[u][j - k - 1][0] + f[v][k][1] + d[u]);
                minimize(f[u][j][1], f[u][j - k - 1][0] + f[v][k - 1][0] + d[u] + d[v]);
                minimize(f[u][j][1], f[u][j - k][1] + f[v][k][1]);
                minimize(f[u][j][1], f[u][j - k][1] + f[v][k][0]);
                minimize(f[u][j][1], f[u][j - k][1] + f[v][k - 1][0] + d[v]);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) cin >> d[i];
    for (int i = 0; i < m; i ++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    memset(f, 0x3f, sizeof f);
    for (int i = 1; i <= n; i ++)
        if (f[i][0][0] > 1000) dfs(i, 0);

    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    for (int i = 1; i <= 1000; i ++)
        for (int j = 1; j <= n; j ++) 
            minimize(dp[i], min(f[j][i][0], f[j][i][1]));

    int q; cin >> q;
    while (q --) {
        int s; cin >> s;
        int l = 0, r = n;
        while (l < r) {
            int mid = l + (r - l + 1) / 2;
            if (dp[mid] <= s) l = mid;
            else r = mid - 1;
        }
        cout << l << '\n';
    }
}
/*
     /\_/\ zzZ
    (= -_-)
    / >u  >u
*/
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 16216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 16216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 156 ms 18248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 16216 KB Time limit exceeded
2 Halted 0 ms 0 KB -