I have run my code in my ide and it works. It gives the correct answer. Now I’m wondering what’s the problem that when I submit it here is appears to be a wrong answer…
Give a link to your code for us to help . or just paste it here .
import java.util.Scanner;
class EvsCoinFlip {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a=0;
int ctr,ctr1;
int T,temp;
int I[],N[],Q[],G[];
int answer[];
System.out.println("Input:");
Scanner playerInput=new Scanner(System.in);
T=playerInput.nextInt();
temp=playerInput.nextInt();
I = new int[temp*T];
N = new int[temp*T];
Q = new int[temp*T];
G = new int[temp];
answer = new int[temp*T];
ctr= temp;
ctr1= T;
G[a]=temp;
if((T>=0)&&(T<=10))
{
while(ctr1>0)
{
while(ctr>0){
I[a]=playerInput.nextInt();
N[a]=playerInput.nextInt();
Q[a]=playerInput.nextInt();
ctr--;
a++;
}
ctr=temp;
ctr1--;
}
}
else
System.out.println("error input");
a=0;
for(int j=0; (ctr*T)>j;j++){
if(N[a]%2==0)
answer[a]=N[a]/2;
else
{ if(((I[a]==1)||(I[a]==2))&&((Q[a]==1)||(Q[a]==2)))
{
if(I[a]==Q[a])
answer[a]=N[a]/2;
else
answer[a]=(N[a]/2)+1;
}
else
{System.out.println("error input");
}
}
a++;
}
System.out.println("Output:");
ctr=temp;
a=0;
for(int j=0; (ctr*T)>j;j++){
System.out.println(answer[a++]);
}
}
}
The code will fail for the following input.
2
2
1 5 1
1 5 2
1
1 5 1
Here the output should be
2
3
2
In your code it is assumed that G is present only once in the input. But G will be present for every test case T. Hence it is failing
Thank you so much . I’ll try changing the codes now.hehe I haven’t considered having two values for the G. thank you. Hope my code will work soon. maybe I’ll just update you here …
hello. I have changed my codes . This time its gives the correct answer for the above example you have given but still it is a “wrong answer”
Can u post the code once again.
actually i haven’t considered the size of my array but it is already working. I just can’t figure out the problem.
import java.util.Scanner;
class EvsCoinFlip {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a=0, b=0 ,c, v=0,d=0 ,e;
int ctr=0,ctr1=0;
int T=0,temp, temp1=0;
int I[],N[],Q[],G[];
int answer[];
System.out.println("Input:");
Scanner playerInput=new Scanner(System.in);
T=playerInput.nextInt();
c=playerInput.nextInt();
I = new int[20000];
N = new int[20000];
Q = new int[20000];
answer = new int[20000];
G = new int[T];
e=T;
G[b++]=c;
if((T>=0)&&(T<=10))
{
while(e-->0)
{
ctr=G[d];
ctr1=ctr1+ctr;
while(ctr>0)
{
I[v]=playerInput.nextInt();
N[v]=playerInput.nextInt();
Q[v]=playerInput.nextInt();
ctr--;
v++;
}
if(e!=0)
G[++d]=playerInput.nextInt();
ctr=G[d];
}
}
else
System.out.println("error input");
for(int j=0; (ctr1)>j;j++)
{
if(N[j]%2==0)
answer[j]=N[j]/2;
else
{
if(((I[j]==1)||(I[j]==2))&&((Q[j]==1)||(Q[j]==2)))
{
if(I[j]==Q[j])
answer[j]=N[j]/2;
else
answer[j]=(N[j]/2)+1;
}
else
System.out.println("error input");
}
}
System.out.println("Output:");
for(int g=0; (ctr1)>g;g++)
{
System.out.println(answer[g]);
}
}
}
I am facing the same issue of wrong answer. And whenever i run my code I think if I can get the test data and run it on my end or if codechef can provide more details on the test case on which the program failed.
Coming to my point…Can someone help with my code. Its also stating wrong answer but when i run test cases it gives right answer (even the one mentioned in this discussion).
#include <stdio.h>
int main(void) {
unsigned int t,g,i,n,q;
unsigned int c,d,coinData;
unsigned int hd,td;
scanf("%d",&t);
while((t--) != 0){
scanf("%d",&g);
while((g--) != 0){
hd=0; td=0;
scanf("%d %d %d",&i,&n,&q);
coinData=0;
if(i==1){
coinData=coinData |((1<<n)-1);
}
//Flipping the coins.
for(c=1;c<=n;c++){
d=0xFFFFFFFF;
d=d<<c;
d=~d;
coinData=coinData^d;
}//end of for
//Counting heads and Tails
for(c=1;c<=n;c++){
coinData=coinData>>1;
if(coinData & 0x00000001){
hd++;
}
else if(~(coinData & 0x00000001))
{
td++;
}
else
printf("Unknown state occurred");
}
//Display data
if(q==1){
printf("%d\n",hd);
}
else if(q==2){
printf("%d\n",td);
}
}//while g end
}//while t end
return 0;
}
The same problem continues even 8 years later !!! @codechef pls check… MY CODE IS 100% WORKING IN ALL IDEs.
My code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
long long g ; cin >> g;
for ( int z = 0 ; z < g ; z++)
{
int i , q ;
long long n;
cin >> i >> n >> q;
long long heads = n / 2 ;
long long tails = n / 2 ;
if ( heads + tails < n && i == 1 )
{
tails++;
}
else
{
heads++;
}
(q == 1) ? cout << heads << "\n" : cout << tails << "\n" ;
}
}
return 0;
}
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–>0)
{
int g;
cin>>g;
while(g–>0)
{
int i,n,q,haid=0,tail=0;
cin>>i>>n>>q;
if(n%2==0)
{
haid=(n/2);
tail=(n/2);
}
else if(n%2!=0 && i==1)
{
haid=(n)/2;
tail=(n/2)+1;
}
else if(n%2!=0 && i==2){
haid=(n/2)+1;
tail=n/2;
}
if(q==1){
cout<<haid<<"\n";
}
else
cout<<tail<<"\n";
}
}
return 0;
}
fully working code;
I am facing runtime error in my code…
#include<stdio.h>
#include<math.h>
main()
{
int T;
scanf("%d",&T);
while(T–)
{
int G;
scanf("%d",&G);
int a[G],b[G],c[G],d[10];
for(int z=0;z<G;z++)
{ int x=0;
scanf("%d",&a[z]);
scanf("%d",&b[z]);
scanf("%d",&c[z]);
if(a[z]==1)
{
x=0;
while(x<b[z])
{
d[x]=1;
x++;
}
}
else
{
x=0;
while(x<b[z])
{
d[x]=2;
x++;
}
}
for(int i=0;i<x;i++)
{
for(int j=0;j<=i;j++)
{
if(i<b[z])
{
if(d[j]==1)
{
d[j]=2;
}
else
{
d[j]=1;
}
}
}
}
int count=0;
for(int i=0;i<x;i++)
{
if(d[i]==c[z])
{
count++;
}
}
printf("%d\n",count);
}
}
}
I am also facing TLE. I don’t know why is this happening.
Code is works for all test cases and i have reduced the complexity to as low as i can.
Please someone guide me.
This is my solution link:
https://www.codechef.com/viewsolution/45782330