Submission #1097326

# Submission time Handle Problem Language Result Execution time Memory
1097326 2024-10-07T00:23:20 Z hickwhither Džumbus (COCI19_dzumbus) C++17
110 / 110
201 ms 80560 KB
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

#define int int64_t // fuck my self

const int INF = 1e18+7;
const int MAXN = 2222;

int n, m, q;
struct Edge
{
    int u, v;
    Edge(){}
    Edge(int _u, int _v): u(_u), v(_v) {}
    int other(const int x){return x^u^v;}
} edge[MAXN] ;

vector<int> e[MAXN];
int s[MAXN];

#define minimize(a,b) a=min(a,b)

int64_t f[MAXN];
int64_t dp[MAXN][MAXN][2];
int64_t lst[MAXN][2];
int sz[MAXN];


void dfs(int u=1, int p=-1){
    sz[u] = 1;
    dp[u][0][0] = 0;
    
    for(int &v: e[u]){
        
        if(v==p) continue;
        dfs(v, u);

        for(int i=0; i<=sz[u]; ++i)
            lst[i][0] = dp[u][i][0],
            lst[i][1] = dp[u][i][1];
        
        for(int U=0; U<=sz[u]; ++U){
        for(int V=0; V<=sz[v]&&U+V<=n; ++V){
                minimize(dp[u][U+V][0], lst[U][0] + dp[v][V][0]);
                minimize(dp[u][U+V][0], lst[U][0] + dp[v][V][1]);
                if(u==0)continue;
                minimize(dp[u][U+V][1], lst[U][1] + dp[v][V][0]);
                minimize(dp[u][U+V][1], lst[U][1] + dp[v][V][1]);


                minimize(dp[u][U+V+1][1], lst[U][0] + dp[v][V][1] + s[u]); // u off
                minimize(dp[u][U+V+1][1], lst[U][1] + dp[v][V][0] + s[v]); // v off

                minimize(dp[u][U+V+2][1], lst[U][0] + dp[v][V][0] + s[u] + s[v]); // both off
        }}

        sz[u]=min(sz[u]+sz[v],n);
    }
}

bool vis[MAXN];
void bfs_beo(int u){
    vis[u] = 1;
    for(int &v : e[u])if(!vis[v]) bfs_beo(v);
}


signed main()
{
    cin.tie(0) -> sync_with_stdio(0);

    cin >> n >> m;
    for(int i=1; i<=n; ++i) cin >> s[i];
    for(int u, v, i=0; i<m; ++i){
        cin >> u >> v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }

    for(int i=1; i<=n; ++i){
        if(!vis[i]){
            e[0].emplace_back(i);
            e[i].emplace_back(0);
            bfs_beo(i);
        }
    }

    memset(dp, 0x3f, sizeof(dp));
    dfs(0);

    // cout << "***\n";

    // for(int i=0; i<=n; ++i){
    //     cout << i << "**\n";
    //     for(int j=0; j<=n; ++j) cout << (dp[i][j][0]>=INF ? -1 : dp[i][j][0]) << ' '; cout << '\n';
    //     for(int j=0; j<=n; ++j) cout << (dp[i][j][1]>=INF ? -1 : dp[i][j][1]) << ' '; cout << '\n';
    //     cout << '\n';
    // }
    
    
    cin >> q;
    while(q--){
        int x;cin >> x;
        bool fl = 1;
        for(int i=n; i>=0; --i)
        if(dp[0][i][0]<=x || dp[0][i][1]<=x){
            cout << i << '\n';
            fl = 0;
            break;
        }
    }

    return 0;
}

Compilation message

dzumbus.cpp: In function 'int main()':
dzumbus.cpp:107:14: warning: variable 'fl' set but not used [-Wunused-but-set-variable]
  107 |         bool fl = 1;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 77952 KB Output is correct
2 Correct 51 ms 77724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 77952 KB Output is correct
2 Correct 51 ms 77724 KB Output is correct
3 Correct 94 ms 80056 KB Output is correct
4 Correct 109 ms 80560 KB Output is correct
5 Correct 201 ms 80212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 79696 KB Output is correct
2 Correct 62 ms 79456 KB Output is correct
3 Correct 69 ms 79980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 77952 KB Output is correct
2 Correct 51 ms 77724 KB Output is correct
3 Correct 94 ms 80056 KB Output is correct
4 Correct 109 ms 80560 KB Output is correct
5 Correct 201 ms 80212 KB Output is correct
6 Correct 60 ms 79696 KB Output is correct
7 Correct 62 ms 79456 KB Output is correct
8 Correct 69 ms 79980 KB Output is correct
9 Correct 84 ms 79700 KB Output is correct
10 Correct 93 ms 80464 KB Output is correct
11 Correct 196 ms 80212 KB Output is correct