답안 #901517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901517 2024-01-09T13:53:57 Z VinhLuu Stove (JOI18_stove) C++17
100 / 100
16 ms 3772 KB
// happy

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#define int long long
//#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 2e5 + 5;
const int oo = 1e16;
const int mod = 1e9 + 7;
const int base = 29; // >= so pt pb max

int n, a[N], b[N], sum, k;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 1; i < n; i ++){
        b[i] = a[i + 1] - a[i] - 1;
        sum += (a[i + 1] - a[i] - 1);
    }
//    cout << sum << "\n";
    sort(b + 1, b + n, greater<int>());
    for(int i = 1; i <= min(n - 1, k - 1); i ++){
//        cout << b[i] << "\n";
        sum -= b[i];
    }

    cout << sum + n;

}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2452 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2524 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2452 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2524 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 14 ms 3772 KB Output is correct
17 Correct 14 ms 3672 KB Output is correct
18 Correct 14 ms 3676 KB Output is correct
19 Correct 16 ms 3768 KB Output is correct
20 Correct 16 ms 3672 KB Output is correct
21 Correct 14 ms 3676 KB Output is correct
22 Correct 14 ms 3656 KB Output is correct
23 Correct 14 ms 3676 KB Output is correct
24 Correct 14 ms 3548 KB Output is correct