『agc 003b』simplified mahjong Solution

算了懒得搞,直接放传送门了:

传送door♂

Solution

  • 如果没有$A_i$的值是0,那么答案始终是$left lfloor dfrac{S}{2} right rfloor$,其中$S$是卡牌的总数
  • 如果有$A_i$的值是0,那么你不能使用有$i$的卡片,所以你可以把这个序列从$i$的地方断开,然后对于没一块单独处理
  • 一共至多处理$n$次,所以时间复杂度是$O(n)$的
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

#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;
ll sz[100001];
ll a[100001];
inline void _read(ll &x)
{
x = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
while (isdigit(t))
{
x = x * 10 + t - '0';
t = getchar();
}
}
inline void _read(int &x)
{
x = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
while (isdigit(t))
{
x = x * 10 + t - '0';
t = getchar();
}
}
int n;
int ()
{
_read(n);
register ll ans = 0;
for (register int i = 1;i <= n;i ++) _read(a[i]);
for (register int i = 1;i <= n;i ++)
{
register ll qwe = min (a[i], a[i + 1]);
if ((a[i] - qwe) & 1 && qwe) qwe--;
ans += qwe;
a[i] -= qwe;
a[i + 1] -= qwe;
ans += a[i] / 2;
}
printf("%lld", ans);
return 0;
}