답안 #1108873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108873 2024-11-05T13:49:09 Z hainam2k9 Stove (JOI18_stove) C++17
0 / 100
1 ms 592 KB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,k,a[MAXN];
int bs(int l, int r){
    int rs=r;
    while(l<=r){
        int mid=(l+r)>>1,cnt=0,pre=a[1],sum=0;
        for(int i = 1; i<n; ++i)
            if(a[i+1]+1-pre>mid) ++cnt, sum+=a[i]+1-pre, pre=a[i+1];
        sum+=a[n]+1-pre;
        if(cnt+1<=k) rs=sum, r=mid-1;
        else l=mid+1;
    }
    return rs;
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> k;
    for(int i = 1; i<=n; ++i)
        cin >> a[i];
    cout << bs(1,2e9);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:37:45: note: in expansion of macro 'fo'
   37 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
stove.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:37:45: note: in expansion of macro 'fo'
   37 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -