1893A - Anonymous Informant - CodeForces Solution


brute force implementation

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll                  long long
#define ld                  long double
#define mod                 1000000007
#define inf                 1e9
#define endl                '\n'


static bool comp(const pair<int, int>& p1, const pair<int, int>& p2){
    if(p1.first!=p2.first){
        return p1.first<p2.first;
    }else{
        return p1.second>p2.second;
    }
}


void solve(){
    int n, k; cin>>n>>k;

    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    int lastInd = n-1;
    k = min(k, n);

    for(int j=0; j<k; j++){
        if(a[lastInd] > n){
            cout << "NO" << endl;
            return;
        }
        
        lastInd -= a[lastInd];
        if(lastInd < 0){
            lastInd += n;
        }
    }

    cout << "YES" << endl;

    

}


int main(){
    fast_io;
    cout << fixed;
    cout << setprecision(10);
 
    int t;
    t=1;
    cin>>t;
 
    while(t--)
    {
        solve();
    }
}



Comments

Submit
0 Comments
More Questions

600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets