/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Wrong Answer 2ms 324.0 KiB
#3 Wrong Answer 2ms 320.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
  int t;
  cin >> t;
  while (t--){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n + 2), vis(n + 2);
    for (int i = 0; i < n; i++){
      cin >> a[i];
    }
    for (int i = 0; i < n; i++){
      if (vis[i]) continue;
      ans++;
      int j = i + a[i];
      while (j < n && vis[j] < 2){
        vis[j]++;
        j = j + a[j];
      }
    }
    for (int i = 0; i < n; i++){
      int x = ans;
      if (i + a[i] < n && vis[i + a[i]] == 1) x++;
      cout << x << ' ';
    }
    cout << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1066 Light switches
Contest
Brain Booster #4
Language
C++17 (G++ 13.2.0)
Submit At
2024-07-14 16:18:12
Judged At
2024-11-11 03:24:24
Judged By
Score
5
Total Time
2ms
Peak Memory
324.0 KiB