/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 7ms 1.312 MiB
#3 Accepted 7ms 1.328 MiB
#4 Accepted 7ms 1.324 MiB
#5 Accepted 7ms 1.324 MiB
#6 Accepted 7ms 1.324 MiB
#7 Accepted 7ms 1.332 MiB
#8 Accepted 7ms 648.0 KiB
#9 Accepted 3ms 540.0 KiB
#10 Accepted 3ms 644.0 KiB
#11 Accepted 7ms 1.277 MiB
#12 Accepted 7ms 1.312 MiB
#13 Accepted 7ms 1.328 MiB
#14 Accepted 7ms 1.277 MiB
#15 Accepted 7ms 1.277 MiB
#16 Accepted 7ms 1.277 MiB
#17 Accepted 6ms 1.32 MiB

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    vector <int> a(n);
    for (auto& x:a) cin >> x;
    int ans (0), c(0);
    bool f (false);
    for (int i(0); i < n; i++) {
      if (a[i] == 1) {
         f = true; c++;
      }
      else if (a[i] != 2 && f) {
        c++;
      }
      else if (a[i] == 2) {
        f = false; c = 0;
      }
      if (a[i] == 3) {
        ans = max (ans, c);
      }
    }
    cout << ans << '\n';
  }
}

Information

Submit By
Type
Submission
Problem
P1036 Perfect subarray
Language
C++17 (G++ 13.2.0)
Submit At
2024-03-26 09:51:14
Judged At
2024-03-26 09:51:14
Judged By
Score
100
Total Time
7ms
Peak Memory
1.332 MiB