版本比较
题解:P16755 [GKS 2020 #C] Countdown
正文
增加 2 行删除 2 行
31 行未改动3233343536373839404142434428 行未改动31 行未改动- 否则 `cnt++`,继续循环。4. 如果 `ok = true`,说明以 $A_i$ 结尾的数列满足条件,`ans++`。3. 输出答案。**时间复杂度:** 遇到每个 $1$ 时需要向前检查最多 $K-1$ 个元素,最坏情况下时间复杂度为 $O(NK)$。### 参考代码```cpp#include <bits/stdc++.h>using namespace std;using i64 = long long;28 行未改动31 行未改动3233343536373839404142434428 行未改动31 行未改动- 否则 `cnt++`,继续循环。4. 如果 `ok = true`,说明以 $A_i$ 结尾的数列满足条件,`ans++`。3. 输出答案。**时间复杂度:** 遇到每个 $1$ 时需要向前检查最多 $K-1$ 个元素,最坏情况下时间复杂度为 $O(NK)$,一般情况下接近 $O(N)$ 或更快。逆向思维有时是一个很好的办法,在一些情况中比普通要快。### 参考代码```cpp line-numbers#include <bits/stdc++.h>using namespace std;using i64 = long long;28 行未改动