-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
59 lines (43 loc) · 1.31 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
const int64_t INF = 1e9+5;
void run_cases() {
int N, M;
cin >> N >> M;
vector<int64_t> tiles(M + 10);
for(int i=0;i<N;i++) {
int foo;
cin >> foo;
tiles[foo]++;
}
vector<vector<int64_t>> dp(3, vector<int64_t>(3, -INF));
vector<vector<int64_t>> next_dp(3, vector<int64_t>(3, 0));
dp[0][0] = 0;
for (int a = 1; a <= M; a++) {
for (int x = 0; x < 3; x++)
for (int y = 0; y < 3; y++)
next_dp[x][y] = -INF;
for (int x = 0; x < 3; x++)
for (int y = 0; y < 3; y++)
for (int z = 0; z < 3; z++)
if (tiles[a] >= x + y + z && tiles[a + 1] >= y + z && tiles[a + 2] >= z) {
int remaining = tiles[a] - (x + y + z);
next_dp[y][z] = max(next_dp[y][z], dp[x][y] + z + remaining / 3);
}
dp = next_dp;
}
int64_t answer = 0;
for (int x = 0; x < 3; x++)
for (int y = 0; y < 3; y++)
answer = max(answer, dp[x][y]);
cout << answer << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int tests = 1;
// cin >> tests;
for(int test = 1;test <= tests;test++) {
run_cases();
}
}