Submission #1084638

# Submission time Handle Problem Language Result Execution time Memory
1084638 2024-09-06T15:21:00 Z ShaShi Džumbus (COCI19_dzumbus) C++17
110 / 110
254 ms 74064 KB
#include <bits/stdc++.h>
 
#define int long long
 
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
 
#define F first 
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define endl "\n"
 
 
 
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
 
const int MAXN = (int)1e3 + 7;
const int MOD = 998244353;
const ll INF = (ll)1e18 + 7;
const int LG = 20;


int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, flag2;
int arr[MAXN]; bool seen[MAXN];
vector<int> adj[MAXN];
vector<int> dp[2][MAXN];


void DFSsz(int v) { seen[v] = 1; for (int u:adj[v]) if (!seen[u]) DFSsz(u); }


void DFS(int v, int p=0) {
    dp[0][v] = {0, INF}; dp[1][v] = {INF, INF};

    for (int u:adj[v]) {
        if (u == p) continue;

        DFS(u, v);

        vector<int> pd[2];
        pd[0].resize(dp[1][v].size()+dp[1][u].size()+7); fill(all(pd[0]), INF);
        pd[1].resize(dp[1][v].size()+dp[1][u].size()+7); fill(all(pd[1]), INF);

        for (int x=0; x<dp[1][v].size(); x++) {
            for (int y=0; y<dp[1][u].size(); y++) {
                pd[1][x+y] = min(pd[1][x+y], dp[1][v][x]+dp[0][u][y]);
                pd[1][x+y] = min(pd[1][x+y], dp[1][v][x]+dp[1][u][y]);
                pd[1][x+y+1] = min(pd[1][x+y+1], dp[0][v][x]+dp[1][u][y]+arr[v]);
                pd[1][x+y+1] = min(pd[1][x+y+1], dp[1][v][x]+dp[0][u][y]+arr[u]);
                pd[1][x+y+2] = min(pd[1][x+y+2], dp[0][v][x]+dp[0][u][y]+arr[v]+arr[u]);
                
                pd[0][x+y] = min(pd[0][x+y], dp[0][v][x]+dp[0][u][y]);
                pd[0][x+y] = min(pd[0][x+y], dp[0][v][x]+dp[1][u][y]);
            }
        }

        dp[0][v] = pd[0]; dp[1][v] = pd[1];
    }
}


int32_t main() {
    #ifdef LOCAL
    freopen("inp.in", "r", stdin);
    freopen("res.out", "w", stdout);
    #else
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    cin >> n >> m;

    for (int i=1; i<=n; i++) cin >> arr[i];
    arr[n+1] = INF;

    for (int i=1; i<=m; i++) {
        cin >> u >> v;

        adj[u].pb(v); adj[v].pb(u);
    }

    for (int i=1; i<=n; i++) {
        if (seen[i]) continue;

        DFSsz(i);

        adj[n+1].pb(i); adj[i].pb(n+1);
    }

    DFS(n+1);

    cin >> q;

    while (q--) {
        cin >> k;

        for (int i=n; i>=0; i--) {
            if (min(dp[0][n+1][i], dp[1][n+1][i]) <= k) {
                // cout << "@ " << dp[0][n+1][i] << " " << dp[1][n+1][i] << endl;
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

Compilation message

dzumbus.cpp: In function 'void DFS(long long int, long long int)':
dzumbus.cpp:52:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int x=0; x<dp[1][v].size(); x++) {
      |                       ~^~~~~~~~~~~~~~~~
dzumbus.cpp:53:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for (int y=0; y<dp[1][u].size(); y++) {
      |                           ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 116 ms 47184 KB Output is correct
2 Correct 113 ms 67152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 47184 KB Output is correct
2 Correct 113 ms 67152 KB Output is correct
3 Correct 150 ms 74064 KB Output is correct
4 Correct 167 ms 55076 KB Output is correct
5 Correct 252 ms 47772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2900 KB Output is correct
2 Correct 23 ms 2396 KB Output is correct
3 Correct 37 ms 2708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 47184 KB Output is correct
2 Correct 113 ms 67152 KB Output is correct
3 Correct 150 ms 74064 KB Output is correct
4 Correct 167 ms 55076 KB Output is correct
5 Correct 252 ms 47772 KB Output is correct
6 Correct 21 ms 2900 KB Output is correct
7 Correct 23 ms 2396 KB Output is correct
8 Correct 37 ms 2708 KB Output is correct
9 Correct 205 ms 5388 KB Output is correct
10 Correct 187 ms 4644 KB Output is correct
11 Correct 254 ms 3808 KB Output is correct