제출 #494581

#제출 시각아이디문제언어결과실행 시간메모리
494581aris12345678Stove (JOI18_stove)C++14
0 / 100
0 ms204 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 100005; int a[mxN]; bool check(ll md, int n, int k) { int cnt = 0, start = 0; for(int i = 0; i < n; i++) { if(a[i]-a[start] > md) { start = i; cnt++; } } if(start != n) cnt++; return cnt <= k; } int main() { int n, k; scanf("%d %d", &n, &k); for(int i = 0; i < n; i++) scanf("%d", &a[i]); ll st = 0, en = LLONG_MAX, md, diff; while(st <= en) { md = (st+en)/2; if(check(md, n, k)) diff = md, en = md-1; else st = md+1; } // cout << diff << "\n"; int start = 0; ll ans = 0; for(int i = 0; i < n; i++) { if(a[i]-a[start] > diff) { ans += 1LL*(a[i-1]-a[start]+1); start = i; } } if(start != n) ans += 1LL*(a[n-1]-a[start]+1); printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'int main()':
stove.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
stove.cpp:39:9: warning: 'diff' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |         if(a[i]-a[start] > diff) {
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...