May you tell me where I am wrong in ALLSUB problem??
https://www.codechef.com/viewsolution/26842257
Problems are too basic like why? TREEVER seems interesting at first but turns out to be dp with a very trivial greedy comparator, and ICECREM’s meet in the middle isn’t anything inventive.
can anyone tell me where i am going wrong in chef feed cats problem
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int n,m,input,flag=1;cin>>n>>m;
int arr[n+1]={0};
for(int i=0;i<m;i++){cin>>input;
for(int j=1;j<n+1;j++){if(arr[j]<arr[input]){flag=0;break;}}
if(flag==0){cout<<"NO"<<endl;break;}
arr[input]=arr[input]+1;
}
if(flag==1)cout<<"YES"<<endl;
}
return 0;
}
1
bba
aaabbbcccddd
Your code gives aabbbacccddd while correct answer is aabbabcccddd
Help me, why its give me a WT.
try:
t = int(input())
while t>0:
n = int(input())
x = []
y = []
z = []
ct = n
while ct>0:
a , b, c = map(int, input().split())
x.append(a)
y.append(b)
z.append©
ct-=1
for i in range(n):
if i==0 and x[i]==2:
print("NO")
else:
if x[i]==1:
print("YES")
else:
if x[i-1]==1:
print("YES")
elif y[i]==z[i]:
print("YES")
else:
print("NO")
x.clear()
y.clear()
z.clear()
t-=1
except EOFError:
pass
If p==2 and a!=b it need not necessarily be “NO” all the time since you can always remember the favourite team as long as the condition max(a,b)<max(pa,pb) keeps on getting satisfied and the state changes to “NO” only when the condition becomes false
Have a look:
for _ in range(int(input())):
n = int(input())
p,pa,pb = 2,0,0
flag=False
for _ in range(n):
m,a,b = map(int,input().split())
if m == 1:
flag=True
print(‘YES’)
p,pa,pb = m,a,b
else:
if (flag and min(a,b) < max(pa,pb)) or (a==b):
print(‘YES’)
else:
flag=False
print(‘NO’)
p,pa,pb = m,a,b
Hey @down_the_bit , Thanks for the help. What about the if block inside else of the following code :
for _ in range(int(input())):
n = int(input())
p,pa,pb = 2,0,0
for _ in range(n):
m,a,b = map(int,input().split())
if m == 1 or a==b:
print('YES')
p,pa,pb = m,a,b
else:
if pa==pb:
print('NO')
elif min(a,b) < max(pa,pb):
print('YES')
else:
print('NO')
p,pa,pb = m,a,b
That would not be required but you need some flag variable to check if the favourite team is still recognisable
1
baa
aabb
The correct answer is baab ,but yous solution print bbaa .
i think that might be due to the fact that lunchtime is focused for school students.
@kshitij_789
@heiseinstein
All substring
can someone tell me which test case i am leaving.
https://www.codechef.com/viewsolution/26854677
1.why are you sorting the 2 string in beginning line 18-19
2.add a line after line 29 - cnt[s[i] - ‘a’]–;
you first make these changes and try again as I have not read the rest of your code
Thank you. It makes sense. I was wondering about differences between cookoff and lunchtime. Now I know
The problem is basically based on a small observation. We can always get the required sum when the given elements are consecutive. Next, consider finding out A[i] + A[i+2]. Note that you only need to check for B[i] and B[i+1], since taking any more terms will only increase the number of variables in the equations which cannot be eliminated. Now any algebraic manipulation on B[i] and B[i+1] doesn’t give you A[i] + A[i+2]. Thus we can always say that if the given indices in the query p and q have same parity, we can not find the required sum and hence the answer is “UNKNOWN”. Also when you consider finding out A[i] + A[i+3] you can immediately see that B[i] - B[i+1] + B[i+2].
Thus we can come up with a general solution. Consider take the sum B[1] - B[2] + B[3] - B[4] + ... + (-1)^(n-2) * B[n-1]. We can see that we get the sums A[1] + A[2], A[1] - A[3], A[1] + A[4], ... , A[n-1] + (-1)^n * A[n]. Let’s call this array as pre[1 ... n], pre[1] = 0. We can use this to find the answer of any query where p and q have different parities.
Can anyone please give insights on the problem APPLE42 ?
