Consider the test input:
1
2 INDIAN
TOP_CONTRIBUTOR
CONTEST_WON 1
Consider the test input:
1
2 INDIAN
TOP_CONTRIBUTOR
CONTEST_WON 1
I don’t understand why but for this it outputs 1
Start debugging then For a start, figure out how many laddus your program calculates, and how many it should calculate.
okay got it , thank you for the help
thanks again. It works fine now
Hi,
Can anyone please explain me how to solve Multiple of 3 (Problem Code: MULTHREE).
I am getting the right answer only for first testcase given in the problem. For 2nd testcase I am getting wrong and 3rd testcase it takes too long for execution.
Please help.
where exactly??
I am getting garbage value for Laddu question. This is my code. Pls help!
#include <stdio.h>
#include <string.h>
int main(void) {
int T, acts, temp;
char nation, str[20];
char a[] = “CONTEST_WON”;
char b[] = “TOP_CONTRIBUTOR”;
char c[] = “BUG_FOUND”;
scanf("%d", &T);
while(T--) {
int laddu=0;
scanf("%d %c", &acts, &nation);
for(int i=0; i<acts; i++) {
scanf("%s", str);
if(!strcmp(str, a)) {
scanf("%d", &temp);
laddu += 300+20-temp;
}
else if(!strcmp(str, b))
laddu += 300;
else if(!strcmp(str, c)) {
scanf("%d", &temp);
laddu += temp;
}
else laddu += 50;
}
printf("%d ", laddu);
if(nation == 'I') printf("%d\n", laddu/200);
else printf("%d\n", laddu/400);
}
return 0;
}
MULTHREE Problem
Here’s my code for the problem with complexity O(1).
It’s still giving TLE by 0.01s.
I don’t think it can be optimized further .
Help me please.
Please have a look.
Okay,Brother you got right but check your solution for this case {2,3,4,5,97}, here the middle element is 4 but answer is 97, in this case you have to check for each element , You just have to need two array sort first one and solve one and put it in second array and sort them. You will Get the answer right. Hope you like it.
for lapindromes you can sort first half and second half then compare…
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
for(int i = 0; i < t; i++){
unsigned long long int k;
int d0, d1;
cin>>k>>d0>>d1;
int base = d0 + d1;
unsigned long long sum = 2 * (d0 + d1);
if(sum == 10){
cout<<“NO”<<endl;
continue;
}
else{
int it = (k - 3)/4;
sum += (20 * it);
for(int m = 1; m <= ((k - 3) % 4); m++){
int x = (pow(2, m)*base);
sum += (x % 10);
}
}
if(sum % 3 == 0){
cout<<“YES”<<endl;
}
else
cout<<“NO”<<endl;
}
return 0;
}
This is my code for multiple of 3… Can someone tell me why it is showing WA
Can anyone please help to find the bug in my code. I am getting Wrong answer. I tried something different. Is my solution approach, wrong? Any suggestion or help will be appreciated. Thank you
#include<bits/stdc++.h>
using namespace std;
bool solve(){
ll k,d0,d1;
cin>>k>>d0>>d1;
int d2 = d0 + d1;
//corner case
if(k==2){
if((d0*10+d1)%3==0)
return true;
return false;
}
//corner case
if(k==3){
if((d0*100+d1*10+d2)%3==0)
return true;
return false;
}
vector<int> pattern; // pattern
/*
example : 13 8 1
the pattern we are looking to built is
pattern [ 2 2 1 2 1 1 0 1 0 0 2 0 ]
remainder of 4 5 6 7 8 9 10 11 12 13 14 15 th digit,
so, since the number ought to be 13(k) we check the 13th digits remainder.
*/
int rem = (d0*100+d1*10+d2)%3;
for (int i = 0; i < 12; i++)
{
d2 = (d2*2)%10;
rem = (rem*10 +d2)%3;
pattern.push_back(rem);
}
// debug(pattern)
/*
Since the pattern is repeating
[ 2 2 1 2 1 1 0 1 0 0 2 0 2 2 1 2 1 1 0 1 0 0 2 0 ]
it start to repeat at every 12 remainder,
so (k-3-1)%12 since we reduced the first 3 remainders which is not
repetitive. also we have checked in the corner cases.
*/
if(pattern[(k-3-1)%12]==0) return true;
return false;
}
int main() {
fastio();
ll t=1;
cin >> t;
while(t--) {
if(solve())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
Can someone help for MULTITHREE problem ? Test cases given are passing but after submitting I get WA .
Can anyone help me with ‘LAPIN’ question I’ve tried everything still getting a WA
#include<bits/stdc++.h>
using namespace std;
string reversestri(string a){
string rev;
reverse(a.begin(),a.end());
rev=a;
return rev;
}
string lapindromechec(string a){
string lapin;
int n = a.size();
int r = a.size()/2;
for (int i = 1; i<= r; i++){
swap(a[r-i], a[n-i]);
}
lapin=a;
return lapin;
}
int checksmal(string a){
for (int i = 0; i < a.size(); i++){
if(islower(a[i])){continue;
}else{return 0;}
}return 1;
}
int main(){
int t; cin>>t;
while(t--){
string a,r,l; cin>>a;
r = reversestri(a);
l=lapindromechec(a);
if (checksmal(a)==1){
if(r==a){cout<<"YES"<<endl;}else{
if(l==a){cout<<"YES"<<endl;
}else{cout<<"NO"<<endl;}}
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
O(n^2) is mostly TLE , Look at my solution
https://www.codechef.com/viewsolution/55951841
i did in O(n) .
sorting is O(log n ) which can be ignored in O(n) (traversing).
that would be O(n) not O(1).
https://www.codechef.com/viewsolution/55951841
i did without making a sorted budget array, in O(n) .
Can anyone tell me why my code is getting TLE for the problem MULTHREE
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
ll t;
cin>>t;
while(t–)
{
ll k,d0,d1,n=2;
cin>>k>>d0>>d1;
ll s=d0+d1;
ll val=(2s)%10+(4s)%10+(8s)%10+(6s)%10,tot;
tot=d0+d1+s%10+((val)((k-3)/4));
int y=(k-3)%4;
//cout<<“Total:”<<tot<<"\n";
while(y–)
{
tot=tot+((ns)%10);
n=(n*2)%10;
}
//cout<<“S:”<<s<<"\n";
//cout<<“Total:”<<tot<<"\n";
if(tot%3==0)
cout<<“Yes”<<"\n";
else
cout<<“No”<<"\n";
}
return 0;
}
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
Edit:
If it’s this: consider the test input:
1
2 7 9