답안 #1001708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001708 2024-06-19T07:07:30 Z vjudge1 구경하기 (JOI13_watching) C++17
100 / 100
621 ms 30032 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
/// author: LilPluton auuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
#define OPT         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb          push_back
#define arr         array
#define vll         vector<int>
#define int         long long
#define segment_tree int l=n*2,r=l+1,mid=(b+e)/2
#define fi          first
#define se          second
#define rep(i,j,k)  for(int i = j; i <= k; ++i)
#define all(a)      a.begin(),a.end()
#define pii         pair<int,int>
#define endll       '\n'
using namespace std;
const int N = 2e3 + 3;
const int INF = 1e18;
int a[N];

int dp[N][N];

int n, p, q;
int check(int w)
{
    for(int i = 0; i <= p; ++i)
    {
        int idx1 = 0, idx2 = 0;
        for(int j = 1; j <= n; ++j)
        {
            dp[i][j] = INF;
            while(idx1 < n && a[idx1 + 1] <= a[j] - w)
            {
                idx1++;
            }
            while(idx2 < n && a[idx2 + 1] <= a[j] - w * 2)
            {
                idx2++;
            }
            dp[i][j] = dp[i][idx2] + 1;
            if(i > 0)
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][idx1]);
            }
        }

    }
    return dp[p][n];
}

signed main()
{
    
    cin >> n >> p >> q;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    if(p + q >= n)
    {
        cout << 1;
        return 0;
    }
    sort(a + 1, a + n + 1);
    int lb = 1, rb = 1e9, ans, mid;
    while(lb <= rb)
    {
        mid = (lb + rb) >> 1;
        if(check(mid) > q)
        {
            lb = mid + 1;
            ans = mid;
        }
        else
        {
            rb = mid - 1;
        }
    }
    cout << lb;
    
} 

Compilation message

watching.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization("unroll-loops")
      | 
watching.cpp: In function 'int main()':
watching.cpp:65:27: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
   65 |     int lb = 1, rb = 1e9, ans, mid;
      |                           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 704 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 6 ms 712 KB Output is correct
8 Correct 42 ms 2392 KB Output is correct
9 Correct 244 ms 12120 KB Output is correct
10 Correct 621 ms 30032 KB Output is correct
11 Correct 26 ms 1624 KB Output is correct
12 Correct 293 ms 15704 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 10 ms 1128 KB Output is correct