/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 2ms 320.0 KiB
#4 Accepted 28ms 2.418 MiB
#5 Accepted 31ms 2.977 MiB
#6 Accepted 28ms 2.211 MiB
#7 Accepted 28ms 2.309 MiB
#8 Accepted 34ms 3.102 MiB
#9 Accepted 39ms 3.305 MiB
#10 Accepted 31ms 3.055 MiB
#11 Accepted 30ms 3.199 MiB
#12 Accepted 31ms 3.066 MiB
#13 Accepted 31ms 3.055 MiB
#14 Accepted 31ms 3.062 MiB
#15 Accepted 31ms 3.055 MiB
#16 Accepted 30ms 3.062 MiB
#17 Accepted 30ms 3.059 MiB
#18 Accepted 30ms 3.16 MiB
#19 Accepted 30ms 3.102 MiB
#20 Accepted 32ms 3.055 MiB

Code

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

void solve() {
	int n; cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int ways[n] {};
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!ways[i]) ans++;
		if (i + arr[i] < n) ways[i + arr[i]]++;
	}
	// cout << ans << " ";
	for (int i = 0; i < n; i++) {
		int a = ans;
		if (i + arr[i] < n and ways[i + arr[i]] == 1) a++;
		cout << a << " ";
	}
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int tt = 1;
	cin >> tt;
	while (tt--) {
		solve();
	}
}

Information

Submit By
Type
Submission
Problem
P1066 Light switches
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 17:26:20
Judged At
2024-11-11 03:23:00
Judged By
Score
100
Total Time
39ms
Peak Memory
3.305 MiB