fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n;
  17. cin >> n;
  18.  
  19. vector<int> vec(n);
  20.  
  21. int isZero = 0;
  22. int ans = 0;
  23.  
  24. for(int i = 0; i < n; i++){
  25. cin >> vec[i];
  26.  
  27. if(vec[i] == 0){
  28. ans += isZero;
  29. isZero = 0;
  30. }
  31. else{
  32. isZero = 1;
  33. }
  34. }
  35. ans += isZero;
  36.  
  37. if(ans < 2)
  38. cout << ans << '\n';
  39. else
  40. cout << 2 << '\n';
  41. }
  42.  
  43.  
  44. signed main(){
  45. FastIO();
  46.  
  47. int t = 1;
  48. cin >> t;
  49.  
  50. while (t--){
  51. solve();
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5316KB
stdin
4
4
0 0 0 0
5
0 1 2 3 4
7
0 2 3 0 1 2 0
1
1000000000
stdout
0
1
2
1