CF2059C Customer Service · znzryb
## 思路讲解
思路其实比较简单,但没那么容易想到,只需要看队尾连续的一即可。
这乍听起来有点奇怪,但其实是因为a ≥ 1,所以说这个在 j 时刻(这个j是指离结束时刻的距离)的操作无法完成 j-1的这个指标,那么就没人帮他完成了。
## AC代码
[https://codeforces.com/problemset/submission/2059/310691802](https://codeforces.com/problemset/submission/2059/310691802)
```cpp
// Problem: CF2059C Customer Service
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF2059C
// Memory Limit: 250 MB
// Time Limit: 2000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int) a.size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
typedef pair<DB,DB> pdd;
constexpr ll MAXN=static_cast<ll>(3e2)+10,INF=static_cast<ll>(5e18)+3;
ll N,M,T,A[MAXN][MAXN];
// ll cur[MAXN];
// ll sumA[MAXN][MAXN];
ll suffix1[MAXN];
inline void solve(){
cin>>N;
for(int i=1;i<=N;++i){
for(int j=1;j<=N;++j){
cin>>A[i][j];
}
}
FOR(i,1,N){
ll cnt=0;
ROF(j,N,0){
if(A[i][j]!=1){
suffix1[i]=cnt;
break;
}
++cnt;
}
}
sort(suffix1+1,suffix1+1+N);
ll ans=0;
FOR(i,1,N){
if(suffix1[i]>=ans){
++ans;
}
}
// #ifdef LOCAL
// FOR(i,1,N){
// cerr<<suffix1[i]<<" ";
// }
// cerr<<"\n";
// #endif
cout<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
solve();
}
return 0;
}
/*
AC
https://codeforces.com/problemset/submission/2059/310691802
*/
```
## 心路历程(WA,TLE,MLE……)
[https://codeforces.com/problemset/submission/2059/310691236](https://codeforces.com/problemset/submission/2059/310691236)
这个的问题在于
```cpp
1
2
1 1
1 1
```
```cpp
FOR(i,1,N){
ll cnt=0;
ROF(j,N,0){
if(A[i][j]!=1){
suffix1[i]=cnt;
break;
}
++cnt;
}
}
```
这种break式样的,做赋值的,一定要想到如果一直满足情况怎么办?