0%

CF2059C Customer Service

思路讲解

思路其实比较简单,但没那么容易想到,只需要看队尾连续的一即可。

这乍听起来有点奇怪,但其实是因为a ≥ 1,所以说这个在 j 时刻(这个j是指离结束时刻的距离)的操作无法完成 j-1的这个指标,那么就没人帮他完成了。

AC代码

https://codeforces.com/problemset/submission/2059/310691802

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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

这个的问题在于

1
2
3
4
1
2
1 1
1 1
1
2
3
4
5
6
7
8
9
10
FOR(i,1,N){
ll cnt=0;
ROF(j,N,0){
if(A[i][j]!=1){
suffix1[i]=cnt;
break;
}
++cnt;
}
}

这种break式样的,做赋值的,一定要想到如果一直满足情况怎么办?