제출 #1156160

#제출 시각아이디문제언어결과실행 시간메모리
1156160nguynWatching (JOI13_watching)C++20
100 / 100
662 ms16152 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back #define pii pair<int,int> const int N = 2e3 + 5; const int inf = 2e9; int n, a[N], p, q; int f[N][N]; signed main(){ ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; if (fopen("INP.INP" ,"r")) { freopen("INP.INP" ,"r" , stdin) ; freopen("OUT.OUT" , "w" , stdout) ; } cin >> n >> p >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); q = min(q, n); int l = 1; int r = 1e9; int res = inf; while(l <= r) { int mid = (l + r) / 2; for (int i = 0; i <= n; i++) { for (int j = 0; j <= q; j++) { f[i][j] = -inf; } } f[0][q] = p; for (int i = 0; i < n; i++) { for (int j = 0; j <= q; j++) { if (f[i][j] == -inf) { continue; } if (j) { int nxt = upper_bound(a + 1, a + 1 + n, a[i + 1] + 2 * mid - 1) - a - 1; f[nxt][j - 1] = max(f[nxt][j - 1], f[i][j]); } int nxt = upper_bound(a + 1, a + 1 + n, a[i + 1] + mid - 1) - a - 1; f[nxt][j] = max(f[nxt][j], f[i][j] - 1); } } bool ok = 0; for (int i = 0; i <= q; i++) { if (f[n][i] >= 0) ok = 1; } if (ok) { res = mid; r = mid - 1; } else { l = mid + 1; } } cout << res; }

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

watching.cpp: In function 'int main()':
watching.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("OUT.OUT" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...