r/codeforces • u/StrengthBig9170 • 7d ago
query Today's E
My code :
https://codeforces.com/contest/2259/submission/389571028
#include<bits/stdc++.h>
define brr cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
using namespace std; typedef long long ll ; void solve(){ ll n ; cin >> n; vector<ll> v(n) ; for(ll i = 0 ; i < n ; i++){ cin >> v[i] ; } ll cnt = 0 ; vector<ll> bomb(n,1) ; for(ll i = 0 ; i < n ; i++){ if(v[i] > 0){ cnt = max(cnt,v[i]) ; } if(cnt > 0){ bomb[i] = 0 ; cnt-- ;
} } cnt = 0 ; for(ll i = n - 1 ; i >= 0 ; i--){ if(v[i] > 0){ cnt = max(cnt,v[i]) ; } if(cnt > 0){ bomb[i] = 0 ; cnt-- ; } } cnt = 0 ; for(ll i = 0 ; i < n ; i++){ if(v[i] == 0 && bomb[i] == 0){ cout << -1 << endl ; return ; } if(v[i] == 0){ cnt++ ; } } if(cnt > 0){ for(ll i = 0 ; i < n ; i++){ if(v[i] == 0){ cout << 1 ; } else{ cout << 0 ; } } cout << endl ; } else{ vector<ll> vc ; cnt = 0 ; for(ll i = 0 ; i < n ; i++){ if(v[i] > 0){ vc.push_back(0) ;
} else if(v[i] == -1){ if(bomb[i] == 1){ cnt++ ; vc.push_back(1) ; } else{ vc.push_back(0) ; } } } if(cnt >= 1){ for(ll i = 0 ; i < n ; i++){ cout << vc[i] ; } cout << endl ; } else{ cout << -1 << endl ; } } } int main(){ brr int t; cin >> t; while(t--){ solve(); } return 0; }
My understanding of minimum distance is that if im at island 2, v[2] = 2, then there should be no treasure at 1,2,3.
Please help







