892B. Wrath#愤怒的连环杀人事件(cin/cout的加速)

时间:2023-03-10 05:52:15
892B. Wrath#愤怒的连环杀人事件(cin/cout的加速)

题目出处:http://codeforces.com/problemset/problem/892/B

题目大意:一队人同时举刀捅死前面一些人后还活着几个

#include<iostream>
#define IO ios::sync_with_stdio(false);\
  cin.tie(0);\
  cout.tie(0);
using namespace std;
typedef __int64 LL;
const int maxn = 2e6+;
int p[maxn]; //库中有max同名
int main(){
IO;//输入输出流加速
int n;cin>>n;
for(int i=;i<n;i++) cin>>p[i];
LL cnt=p[n-], ans=;
for(int i=n-; i>=; i--){
if(!cnt) ans++;
cnt = (cnt-)>p[i]?(cnt-):p[i];
}
cout<<ans<<endl;
return ;
}

本题题目解题思路并不难,但是在测试的时候多次超时,然后看了别人的代码,在此体现了cin/cout的慢节奏

解决办法就是加入两行代码

#define IO ios::sync_with_stdio(false);\cin.tie(0);\cout.tie(0);
IO;//输入输出流加速
详细原因百度都可以查到。