/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 2ms 324.0 KiB
#4 Accepted 47ms 2.309 MiB
#5 Accepted 51ms 3.062 MiB
#6 Accepted 47ms 2.312 MiB
#7 Accepted 47ms 2.316 MiB
#8 Accepted 78ms 3.148 MiB
#9 Accepted 113ms 3.176 MiB
#10 Accepted 51ms 3.0 MiB
#11 Accepted 51ms 3.062 MiB
#12 Accepted 51ms 3.062 MiB
#13 Accepted 52ms 3.055 MiB
#14 Accepted 52ms 3.066 MiB
#15 Accepted 53ms 3.066 MiB
#16 Accepted 51ms 3.023 MiB
#17 Accepted 53ms 3.141 MiB
#18 Accepted 53ms 3.098 MiB
#19 Accepted 59ms 3.059 MiB
#20 Accepted 65ms 3.117 MiB

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]++;
        if (vis[j] > 1) break;
        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:22:25
Judged At
2024-11-11 03:24:18
Judged By
Score
100
Total Time
113ms
Peak Memory
3.176 MiB