ソースコード 拡げる

Copy
```#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_N (1<<17)

struct SegTree {
int seg[MAX_N*2-1] = {};

void update(int i, int x) {
i += MAX_N-1;
seg[i] = max(seg[i], x);
while (i > 0) {
i = (i-1) / 2;
seg[i] = max(seg[i*2+1], seg[i*2+2]);
}
}
int query(int a, int b, int k=0, int l=0, int r=MAX_N) {
if (r <= a || b <= l) return 0;
if (a <= l && r <= b) return seg[k];
return max(
query(a, b, k*2+1, l, (l+r)/2),
query(a, b, k*2+2, (l+r)/2, r)
);
}
};

int N, K;
int A[100000];
vector<int> xs;
SegTree seg[101];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> K;
vector<int> xs;
xs.pb(-1);
rep(i, N) cin >> A[i], xs.pb(A[i]);
sort(all(xs)); uniq(xs);
rep(i, N) A[i] = index(xs, A[i]);
seg[0].update(0, 0);
rep(i, N) {
int a = A[i];
for (int k=K; k>=0; k--) {
seg[k].update(a, seg[k].query(0, a)+1);
if (k+1 <= K) seg[k+1].update(a, seg[k].seg[0]+1);
}
}
int m = 0;
rep(i, K+1) m = max(m, seg[i].seg[0]);
cout << m << "\n";
return 0;
}
```

#### 提出情報

提出日時 2018-02-03 16:47:58+0900 B - だんだん強く funcsr C++14 (GCC 5.4.1) 0 1692 Byte WA 1895 ms 103928 KB

#### ジャッジ結果

セット名 All

 AC × 43 WA × 25
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample00 AC 2 ms 2432 KB
00_sample01 AC 1 ms 256 KB
00_sample02 AC 2 ms 2432 KB
01_minimal00 AC 1 ms 256 KB
01_minimal01 WA 21 ms 100736 KB
01_minimal02 AC 1 ms 256 KB
01_minimal03 WA 21 ms 100736 KB
20_small_random00 AC 11 ms 47488 KB
20_small_random01 WA 24 ms 100736 KB
20_small_random02 AC 10 ms 41344 KB
20_small_random03 WA 15 ms 63872 KB
20_small_random04 AC 11 ms 45440 KB
20_small_random05 AC 10 ms 43392 KB
20_small_random06 AC 6 ms 24960 KB
20_small_random07 AC 5 ms 18816 KB
20_small_random08 WA 15 ms 65920 KB
20_small_random09 WA 19 ms 80256 KB
20_small_random10 AC 8 ms 33152 KB
20_small_random11 WA 16 ms 70016 KB
20_small_random12 WA 20 ms 86400 KB
20_small_random13 WA 21 ms 92544 KB
20_small_random14 WA 15 ms 63872 KB
20_small_random15 AC 9 ms 37248 KB
20_small_random16 AC 10 ms 41344 KB
20_small_random17 WA 13 ms 57728 KB
20_small_random18 AC 6 ms 22912 KB
20_small_random19 AC 7 ms 27008 KB
21_small_increasing00 AC 1 ms 256 KB
21_small_increasing01 WA 6 ms 20864 KB
21_small_increasing02 WA 10 ms 41344 KB
21_small_increasing03 WA 14 ms 61824 KB
21_small_increasing04 WA 19 ms 82304 KB
21_small_increasing05 WA 23 ms 100736 KB
22_small_decreasing00 AC 1 ms 256 KB
22_small_decreasing01 AC 6 ms 20864 KB
22_small_decreasing02 AC 10 ms 41344 KB
22_small_decreasing03 AC 14 ms 61824 KB
22_small_decreasing04 AC 19 ms 82304 KB
22_small_decreasing05 WA 23 ms 100736 KB
23_small_mountain00 AC 1 ms 256 KB
23_small_mountain01 AC 6 ms 20864 KB
23_small_mountain02 AC 10 ms 41344 KB
23_small_mountain03 WA 14 ms 61824 KB
23_small_mountain04 WA 19 ms 82304 KB
23_small_mountain05 WA 23 ms 100736 KB
24_small_valley00 AC 1 ms 256 KB
24_small_valley01 AC 6 ms 20864 KB
24_small_valley02 AC 10 ms 41344 KB
24_small_valley03 WA 14 ms 61824 KB
24_small_valley04 WA 19 ms 82304 KB
24_small_valley05 WA 23 ms 100736 KB
30_large_random00 AC 1437 ms 54008 KB
30_large_random01 AC 742 ms 33528 KB
30_large_random02 AC 48 ms 1912 KB
30_large_random03 AC 131 ms 6904 KB
30_large_random04 AC 923 ms 39672 KB
31_large_increasing00 AC 30 ms 1912 KB
31_large_increasing01 WA 905 ms 54008 KB
31_large_increasing02 WA 1827 ms 103928 KB
32_large_decreasing00 AC 30 ms 1912 KB
32_large_decreasing01 AC 939 ms 54008 KB
32_large_decreasing02 AC 1895 ms 103928 KB
33_large_mountain00 AC 36 ms 1528 KB
33_large_mountain01 AC 929 ms 53240 KB
33_large_mountain02 AC 1872 ms 102776 KB
34_large_valley00 AC 36 ms 1528 KB
34_large_valley01 AC 928 ms 53240 KB
34_large_valley02 AC 1882 ms 102776 KB