Submission #367447

# Submission time Handle Problem Language Result Execution time Memory
367447 2021-02-17T11:43:15 Z Sparky_09 Watching (JOI13_watching) C++17
0 / 100
5 ms 748 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

template <class T>
void rd(T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void wr(T x) {
	if (x < 0) putchar('-'), wr(-x);
	else if (x < 10) putchar(x + '0');
	else wr(x / 10), putchar(x % 10 + '0');
}

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}
const ll maxn = 2020;
ll p, q, n, dp[maxn][maxn], a[maxn];

bool solve(ll len){
  ll l = 1, r = 1;
  rep(i, 1, n+1){
      while(a[l] < a[i]-len+1) l++;
      while(a[r] < a[i]-2*len+1) r++;
      rep(j,0,p+1){
         dp[i][j] = 1e12;
         if(j) dp[i][j] = dp[l-1][j-1];
         dp[i][j] = min(dp[r-1][j]+1,dp[i][j]);
      }
  }
  return (dp[n][p] <= q ? true : false);
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
    rd(n);rd(p);rd(q);
    rep(i, 1, n+1) cin>>a[i];
    sort(a+1, a+n+1);
    ll l = 1, h = 1e9+30;
    while(l<=h){
        ll mid = (l+h)/2;
        if(solve(mid)) h=mid-1;
        else l=mid+1;
    }
    cout << l;
}

Compilation message

watching.cpp: In function 'void usaco(std::string)':
watching.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 748 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -