Submission #1277352

#TimeUsernameProblemLanguageResultExecution timeMemory
1277352adscoding구경하기 (JOI13_watching)C++20
100 / 100
247 ms15628 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define BIT(mask, x) ((mask >> (x)) & 1) #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int maxn = 2e3 + 3; int n, nbig, nsmall, a[maxn]; bool check(const int &w) { vector<vector<int>> dp(n + 1, vector<int>(nbig + 1, 1e9)); dp[0][0] = 0; int jbig = 1, jsmall = 1; FOR(i, 1, n) { while (jbig < i && a[i] - a[jbig] + 1 > 2 * w) ++jbig; while (jsmall < i && a[i] - a[jsmall] + 1 > w) ++jsmall; FOR(big, 0, nbig) { if (big) dp[i][big] = min(dp[i][big], dp[jbig - 1][big - 1]); if (dp[jsmall - 1][big] < nsmall) dp[i][big] = min(dp[i][big], dp[jsmall - 1][big] + 1); } } FOR(i, 0, nbig) if (dp[n][i] <= nsmall) return true; return false; } void solve() { cin >> n >> nsmall >> nbig; nsmall = min(nsmall, n); nbig = min(nbig, n); while (nbig > 0 && nbig + nsmall > n) --nbig; FOR(i, 1, n) cin >> a[i]; sort(a + 1, a + n + 1); int l = 1, r = 1e9; while (l <= r) { int mid = l + r >> 1; if (check(mid)) r = mid - 1; else l = mid + 1; } cout << l; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TASK "TEST" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); return 0; } /* NOTES: */

Compilation message (stderr)

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