답안 #359103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
359103 2021-01-26T10:57:55 Z shahriarkhan 구경하기 (JOI13_watching) C++14
100 / 100
99 ms 8684 KB
#include<bits/stdc++.h>
using namespace std ;

const int mx = 2005 ;

int a[mx] , dp[mx][mx] , n , p , q ;

set<pair<int,int> > s ;

int check(int w)
{
    for(int i = 0 ; i <= p ; ++i)
    {
        for(int j = 0 ; j <= q ; ++j)
        {
            dp[i][j] = 0 ;
        }
    }
    int comp[n+1][2] ;
    for(int i = 1 ; i <= n ; ++i)
    {
        comp[i][0] = (*(--s.lower_bound({a[i]+w,0}))).second ;
        comp[i][1] = (*(--s.lower_bound({a[i]+w+w,0}))).second ;
    }
    for(int i = 0 ; i <= p ; ++i)
    {
        for(int j = 0 ; j <= q ; ++j)
        {
            if(i)
            {
                dp[i][j] = max(dp[i][j],comp[dp[i-1][j] + 1][0]) ;
            }
            if(j)
            {
                dp[i][j] = max(dp[i][j],comp[dp[i][j-1] + 1][1]) ;
            }
            if(dp[i][j]==n) return 1 ;
        }
    }
    return 0 ;
}

int main()
{
    scanf("%d%d%d",&n,&p,&q) ;
    for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ;
    if((p+q)>=n)
    {
        puts("1") ;
        return 0 ;
    }
    sort(a+1,a+n+1) ;
    for(int i = 1 ; i <= n ; ++i) s.insert({a[i],i}) ;
    int low = 0 , high = a[n] ;
    while(low<high)
    {
        int mid = (low+high)/2 ;
        if(check(mid)) high = mid ;
        else low = mid + 1 ;
    }
    printf("%d\n",low) ;
    return 0 ;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%d%d%d",&n,&p,&q) ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
watching.cpp:46:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ;
      |                                   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 17 ms 1260 KB Output is correct
9 Correct 20 ms 3820 KB Output is correct
10 Correct 34 ms 8684 KB Output is correct
11 Correct 16 ms 1132 KB Output is correct
12 Correct 99 ms 8300 KB Output is correct
13 Correct 7 ms 636 KB Output is correct
14 Correct 8 ms 492 KB Output is correct
15 Correct 9 ms 492 KB Output is correct