for ( int i = 0; i < 7; i++ ) {
if ( v[i].first != i + 1 ) {
puts("no");
return 0;
}
}
for ( int i = 7; i < 13; i++ ) {
if ( v[i].first != 13 - i || v[i].second != v[12 - i].second ) {
puts("no");
return 0;
}
}
can someone explain me this?
This is my accepted solution for this question on Codechef
#include <bits/stdc++.h>
using namespace std;
int main()
{
long t;
cin>>t;
while(t–)
{
long n;
cin>>n;
int p[n],flag=1,i;
for(i=0;i<n;i++)
cin>>p[i];
int chec[8]={0};
int main() {
int T;
scanf("%d", &T);
assert(T >= 1 && T <= MAX);
while (T–) {
int n;
scanf("%d", &n);
assert(n >= 1 && n <= MAX);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
assert(a[i] >= 1 && a[i] <= MAX);
}
vector<pair<int, int> > cnts;
int cnt = 1, which = a[0];
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
cnt++;
} else {
cnts.push_back(make_pair(which, cnt));
which = a[i];
cnt = 1;
}
}
if (cnt > 0) {
cnts.push_back(make_pair(which, cnt));
}
int ok = true;
// cnt dentoes consecutive groups of equal numbers.
if (cnts.size() == 13) {
for (int i = 0; i < 13; i++) {
if (cnts[i] != cnts[13 - i - 1]) {
ok = false;
}
if (i < 7 && cnts[i].first != i + 1) {
ok = false;
}
}
} else {
ok = false;
}
puts(ok ? “yes” : “no”);
}
return 0;
}
Now Test case i have used is this
1
13
3 4 5 6 1 2 7 2 1 6 5 4 3
My accepted solution is giving yes for above test case while Author’s solution giving no for the same…
I have run several hundreds of codes of other people also for the same test case.Their answer is yes for above test .
But Editorial and Tester solution is giving no for the same.
Just want to ask Codechef Admins what is happening here .Even the guys who have made the question have not used the correct test cases for checking solutions.
Could anyone please point out which cases I am missing https://www.codechef.com/viewsolution/30560990
I decremented the elements by 1 after each recursion and checked if the first and last a1 elements are equal to 1