Submission #2049815


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define MAX 123456

struct BIT{
  int t[MAX];
  void init(){
    for(int i=0;i<MAX;i++){
      t[i]=0;
    }
  }
  int maxm(int i=123400){
    int res=0;
    i+=5;
    while(i>0){
      res=max(res,t[i]);
      i-=(i&-i);
    }
    return res;
  }
  
  void update(int i,int x){
    i+=5;
    while(i<MAX){
      t[i]=max(t[i],x);
      i+=(i&-i);
    }
  }
};

BIT A[101];
int N,K;
int v[MAX];
vector<int> X;

void solve(){
  for(int i=0;i<N;i++){
    int tmp=0;
    int cost=0;

    int a[101]={};
    for(int j=0;j<=K;j++){
      if(j>0){
        tmp = max( tmp, A[j-1].maxm() );
        //        A[j].update( v[i] , tmp+1);
        a[j]=max(a[j],tmp+1);
      }
      cost = max(cost, A[j].maxm( v[i]-1 ) );
      //      A[j].update( v[i], cost+1);
      a[j]=max(a[j],cost+1);
    }
    for(int j=0;j<=K;j++){
      A[j].update( v[i], a[j] );
    }
    
  }

  int ans=1;
  for(int i=0;i<=K;i++){
    ans=max(ans, A[i].maxm() );
  }
  cout<<ans<<endl;
}

int main(){
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>v[i];
    X.push_back(v[i]);
  }
  sort(X.begin(),X.end());
  X.erase( unique( X.begin(), X.end() ) , X.end() );
  
  for(int i=0;i<N;i++){
    v[i]=lower_bound( X.begin(),X.end(),v[i]) - X.begin();
    v[i]++;
    //    cout<<v[i]<<' ';
  }
  //  cout<<endl;
  solve();
  return 0;
}

Submission Info

Submission Time
Task B - だんだん強く
User dohatsutsu
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1432 Byte
Status AC
Exec Time 684 ms
Memory 49656 KB

Judge Result

Set Name All
Score / Max Score 800 / 800
Status
AC × 68
Set Name Test Cases
All 00_sample00, 00_sample01, 00_sample02, 01_minimal00, 01_minimal01, 01_minimal02, 01_minimal03, 20_small_random00, 20_small_random01, 20_small_random02, 20_small_random03, 20_small_random04, 20_small_random05, 20_small_random06, 20_small_random07, 20_small_random08, 20_small_random09, 20_small_random10, 20_small_random11, 20_small_random12, 20_small_random13, 20_small_random14, 20_small_random15, 20_small_random16, 20_small_random17, 20_small_random18, 20_small_random19, 21_small_increasing00, 21_small_increasing01, 21_small_increasing02, 21_small_increasing03, 21_small_increasing04, 21_small_increasing05, 22_small_decreasing00, 22_small_decreasing01, 22_small_decreasing02, 22_small_decreasing03, 22_small_decreasing04, 22_small_decreasing05, 23_small_mountain00, 23_small_mountain01, 23_small_mountain02, 23_small_mountain03, 23_small_mountain04, 23_small_mountain05, 24_small_valley00, 24_small_valley01, 24_small_valley02, 24_small_valley03, 24_small_valley04, 24_small_valley05, 30_large_random00, 30_large_random01, 30_large_random02, 30_large_random03, 30_large_random04, 31_large_increasing00, 31_large_increasing01, 31_large_increasing02, 32_large_decreasing00, 32_large_decreasing01, 32_large_decreasing02, 33_large_mountain00, 33_large_mountain01, 33_large_mountain02, 34_large_valley00, 34_large_valley01, 34_large_valley02
Case Name Status Exec Time Memory
00_sample00 AC 1 ms 384 KB
00_sample01 AC 1 ms 256 KB
00_sample02 AC 1 ms 384 KB
01_minimal00 AC 1 ms 256 KB
01_minimal01 AC 16 ms 47488 KB
01_minimal02 AC 1 ms 256 KB
01_minimal03 AC 15 ms 47488 KB
20_small_random00 AC 8 ms 22912 KB
20_small_random01 AC 16 ms 47488 KB
20_small_random02 AC 7 ms 18816 KB
20_small_random03 AC 10 ms 29056 KB
20_small_random04 AC 7 ms 20864 KB
20_small_random05 AC 7 ms 20864 KB
20_small_random06 AC 5 ms 12672 KB
20_small_random07 AC 4 ms 8576 KB
20_small_random08 AC 11 ms 31104 KB
20_small_random09 AC 12 ms 37248 KB
20_small_random10 AC 6 ms 14720 KB
20_small_random11 AC 12 ms 33152 KB
20_small_random12 AC 14 ms 41344 KB
20_small_random13 AC 15 ms 43392 KB
20_small_random14 AC 11 ms 31104 KB
20_small_random15 AC 6 ms 16768 KB
20_small_random16 AC 7 ms 20864 KB
20_small_random17 AC 9 ms 27008 KB
20_small_random18 AC 4 ms 10624 KB
20_small_random19 AC 5 ms 12672 KB
21_small_increasing00 AC 1 ms 256 KB
21_small_increasing01 AC 4 ms 10624 KB
21_small_increasing02 AC 7 ms 18816 KB
21_small_increasing03 AC 10 ms 29056 KB
21_small_increasing04 AC 13 ms 39296 KB
21_small_increasing05 AC 16 ms 47488 KB
22_small_decreasing00 AC 1 ms 256 KB
22_small_decreasing01 AC 4 ms 10624 KB
22_small_decreasing02 AC 7 ms 18816 KB
22_small_decreasing03 AC 10 ms 29056 KB
22_small_decreasing04 AC 13 ms 39296 KB
22_small_decreasing05 AC 16 ms 47488 KB
23_small_mountain00 AC 1 ms 256 KB
23_small_mountain01 AC 4 ms 10624 KB
23_small_mountain02 AC 7 ms 18816 KB
23_small_mountain03 AC 10 ms 29056 KB
23_small_mountain04 AC 13 ms 39296 KB
23_small_mountain05 AC 16 ms 47488 KB
24_small_valley00 AC 1 ms 256 KB
24_small_valley01 AC 4 ms 10624 KB
24_small_valley02 AC 7 ms 18816 KB
24_small_valley03 AC 10 ms 29056 KB
24_small_valley04 AC 13 ms 39296 KB
24_small_valley05 AC 15 ms 47488 KB
30_large_random00 AC 490 ms 27000 KB
30_large_random01 AC 259 ms 16888 KB
30_large_random02 AC 77 ms 1528 KB
30_large_random03 AC 100 ms 4600 KB
30_large_random04 AC 298 ms 20984 KB
31_large_increasing00 AC 67 ms 1528 KB
31_large_increasing01 AC 330 ms 27000 KB
31_large_increasing02 AC 664 ms 49656 KB
32_large_decreasing00 AC 64 ms 1528 KB
32_large_decreasing01 AC 337 ms 27128 KB
32_large_decreasing02 AC 680 ms 49656 KB
33_large_mountain00 AC 71 ms 1400 KB
33_large_mountain01 AC 346 ms 26488 KB
33_large_mountain02 AC 681 ms 49016 KB
34_large_valley00 AC 71 ms 1400 KB
34_large_valley01 AC 345 ms 26488 KB
34_large_valley02 AC 684 ms 49016 KB