제출 #1355182

#제출 시각아이디문제언어결과실행 시간메모리
1355182lizi14구경하기 (JOI13_watching)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define ss second
#define ina insert
#define pb push_back
int n,p,q;
const int N=2005
vector<int>x(N+1);
bool check(int w){
    int dp[n+1][p+1];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=p; j++){
            if(i==0){
                dp[i][j]=0;
            }
            else dp[i][j]=1e18;
        }
    }
    int l_pa=0;
    int l_did=0;
    //dp[0][0]=1;
    for(int i=1; i<=n; i++){
        while(l_pa+1<=n && x[i]-w>=x[l_pa+1])l_pa++;
        while(l_did+1<=n && x[i]-2*w>=x[l_did+1])l_did++;
        
        for(int j=0; j<=p; j++){
            if(j>=1)dp[i][j]=min(dp[l_pa][j-1],dp[i][j]);
            dp[i][j]=min(dp[i][j],dp[l_did][j]+1);
            
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    if(dp[n][p]<=q){
        return true;
    }
    return false;
}

signed main(){
    cin>>n>>p>>q;
    x.resize(n + 1);
    for(int i=1; i<=n; i++){
        cin>>x[i];
    }
    x[0]=-1;
    sort(x.begin(),x.end());
    int l=1,r=1e9;
    int ans=-1;
    while(l<=r){
        int mid=(l+r)/2;
        int h=check(mid);
        //cout<<h<<" "<<mid<<endl;
        if(h){
            r=mid-1;
            ans=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<ans<<endl;
}

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

watching.cpp:9:1: error: expected ',' or ';' before 'vector'
    9 | vector<int>x(N+1);
      | ^~~~~~
watching.cpp: In function 'bool check(int)':
watching.cpp:17:27: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   17 |             else dp[i][j]=1e18;
      |                           ^~~~
watching.cpp:24:28: error: 'x' was not declared in this scope
   24 |         while(l_pa+1<=n && x[i]-w>=x[l_pa+1])l_pa++;
      |                            ^
watching.cpp:25:29: error: 'x' was not declared in this scope
   25 |         while(l_did+1<=n && x[i]-2*w>=x[l_did+1])l_did++;
      |                             ^
watching.cpp: In function 'int main()':
watching.cpp:43:5: error: 'x' was not declared in this scope
   43 |     x.resize(n + 1);
      |     ^