|

General

# Author Problem Lang Verdict Time Memory Sent Judged
232103081 Practice:
jashu_18
1893A - 29 GNU C++20 (64) Wrong answer on test 2 30 ms 8 KB 2023-11-09 19:51:20 2023-11-09 19:51:20
→ Source
#include <bits/stdc++.h>
#define pb push_back
// #define mp make_pair

#define gcd __gcd
#define ll long long
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rloop(i, n) for (ll i = n - 1; i >= 0; i--)
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

// Union Find Algorithm Almost O(1) for reasonable size N. O(log*N) to be precise
struct UnionFind
{
int n;
vector<int> rank;
vector<int> parent;
// store other info as required
UnionFind(int n)
{
rank.resize(n);
fill(rank.begin(), rank.end(), 0);
parent.resize(n);
for (int i = 0; i < n; i++)
{
parent[i] = i;
}
}
int get(int a)
{
return parent[a] = (parent[a] == a ? a : get(parent[a]));
}
void merge(int a, int b)
{
a = get(a);
b = get(b);
if (a == b)
{
return;
}
if (rank[a] == rank[b])
{
rank[a]++;
}
if (rank[a] > rank[b])
{
parent[b] = a;
}
else
{
parent[a] = b;
}
}
};

// Find maxXor of two numbers in a array
struct Node
{

bool containsKey(int ind)
{
}
Node *get(int ind)
{
}
void put(int ind, Node *node)
{
}
};
class Trie
{
private:
Node *root;

public:
Trie()
{
root = new Node();
}

public:
void insert(int num)
{
Node *node = root;
// cout << num << endl;
for (int i = 31; i >= 0; i--)
{
int bit = (num >> i) & 1;
if (!node->containsKey(bit))
{
node->put(bit, new Node());
}
node = node->get(bit);
}
}

public:
int findMax(int num)
{
Node *node = root;
int maxNum = 0;
for (int i = 31; i >= 0; i--)
{
int bit = (num >> i) & 1;
if (node->containsKey(!bit))
{
maxNum = maxNum | (1 << i);
node = node->get(!bit);
}
else
{
node = node->get(bit);
}
}
return maxNum;
}
};
int maxXOR(int n, int m, vector<int> &arr1, vector<int> &arr2)
{
Trie trie;
for (int i = 0; i < n; i++)
{
trie.insert(arr1[i]);
}
int maxi = 0;
for (int i = 0; i < m; i++)
{
maxi = max(maxi, trie.findMax(arr2[i]));
}
return maxi;
}

/*ASCII
0->48 ; A->65 ; a->97
*/
ll fact(ll num)
{
ll prev = 1, curr = 1;

for (int i = 1; i <= num; i++)
{
curr = ((prev % mod) * (i % mod)) % mod;
prev = curr;
}

return curr % mod;
}
bool helper(ll mid, ll n, vector<ll> &a)
{
ll cnt = 1, key = a[0] + mid;

for (int i = 1; i < a.size(); i++)
{
if (abs(a[i] - key) > mid)
{
cnt++;
key = a[i] + mid;
}
}

return cnt <= 3;
}
void solve()
{
ll n, k;
cin >> n >> k;
vector<ll> b(n);
loop(i, n) cin >> b[i];
vector<int> vis(n, 0);
bool flag = true;
int ind = n - 1;
while (true)
{
if (b[ind] > n)
{
flag = false;
break;
}
if (vis[ind])
{
break;
}
vis[ind] = 1;
ind -= b[ind];
if (ind < 0)
ind += n;
}
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}

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

int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?