Submission #627017

# Submission time Handle Problem Language Result Execution time Memory
627017 2022-08-12T04:48:06 Z tamthegod Road Closures (APIO21_roads) C++14
12 / 100
99 ms 34160 KB
#include<bits/stdc++.h>
//#include "roads.h"
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
ll f[maxN][2];
vector<pair<int, int>> adj[maxN];
vector<ll> minimum_closure_costs(int n, vector<int> U, vector<int> V, vector<int> W)
{
    vector<ll> res;
    bool ok = true;
    ll sum = 0;
    for(int i=0; i<n-1; i++)
    {
        int u = U[i] + 1, v = V[i] + 1, w = W[i];
        //cout << u << " " << v << '\n';
        sum += w;
        if(U[i] != i || V[i] != i + 1) ok = false;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    if(adj[1].size() == n - 1)
    {
        vector<int> vc;
        for(int i=0; i<n-1; i++) vc.pb(W[i]);
        sort(vc.begin(), vc.end());
        for(int i=0; i<n; i++)
        {
            res.pb(sum);
            sum -= vc.back();
            vc.pop_back();
        }
        return res;
    }
    if(ok)
    {
       res.pb(sum);
       f[1][1] = W[0];
       for(int i=2; i<n; i++)
       {
           f[i][0] = f[i - 1][1];
           f[i][1] = min(f[i - 1][0], f[i - 1][1]) + W[i - 1];
       }
       res.pb(min(f[n - 1][0], f[n - 1][1]));
       while(res.size() != n) res.pb(0);
       return res;
    }
}
/*void Solve()
{
    int n;
    cin >> n;
    vector<int> u(n), v(n), w(n);
    for(int i=0; i<n-1; i++) cin >> u[i];
    for(int i=0; i<n-1; i++) cin >> v[i];
    for(int i=0; i<n-1; i++) cin >> w[i];
    vector<ll> res = minimum_closure_costs(n, u, v, w);
    for(int v : res) cout << v << " ";
}
int32_t main()
{
    freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Solve();
}*/

Compilation message

roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:30:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |     if(adj[1].size() == n - 1)
      |        ~~~~~~~~~~~~~~^~~~~~~~
roads.cpp:53:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |        while(res.size() != n) res.pb(0);
      |              ~~~~~~~~~~~^~~~
roads.cpp:56:1: warning: control reaches end of non-void function [-Wreturn-type]
   56 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 17 ms 23892 KB Output is correct
3 Correct 14 ms 24020 KB Output is correct
4 Correct 16 ms 24016 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 16 ms 23800 KB Output is correct
7 Correct 16 ms 23764 KB Output is correct
8 Correct 17 ms 23952 KB Output is correct
9 Correct 14 ms 23912 KB Output is correct
10 Correct 18 ms 23796 KB Output is correct
11 Correct 14 ms 23800 KB Output is correct
12 Correct 62 ms 29088 KB Output is correct
13 Correct 65 ms 32552 KB Output is correct
14 Correct 70 ms 31852 KB Output is correct
15 Correct 87 ms 32472 KB Output is correct
16 Correct 77 ms 32560 KB Output is correct
17 Correct 99 ms 32628 KB Output is correct
18 Correct 14 ms 23716 KB Output is correct
19 Correct 58 ms 31868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23796 KB Output is correct
2 Correct 55 ms 31180 KB Output is correct
3 Correct 61 ms 33452 KB Output is correct
4 Correct 81 ms 34036 KB Output is correct
5 Correct 97 ms 34160 KB Output is correct
6 Correct 17 ms 23976 KB Output is correct
7 Correct 14 ms 23984 KB Output is correct
8 Correct 18 ms 23940 KB Output is correct
9 Correct 18 ms 23792 KB Output is correct
10 Correct 15 ms 23776 KB Output is correct
11 Correct 17 ms 23716 KB Output is correct
12 Correct 52 ms 29392 KB Output is correct
13 Correct 65 ms 33272 KB Output is correct
14 Correct 20 ms 23708 KB Output is correct
15 Correct 58 ms 32500 KB Output is correct
16 Correct 66 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23764 KB Output is correct
2 Incorrect 17 ms 23764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23764 KB Output is correct
2 Incorrect 17 ms 23764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 32648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 32648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 17 ms 23892 KB Output is correct
3 Correct 14 ms 24020 KB Output is correct
4 Correct 16 ms 24016 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 16 ms 23800 KB Output is correct
7 Correct 16 ms 23764 KB Output is correct
8 Correct 17 ms 23952 KB Output is correct
9 Correct 14 ms 23912 KB Output is correct
10 Correct 18 ms 23796 KB Output is correct
11 Correct 14 ms 23800 KB Output is correct
12 Correct 62 ms 29088 KB Output is correct
13 Correct 65 ms 32552 KB Output is correct
14 Correct 70 ms 31852 KB Output is correct
15 Correct 87 ms 32472 KB Output is correct
16 Correct 77 ms 32560 KB Output is correct
17 Correct 99 ms 32628 KB Output is correct
18 Correct 14 ms 23716 KB Output is correct
19 Correct 58 ms 31868 KB Output is correct
20 Correct 14 ms 23796 KB Output is correct
21 Correct 55 ms 31180 KB Output is correct
22 Correct 61 ms 33452 KB Output is correct
23 Correct 81 ms 34036 KB Output is correct
24 Correct 97 ms 34160 KB Output is correct
25 Correct 17 ms 23976 KB Output is correct
26 Correct 14 ms 23984 KB Output is correct
27 Correct 18 ms 23940 KB Output is correct
28 Correct 18 ms 23792 KB Output is correct
29 Correct 15 ms 23776 KB Output is correct
30 Correct 17 ms 23716 KB Output is correct
31 Correct 52 ms 29392 KB Output is correct
32 Correct 65 ms 33272 KB Output is correct
33 Correct 20 ms 23708 KB Output is correct
34 Correct 58 ms 32500 KB Output is correct
35 Correct 66 ms 33344 KB Output is correct
36 Correct 16 ms 23764 KB Output is correct
37 Incorrect 17 ms 23764 KB Output isn't correct
38 Halted 0 ms 0 KB -