제출 #1119935

#제출 시각아이디문제언어결과실행 시간메모리
1119935tintingyn21구경하기 (JOI13_watching)C++17
100 / 100
159 ms16452 KiB
// author : daohuyenchi #ifdef LOCAL #include "D:\C++ Submit\debug.h" #else #define debug(...) #endif #include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define db double #define i32 int32_t #define i64 int64_t #define ll long long // #define fi first #define se second // #define int long long // consider carefully // #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define pil pair<int, ll> #define PAIR make_pair // TIME IS LIMITED ... #define rep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define repd(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define repv(v, H) for(auto &v: H) // REFLECT ON THE PAST ... #define RESET(c, x) memset(c, x, sizeof(c)) #define MASK(i) (1LL << (i)) #define BIT(mask, i) (((mask) >> (i)) & 1LL) #define ONBIT(mask, i) ((mask) | (1LL << (i))) #define OFFBIT(mask, i) ((mask) &~ (1LL << (i))) #define COUNTBIT __builtin_popcountll // 30 / 1 / 2024 ? love is zero... start from zero #define vi vector <int> #define vll vector <ll> #define lwb lower_bound #define upb upper_bound #define all(v) (v).begin(), (v).end() #define special(H) (H).resize(distance(H.begin(), unique(all(H)))) // #define sp ' ' #define nl '\n' #define EL {cerr << '\n';} #define yes "YES" #define no "NO" #define Log2(n) (63 - __builtin_clzll(n)) #define left __left__ #define right __right__ #define lps(id) ((id) << 1) #define rps(id) ((id) << 1 | 1) //____________________________________________________________________ template <class X, class Y> bool maximize(X &a, const Y &b) { if(a < b) return a = b, true; return false; } template <class X, class Y> bool minimize(X &a, const Y &b) { if(a > b) return a = b, true; return false; } template <class... T> void print(T&&... n) { using exp = int[]; exp{0, (cerr << n << sp, 0)...}; cerr << nl; } template <class T, class... C> void assign(int n, T v, C&&... a) { using e = int[]; e{(a.assign(n, v), 0)...}; } template <class... C> void resize(int n, C&&... a) { using e = int[]; e{(a.resize(n), 0)...}; } template <class T> using vector2d = vector<vector<T>>; template <class T> using vector3d = vector<vector2d<T>>; template <class T> int ssize(T &a) { return (int) a.size(); } //____________________________________________________________________ mt19937 rng(chrono::steady_clock().now().time_since_epoch().count()); const int MOD = 1000000007; // const int MOD[2] = {1000000009, 998244353}; template<class X> void modmize(X &x, int cur_Mod = MOD) { if(x >= cur_Mod) x -= cur_Mod; if(x < 0) x += cur_Mod; } const long long oo = 1e18 + 7; const long long LINF = 1e18 + 7; const int IINF = 2e9; const int nmax = 2e3 + 10; const int MAX = 2e5; const int base = 311; const db eps = 1e-6; const int block = 500; static const double PI = acos(-1.0); //____________________________________________________________________ int n, P, Q; int a[nmax]; int dp[nmax][nmax]; bool bin_check(int val) { vector2d <int> nxt(n + 2, vector <int>(2, 0)); rep (i, 1, n) { repd (j, n, i) { if (a[j] - a[i] + 1 <= val && nxt[i][0] == 0) { nxt[i][0] = j; } if (a[j] - a[i] + 1 <= val * 2 && nxt[i][1] == 0) { nxt[i][1] = j; } } } rep (i, 0, n) rep (i2, 0, n) dp[i][i2] = 0; dp[1][0] = nxt[1][0]; dp[0][1] = nxt[1][1]; rep (i, 0, min(n, P)) { rep (j, 0, min(n, Q)) { if (dp[i][j] != 0 && dp[i][j] < n) { int cur = dp[i][j]; maximize(dp[i + 1][j], max(cur, nxt[cur + 1][0])); maximize(dp[i][j + 1], max(cur, nxt[cur + 1][1])); } } } rep (i, 0, min(n, P)) rep (j, 0, min(n, Q)) { if (dp[i][j] == n) return 1; } return 0; } void tintingyn() { cin >> n >> P >> Q; rep (i, 1, n) { cin >> a[i]; } sort(a + 1, a + n + 1); int l = 1, r = 1e9; int res = -1; while (l <= r) { int mid = (l + r) / 2; if (bin_check(mid)) { res = mid; r = mid - 1; } else l = mid + 1; } cout << res << nl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //________________________________________________________________ #define TASK "3" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } //________________________________________________________________ // CODE FROM HERE ...! int num_test = 1; // cin >> num_test; while(num_test--) { tintingyn(); } cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" << nl; return 0; }

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

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