답안 #921995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921995 2024-02-04T16:09:32 Z IUA_Hasin Stove (JOI18_stove) C++17
100 / 100
46 ms 5552 KB
#include <bits/stdc++.h>
 
#define endl                                "\n"
#define finp                                for(int i=0; i<n; i++)
#define fknp                                for(int k=0; k<n; k++)
#define yeap                                cout<<"YES"<<endl
#define nope                                cout<<"NO"<<endl
#define inpintn                             int n; cin>>n
#define inpintarrn                          int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define inpllarrn                           long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define ll                                  long long
#define pb                                  push_back
#define answer                              cout<<ans<<endl
#define INF                                 (ll)(1e18)
 
 
using namespace std;
 
int main ()
{ 
    ll n, k;
    cin>>n>>k;
    if(n==1){
        ll arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        cout<<1<<endl;
    } else if(n==2){
        ll arr[n];
        for(int i=0; i<n; i++){
            cin>>arr[i];
        }
        if(k>=2){
            cout<<2<<endl;
        } else {
            ll aaa = arr[1] - arr[0] + 1;
            cout<<aaa<<endl;
        }
    } else {
        ll arr[n];
    ll brr[n-1];
    vector<ll> v;
    vector<ll> v1;
    for(int i=0; i<n; i++){
        if(i==0){
            cin>>arr[i];
        } else {
            cin>>arr[i];
            brr[i-1] = arr[i] - arr[i-1]; 
        }
    }

    ll strt = arr[0];

    for(int i=0; i<n-1; i++){
        if(i==n-2){
            if(brr[i]==1){
                ll aa = arr[i+1]+1;
                v.push_back(aa);
                v1.push_back(strt);
            } else {
                ll aa = arr[i]+1;
                v.push_back(aa);
                v1.push_back(strt);
                strt = arr[n-1];
                aa = strt+1;
                v.push_back(aa);
                v1.push_back(strt);
            }
        } else if(brr[i]!=1){
            ll aa = arr[i]+1;
            v.push_back(aa);
            v1.push_back(strt);
            strt = arr[i+1];
        }
    }

    ll siz = v.size();
    ll crr[siz-1];
    ll x = siz - 1;
    for(int i=0; i<siz-1; i++){
        crr[i] = v1[i+1] - v[i];
    }
    sort(crr, crr+x);
    ll startt = 0;
    ll ans = n;
    if(n==1){
        cout<<1<<endl;
    } else if(n==2){
        if(k>=2){
            cout<<2<<endl;
        } else {
            ll aaa = arr[1] - arr[0] + 1;
            cout<<aaa<<endl;
        }
    } else if(siz<=k){
        cout<<ans<<endl;
    } else {
        while(siz>k){
            ans+=crr[startt];
            startt++;
            siz--;
        }
        cout<<ans<<endl;
    }   



    // for(int i=0; i<v.size(); i++){
    //     cout << v[i] << " ";
    // }

    // cout<<endl;

    // for(int j=0; j<v1.size(); j++){
    //     cout << v1[j] << " ";
    // }
    // cout<<endl;

    // for(int i=0; i<siz-1; i++){
    //     cout << crr[i] << " ";
    // }

    // cout<<endl;

    // cout<<ans<<endl;

    // cout << v1[2] << endl;
    }
    
    return 0;
 
 
}
# 결과 실행 시간 메모리 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 0 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 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 600 KB Output is correct
15 Correct 1 ms 412 KB Output is correct
# 결과 실행 시간 메모리 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 0 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 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 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 600 KB Output is correct
15 Correct 1 ms 412 KB Output is correct
16 Correct 37 ms 5312 KB Output is correct
17 Correct 46 ms 5312 KB Output is correct
18 Correct 36 ms 5308 KB Output is correct
19 Correct 36 ms 5308 KB Output is correct
20 Correct 37 ms 5552 KB Output is correct
21 Correct 39 ms 5276 KB Output is correct
22 Correct 39 ms 5344 KB Output is correct
23 Correct 36 ms 5356 KB Output is correct
24 Correct 37 ms 5284 KB Output is correct