I’ve pretty much followed whatever was mentioned in the editorial. My sol’n is passing the sample test case but gives WA upon submission. Please help me rectify the issue, thanks.
#include <iostream>
using namespace std;
int main() {
int cases,d0,d1,d2,d3,d4,d5,d6,digitsum,S;
unsigned long K;
cin >> cases;
while(cases--){
cin >> K >> d0 >> d1;
digitsum = d0+d1;
if(K==2){
(!(digitsum%3))?cout<<"YES"<<endl:cout<<"NO"<<endl;
continue;
}
d2 = (d0+d1)%10;
d3 = (2*(d0+d1))%10;
d4 = (4*(d0+d1))%10;
d5 = (8*(d0+d1))%10;
d6 = (6*(d0+d1))%10;
S = d3+d4+d5+d6;
switch((K-3)%4){
case 0: digitsum += d2+(S*((K-3)/4));
break;
case 1: digitsum += d2+(S*((K-3)/4))+d3;
break;
case 2: digitsum += d2+(S*((K-3)/4))+d3+d4;
break;
case 3: digitsum += d2+(S*((K-3)/4))+d3+d4+d5;
}
(!(digitsum%3))?cout<<"YES"<<endl:cout<<"NO"<<endl;
}
return 0;
}
int main() {
// your code goes here
int t;
cin>>t;
for(int i=0;i<t;i++)
{
long long int k;
cin>>k;
long long int d0,d1;
cin>>d0;cin>>d1;
long long int j,count;
count=d0+d1;
k-=2;
Here the cycle will always be a permutation of 2, 4, 6, 8. So why is it giving WA on putting 20 directly in place of S? OR
Give me an example where d2, d3, d4, d5 are not the permutation of 2,4,6,8.
I have also applied this approach because this seems to be a very generic approach other than what others have provided but the answer is wrong as per codechef, is your code working or you can give me some boundary cases which doesn’t satisfy this approach?
Very precise and optimized code. I never would have thought of using the bitwise operator. I would appreciate it if you could spare some time to explain how you would come up with the solution using the bitwise operator.
#include <iostream>
using namespace std;
int main() {
// your code goes here
short d0,d1,term1,y;
int t,sum;
long long k,repeat;
cin>>t;
while(t--) {
cin>>k>>d0>>d1;
sum=d0+d1;
for (int i=2;i<k;i++) {
y=sum%10;
if (y==0)
break;
else if (y%2==0) {
repeat=(k-i)/4;
sum+=repeat*20;
term1=(k-i)%4;
if (term1==3)
sum+=y+((2*y)%10)+((3*y)%10);
else if (term1==2)
sum+=y+((2*y)%10);
else if (term1==1)
sum+=y;
break;
}
else
sum+=y;
}
if (sum%3==0)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
I have tried all kinds of input and the logic is correct but while submission it says wrong answer. Can someone tell me where it’s going wrong?