/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 8ms 1.27 MiB
#3 Accepted 8ms 1.316 MiB
#4 Accepted 8ms 1.312 MiB
#5 Accepted 8ms 1.27 MiB
#6 Accepted 8ms 1.312 MiB
#7 Accepted 9ms 1.27 MiB
#8 Accepted 8ms 580.0 KiB
#9 Accepted 3ms 576.0 KiB
#10 Accepted 3ms 580.0 KiB
#11 Accepted 8ms 1.32 MiB
#12 Accepted 8ms 1.273 MiB
#13 Accepted 8ms 1.062 MiB
#14 Accepted 8ms 1.266 MiB
#15 Accepted 8ms 1.062 MiB
#16 Accepted 8ms 1.316 MiB
#17 Accepted 8ms 1.312 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-11-11 03:40:18
Judged By
Score
100
Total Time
9ms
Peak Memory
1.32 MiB