제출 #917994

#제출 시각아이디문제언어결과실행 시간메모리
917994vjudge1Stove (JOI18_stove)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; //----------------------- // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define pb push_back #define pf push_front #define mp make_pair #define mem(f,x) memset(f, x, sizeof(f)) #define __lcm(a, b) (1ll * a * b) / __gcd(a, b) #define bit(mask, i) ((mask >> i) & 1) #define pii pair<int, int> #define pll pair<ll, ll> #define el '\n' #define F first #define S second #define io(x) freopen(x".inp","r",stdin),freopen(x".out","w",stdout) //----------------------- const ll INF = 1e18; const int MOD = 1e9 + 7; const int MULTI = 0; const int dx[4] = {0, 0, 1, -1}; //R L D U const int dy[4] = {1, -1, 0, 0}; //-----AUTHOR trvhung VNG High School for Gifted Student----- const int maxn = 1e5 + 5; int n, k, a[maxn]; int check(int x) { int remain = k, i = 0, ret = 0; while (remain > 0) { remain--; int cur = 1; i++; while (i < n && cur + a[i + 1] - a[i] <= x) { cur += a[i + 1] - a[i]; i++; } ret += cur; if (i == n) return ret; } return -1; } void solve() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; int l = 1, r = 1e9, ans = 0; while (l <= r) { int mid = l + r >> 1; if (check(mid) != -1) { ans = check(mid); r = mid - 1; } else l = mid + 1; } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (!MULTI) solve(); else { int test; cin >> test; while (test--) solve(); } return 0; }

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

stove.cpp: In function 'void solve()':
stove.cpp:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |   int mid = l + r >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...