답안 #412423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412423 2021-05-26T21:00:16 Z kimbj0709 구경하기 (JOI13_watching) C++14
100 / 100
103 ms 7884 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int small,big;
vector<int> vect1;

bool can(int k){
  int dp[small+2][big+2];
  int pos1[vect1.size()+2],pos2[vect1.size()+2];
  for(int i=0;i<vect1.size();i++){
    pos1[i] = i,pos2[i] = i;
    while(pos1[i]+1<vect1.size()&&vect1[pos1[i]+1]-vect1[i]+1<=k){
      pos1[i]++;
    }
    while(pos2[i]+1<vect1.size()&&vect1[pos2[i]+1]-vect1[i]+1<=k*2){
      pos2[i]++;
    }
  }
  memset(dp,0,sizeof(dp));
  for(int i=0;i<=small;i++){
    for(int j=0;j<=big;j++){
      if(dp[i][j]==vect1.size()){
        return 1;
      }
      dp[i+1][j] = max(dp[i+1][j],pos1[dp[i][j]]+1);
      dp[i][j+1] = max(dp[i][j+1],pos2[dp[i][j]]+1);
    }
  }
  return 0;
}

int32_t main() {
  int no_of_input,input;
  cin >> no_of_input >> small >> big;
  for(int i=0;i<no_of_input;i++){
    cin >> input;
    vect1.push_back(input);
  }
  sort(vect1.begin(),vect1.end());
  if(small+big>=vect1.size()){
    cout << 1;
    return 0;
  }
  int low = 0,high = INT_MAX;
  while(low+1!=high){
    //cout << low << " " << high << endl;
    int mid = (low+high)/2;
    if(can(mid)==1){
      high = mid;
    }
    else{
      low = mid;
    }
  }
  cout <<high;
}

Compilation message

watching.cpp: In function 'bool can(long long int)':
watching.cpp:10:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |   for(int i=0;i<vect1.size();i++){
      |               ~^~~~~~~~~~~~~
watching.cpp:12:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while(pos1[i]+1<vect1.size()&&vect1[pos1[i]+1]-vect1[i]+1<=k){
      |           ~~~~~~~~~^~~~~~~~~~~~~
watching.cpp:15:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     while(pos2[i]+1<vect1.size()&&vect1[pos2[i]+1]-vect1[i]+1<=k*2){
      |           ~~~~~~~~~^~~~~~~~~~~~~
watching.cpp:22:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |       if(dp[i][j]==vect1.size()){
      |          ~~~~~~~~^~~~~~~~~~~~~~
watching.cpp: In function 'int32_t main()':
watching.cpp:40:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if(small+big>=vect1.size()){
      |      ~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 31 ms 332 KB Output is correct
8 Correct 26 ms 1100 KB Output is correct
9 Correct 27 ms 1072 KB Output is correct
10 Correct 32 ms 1612 KB Output is correct
11 Correct 23 ms 1704 KB Output is correct
12 Correct 103 ms 7884 KB Output is correct
13 Correct 37 ms 332 KB Output is correct
14 Correct 28 ms 332 KB Output is correct
15 Correct 23 ms 332 KB Output is correct