제출 #831301

#제출 시각아이디문제언어결과실행 시간메모리
831301manhtuan22007Stove (JOI18_stove)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> //#define int long long #define ll long long using namespace std; const int maxn = 1e5 + 10; int n , k , a[maxn]; int cal(int x){ int j = 1 , cnt = 1; for(int i = 1 ; i <= n ; i ++){ if(a[i] - a[j] + 1 <= x) continue; j = i; ++cnt; } return cnt; } int32_t main() { cin.tie(0)->sync_with_stdio(0); if(fopen(".inp" , "r")){ freopen(".inp" , "r" , stdin); freopen(".out" , "w" , stdout); } cin >> n >> k; for(int i = 1 ; i <= n ; i ++) cin >> a[i]; int l = 0 , r = 1e9 + 1 , ans = 1e9; // cout << cal(3) << "\n"; while(l <= r){ int mid = (l + r) / 2; if(cal(mid) <= k) ans = mid , r = mid - 1; else l = mid + 1; } // cout << ans << " "; ll res = 0 , j = 0; for(int i = 1 ; i <= n ; i = j + 1){ while(a[j + 1] - a[i] + 1 <= ans && j < n){ ++j; } res += a[j] - a[i] + 1; // cout << i << " " << j << '\n'; } cout << res; }

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

stove.cpp: In function 'int32_t main()':
stove.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen(".inp" , "r" , stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen(".out" , "w" , stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...