Submission #378113

# Submission time Handle Problem Language Result Execution time Memory
378113 2021-03-16T03:29:03 Z jlallas384 Stove (JOI18_stove) C++17
100 / 100
79 ms 8672 KB
#include <bits/stdc++.h>
using namespace std;

struct dsu{
    vector<int> sz,par;
    dsu(int n): sz(n,1),par(n){
        iota(par.begin(),par.end(),0);
    }
    int find(int a){
        return a == par[a] ? a : par[a] = find(par[a]);
    }
    void unite(int a,int b){
        a = find(a), b = find(b);
        if(sz[a] < sz[b]) swap(a,b);
        sz[a] += sz[b];
        par[b] = a;
    }
};

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto &x: a){
        cin >> x;
    }
    dsu d(n);
    vector<pair<int,int>> edges;
    for(int i = 0; i < n - 1; i++){
        edges.emplace_back(a[i+1] - a[i], i);
    }
    sort(edges.begin(), edges.end());
    vector<vector<int>> comp(n);
    for(int i = 0; i < n - k; i++){
        d.unite(edges[i].second,edges[i].second+1);
    }
    for(int i = 0; i < n; i++){
        comp[d.find(i)].push_back(a[i]);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(comp[i].size() == 1) ans++;
        else if(comp[i].size() > 1) ans += comp[i].back() - comp[i][0] + 1;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 61 ms 6112 KB Output is correct
17 Correct 61 ms 6112 KB Output is correct
18 Correct 76 ms 6112 KB Output is correct
19 Correct 64 ms 6240 KB Output is correct
20 Correct 64 ms 7264 KB Output is correct
21 Correct 63 ms 8544 KB Output is correct
22 Correct 65 ms 8672 KB Output is correct
23 Correct 79 ms 8672 KB Output is correct
24 Correct 62 ms 8672 KB Output is correct