# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
965580 |
2024-04-19T00:24:54 Z |
vjudge1 |
Stove (JOI18_stove) |
C++17 |
|
23 ms |
6716 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define dbg puts("dbg");
#define outp(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define test int t; cin >> t; while(t--){solve();}
#define MOD 998244353
int fpb(int a,int b){if(b == 0){return a;}return fpb(b, a%b);}
int kpk(int a,int b){return (a*b)/fpb(a, b);}
int n, k, t[100003], totGroupNow, par[100003];
vector <pair <int, pii>> v;
int root(int x){
if(par[x] == x){
return x;
}
par[x] = root(par[x]);
return par[x];
}
void join(int x, int y){
par[root(x)] = root(y);
}
bool cek(int x, int y){
return (root(x) == root(y));
}
void solve(){
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> t[i];
}
for(int i=2; i<=n; i++){
v.pb({t[i]-t[i-1], {i-1, i}});
}
sort(all(v));
totGroupNow = n;
for(int i=1; i<=n; i++){
par[i] = i;
}
for(auto i : v){
if(totGroupNow == k) break;
join(i.second.first, i.second.second);
totGroupNow--;
}
int mini = t[1], maxi = t[1], res = 0;
for(int i=2; i<=n+1; i++){
if(cek(i-1, i)){
maxi = t[i];
} else {
res += maxi - mini + 1;
mini = t[i], maxi = t[i];
}
// cout << mini << " " << maxi << endl;
}
cout << res << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
516 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
516 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
20 ms |
5420 KB |
Output is correct |
17 |
Correct |
20 ms |
6352 KB |
Output is correct |
18 |
Correct |
20 ms |
5888 KB |
Output is correct |
19 |
Correct |
21 ms |
5328 KB |
Output is correct |
20 |
Correct |
23 ms |
5452 KB |
Output is correct |
21 |
Correct |
19 ms |
5404 KB |
Output is correct |
22 |
Correct |
19 ms |
5328 KB |
Output is correct |
23 |
Correct |
20 ms |
6604 KB |
Output is correct |
24 |
Correct |
19 ms |
6716 KB |
Output is correct |