Why is my virtual judge solution giving me wrong answers?

In summary: return arr[n]; } if(n==4) { arr[n]=e%10000007; return arr[n]; } if(n==5) { arr[n]=f%10000007; return arr[n]; } return arr[n];}int main(){ int cas; c
  • #1
fireflies
210
12
<< Mentor Note -- Posts edited to add code tags for better readability >>

Hello everyone-

The vjudge problem link is: http://www.lightoj.com/volume_showproblem.php?problem=1006

My solution is:

C:
#include <iostream>

using namespace std;

long long int arr[10001];
long long int a,b,c,d,e,f;

long long int F(int n)
{
    if(n==0)
    {
        arr[n]=a;
        return arr[n];
    }
    if(n==1)
    {
        arr[n]=b;
        return arr[n];
    }
    if(n==2)
    {
        arr[n]=c;
        return arr[n];
    }
    if(n==3)
    {
        arr[n]=d;
        return arr[n];
    }
    if(n==4)
    {
        arr[n]=e;
        return arr[n];
    }
    if(n==5)
    {
        arr[n]=f;
        return arr[n];
    }
    if(arr[n]!=-1)
        return arr[n];
    arr[n]=F(n-1) + F(n-2) + F(n-3) + F(n-4) + F(n-5) + F(n-6);
    return arr[n];
}

int main()
{
    int cas;
    cin>>cas;

    for(int i=1; i<=cas; i++)
    {
        int n;
        cin>>a>>b>>c>>d>>e>>f>>n;
        for(int i=0;i<=n;i++)
            arr[I]=-1;
        long long int result=F(n)%10000007;
        cout<<"Case "<<i<<": "<<result<<"\n";
    }
    return 0;
}

I got several wrong answers...

In the forum there is said: http://www.lightoj.com/forum_viewtopic.php?topic=193

A critical input output is:

Input:
1
10000007 0 0 0 0 0 0
Output:
Case 1: 0

I don't understand this... Can anyone help?? (edit: I got it... and edited the code. But still wrong answer. Can anybody tell me why?)[/I]
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
I need to login to view anything on that site.
 
  • #3
Given a code (not optimized), and necessary inputs, you have to find the output of the code for the inputs. The code is as follows:

C:
int a, b, c, d, e, f;
int fn( int n ) {
    if( n == 0 ) return a;
    if( n == 1 ) return b;
    if( n == 2 ) return c;
    if( n == 3 ) return d;
    if( n == 4 ) return e;
    if( n == 5 ) return f;
    return( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
}
int main() {
    int n, caseno = 0, cases;
    scanf("%d", &cases);
    while( cases-- ) {
        scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
        printf("Case %d: %d[B]\n[/B]", ++caseno, fn(n) % 10000007);
    }
    return 0;
}

Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains seven integers, a, b, c, d, e, f and n. All integers will be non-negative and 0 ≤ n ≤ 10000 and the each of the others will be fit into a 32-bit integer.

Output
For each case, print the output of the given code. The given code may have integer overflow problem in the compiler, so be careful.

Sample Input
Output for Sample Input

5

0 1 2 3 4 5 20

3 2 1 5 0 1 9

4 12 9 4 5 6 15

9 8 7 6 5 4 3

3 4 3 2 54 5 4

Case 1: 216339

Case 2: 79

Case 3: 16636

Case 4: 6

Case 5: 54
 
Last edited by a moderator:
  • #4
I updated my code... It is

C:
#include <iostream>

using namespace std;

long long int arr[10001];
long long int a,b,c,d,e,f;

long long int F(int n)
{
    if(n==0)
    {
        arr[n]=a%10000007;
        return a;
    }
    if(n==1)
    {
        arr[n]=b%10000007;
        return arr[n];
    }
    if(n==2)
    {
        arr[n]=c%10000007;
        return arr[n];
    }
    if(n==3)
    {
        arr[n]=d%10000007;
        return arr[n];
    }
    if(n==4)
    {
        arr[n]=e%10000007;
        return arr[n];
    }
    if(n==5)
    {
        arr[n]=f%10000007;
        return arr[n];
    }
    if(arr[n]!=-1)
        return arr[n];
    arr[n]=(F(n-1)%10000007 + F(n-2)%10000007 + F(n-3)%10000007 + F(n-4)%10000007 + F(n-5)%10000007 + F(n-6)%10000007)%10000007;
    return arr[n];
}

int main()
{
    int cas;
    cin>>cas;

    for(int i=1; i<=cas; i++)
    {
        int n;
        cin>>a>>b>>c>>d>>e>>f>>n;
        for(int i=0;i<=n;i++)
            arr[i]=-1;
        long long int result=F(n);
        cout<<"Case "<<i<<": "<<result<<"\n";
    }
    return 0;
}

but it is still getting W/A
 
Last edited by a moderator:
  • #5
1. Please post the question.
2> Please use CODE tags.
 
  • Like
Likes berkeman
  • #6
Vanadium 50 said:
1. Please post the question.
2> Please use CODE tags.
I posted the question
 
  • #7
The question on the vjudge is:
Given a code (not optimized), and necessary inputs, you have to find the output of the code for the inputs. The code is as follows:

C:
int a, b, c, d, e, f;
int fn( int n ) {
if( n == 0 ) return a;
if( n == 1 ) return b;
if( n == 2 ) return c;
if( n == 3 ) return d;
if( n == 4 ) return e;
if( n == 5 ) return f;
return( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
}
int main() {
int n, caseno = 0, cases;
scanf("%d", &cases);
while( cases-- ) {
scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
printf("Case %d: %d[B]\n[/B]", ++caseno, fn(n) % 10000007);
}
return 0;
}

Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains seven integers, a, b, c, d, e, f and n. All integers will be non-negative and 0 ≤ n ≤ 10000 and the each of the others will be fit into a 32-bit integer.

Output
For each case, print the output of the given code. The given code may have integer overflow problem in the compiler, so be careful.

Sample Input
Output for Sample Input

5

0 1 2 3 4 5 20

3 2 1 5 0 1 9

4 12 9 4 5 6 15

9 8 7 6 5 4 3

3 4 3 2 54 5 4

Case 1: 216339

Case 2: 79

Case 3: 16636

Case 4: 6

Case 5: 54
 
Last edited by a moderator:
  • #8
It is accepted now :)

Thanks though
 
  • #9
fireflies said:
I posted the question

No you didn't. You posted a link to a site not open to the general public.
 
  • #10
Vanadium 50 said:
No you didn't. You posted a link to a site not open to the general public.
I did... Check... I re-posted again. It is a virtual judge question, given the sample input and output... There is a code given there... We need to determine the possible outputs when the sample inputs are given. We cannot do it with the code given in the question since there is time limits 0.5 s. The question is here. Note, the code (not my one, the other one with sample input and output) is a part of the question.
 
  • #11
Vanadium 50 said:
No you didn't. You posted a link to a site not open to the general public.
Please read the first line of the post no#3 of the thread. That says what we have to do, and that post is the question :)
 
  • #12
Vanadium 50 said:
1. Please post the question.
2> Please use CODE tags.
fireflies said:
for(int i=0;i<=n;i++)
arr=-1;
long long int result=F(n);
You ignored V50's second point. Above is a quote of a few lines in your main() function. Below are the same lines of code. Notice a difference?
C:
for(int i=0;i<=n;i++)
            arr[i]=-1;
        long long int result=F(n);
Because you didn't use code tags, whatever indentation you might have used gets lost, making your code more difficult to read. This italics tag is also the reason that your code in post #4 suddenly switches to italics down near the end of your code. What's even worse, when you wrote arr[i], the browser renders the string [i] as an italics BBCode tag, so arr[i] becomes just arr, and now your code becomes truly unreadable. (I had to take extra steps to prevent the bracketed letter from being interpreted as an italics tag.)

For more information about code tags, see https://www.physicsforums.com/threads/read-this-before-posting-code-geshi-syntax-highlighter.773407/.
 
  • #14
Thanks for that :) Adding code tags is still hard for me. I hope I will learn soon. :)
 
  • #15
fireflies said:
Adding code tags is still hard for me.
They're not that hard at all. Put an opening code tag at the beginning, and a closing code tag at the bottom. In bold are the tags you would add for C code.
[code=c]int main() {
int n, caseno = 0, cases;
scanf("%d", &cases);
while( cases-- ) {
scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
printf("Case %d: %dn", ++caseno, fn(n) % 10000007);
}
return 0;
}
[/code]

Here's how the above would appear in a browser (the browser consumes the code tags):
C:
int main() {
    int n, caseno = 0, cases;
    scanf("%d", &cases);
    while( cases-- ) {
        scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
        printf("Case %d: %dn", ++caseno, fn(n) % 10000007);
    }
    return 0;
}
How hard is that?
fireflies said:
I hope I will learn soon. :)
Yes, I do too.
 
Last edited:
  • Like
Likes fireflies and berkeman
  • #16
Let's try

C:
int main()
{
printf("Thank You!");
return 0;
}
 
  • #17
Yeah! :)
 
  • #18
fireflies said:
Let's try

C:
int main()
{
printf("Thank You!");
return 0;
}
See? It's not hard.
Style-wise, I would indent the body of main() like this.
C:
int main()
{
   printf("Thank You!");
   return 0;
}

The code tag is pretty smart (or rather, the software that's behind these tags is). We support many different programming languages, so opening code tags with code=fortran or code=python will highlight keywords in those languages. Note that you can't have any spaces between 'code' and whatever language you're working with. There's a stickied post near the top of this forum section that goes into more detail about this stuff: https://www.physicsforums.com/threads/read-this-before-posting-code-geshi-syntax-highlighter.773407/.
 
  • Like
Likes fireflies
  • #19
I did not consider indentation actually. I might have been thinking the code tags does that too :D

And thanks for showing how to do this.
 
  • Like
Likes berkeman

1. What is a virtual judge problem?

A virtual judge problem is a computer science problem that uses an online platform to test and evaluate a programmer's code. It provides a simulated environment for the programmer to write and run their code, and then compares the output of their code with the expected output to determine if it is correct or not.

2. How does a virtual judge problem differ from a traditional coding challenge?

A virtual judge problem differs from a traditional coding challenge in that it is evaluated by a computer program rather than a human. This allows for faster and more objective evaluation, as well as the ability to provide immediate feedback and multiple test cases.

3. What are the benefits of using a virtual judge problem?

Using a virtual judge problem can help programmers improve their coding skills by providing real-time feedback and the ability to practice with multiple test cases. It also saves time and resources for companies and organizations that use coding challenges as part of their hiring process.

4. Are there any downsides to using a virtual judge problem?

One potential downside of using a virtual judge problem is that it may not accurately simulate real-world coding situations or challenges. Additionally, some programmers may find it less engaging or challenging compared to traditional coding challenges that involve human evaluation and interaction.

5. How can one prepare for a virtual judge problem?

To prepare for a virtual judge problem, it is important to practice coding in a simulated environment and become familiar with the platform that will be used. It is also helpful to study different coding algorithms and techniques and to read and understand the problem statement and requirements carefully before attempting to code a solution.

Similar threads

  • Programming and Computer Science
Replies
29
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
22
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
929
  • Programming and Computer Science
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
17
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
Back
Top