/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 4ms 328.0 KiB
#3 Accepted 2ms 320.0 KiB
#4 Time Exceeded ≥2073ms ≥6.566 MiB
#5 Time Exceeded ≥2094ms ≥6.578 MiB
#6 Time Exceeded ≥2090ms ≥6.668 MiB
#7 Time Exceeded ≥2091ms ≥6.578 MiB
#8 Time Exceeded ≥2076ms ≥6.695 MiB
#9 Time Exceeded ≥2094ms ≥6.688 MiB
#10 Time Exceeded ≥2080ms ≥6.664 MiB
#11 Time Exceeded ≥2086ms ≥6.59 MiB
#12 Time Exceeded ≥2093ms ≥6.609 MiB
#13 Time Exceeded ≥2089ms ≥6.574 MiB
#14 Time Exceeded ≥2092ms ≥6.578 MiB
#15 Time Exceeded ≥2071ms ≥6.605 MiB
#16 Time Exceeded ≥2071ms ≥6.574 MiB
#17 Time Exceeded ≥2093ms ≥6.688 MiB
#18 Time Exceeded ≥2090ms ≥6.516 MiB
#19 Time Exceeded ≥2087ms ≥6.578 MiB
#20 Time Exceeded ≥2021ms ≥6.625 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 

#define ll long long
#define int long long
template<typename s, typename t> void smax(s &a, const t &b) {if (a<b) a=b;}
template<typename s, typename t> void smin(s &a, const t &b) {if (a>b) a=b;}
char gap = 32;

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define fill(x, y) memset(x, y, sizeof(x))
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define lll __int128_t
ll hashPrime = 1610612741;

void solve(){
    int n; cin >> n;
    vector<int>v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    vector<int> r(n, -1);
    
    for (int i = 0; i < n; i++) {
        if (r[i] == -1) {
            queue<int> q;
            q.push(i);
            int cnt = 0;
            while (!q.empty()) {
                int cur = q.front();
                q.pop();
                if (r[cur] != -1) continue;
                r[cur] = cnt++;
                int next = cur + v[cur];
                if (next < n && r[next] == -1) {
                    q.push(next);
                }
            }
        }
    }
    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        vector<int> Ai = v;
        Ai[i] = 0;

        vector<bool> on(n, false);
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (!on[j]) {
                cnt++;
                queue<int> q;
                q.push(j);
                while (!q.empty()) {
                    int curr = q.front();
                    q.pop();
                    if (on[curr]) continue;
                    on[curr] = true;
                    int next = curr + Ai[curr];
                    if (next < n && !on[next]) {
                        q.push(next);
                    }
                }
            }
        }
        cout << cnt << " ";
    }
    cout << endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; cin >> t;
    while(t--){
        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 16:41:47
Judged At
2024-10-03 13:37:08
Judged By
Score
15
Total Time
≥2094ms
Peak Memory
≥6.695 MiB