有人可以告诉我为什么这个代码不被接受?注意:我不是要求解决方案,只是告诉我这段代码失败的地方 [英] Can someone please tell me why is this code not being accepted? Note:I am not asking for a solution, just tell me where this code fails

查看:97
本文介绍了有人可以告诉我为什么这个代码不被接受?注意:我不是要求解决方案,只是告诉我这段代码失败的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比赛页面| CodeChef [ ^ ]

约束:>

所有元素都是> = 1,即a [i]> = 1和(10> = t> = 1)和(700> = n> = 1)



我尝试过的事情:



i几乎尝试了所有类型的测试用例,所有都是正确的,我无法识别我的代码失败的地方。

Contest Page | CodeChef[^]
Constraints:>
All elements are >=1 i.e. a[i]>=1 and (10>=t>=1) and (700>=n>=1)

What I have tried:

i have tried almost all types of test cases i could possibly do, all come out correct and i am unable to recognize where my code is failing.

#include<stdio.h>
int main()
{
    long long int n, t, k, i, j, max[701], a[701][701], sum, flag;
 
    scanf( "%lld", &t );

    for( k = 0 ; k < t ; k++ )
    { 
        scanf( "%lld", &n );

        for( i = 0 ; i < n ; i++ )
        {  
            for( j = 0 ; j < n ; j++ )
            { 
                scanf( "%lld", &a[i][j] );
                if( j == 0)
                    max[i] = a[i][0];
                if( a[i][j] > max[i] )
                    max[i] = a[i][j];
            }
        }

        sum = 0, flag = 0;

        for( i = 0 ; i < n-1 ; i++ )
        { 
            if( max[i] < max[i+1])
                sum = sum + max[i];
            else
            {
                flag = 1;
                break;
            }
        }

        if(flag == 1)
            printf("-1\n");
        else
        {
            sum = sum + max[n-1];
            printf("%lld\n", sum );
        }
    }
}

推荐答案

引用:

有人可以告诉我为什么这段代码不被接受?注意:我不是要求解决方案,只是告诉我这段代码失败的地方

Can someone please tell me why is this code not being accepted? Note:I am not asking for a solution, just tell me where this code fails



你的问题是你的代码是另一个问题的正确答案。

你计算每条线的最大值然后加上最大值,同时检查它们是否尊重次要约束。



你有一个目标:


Your problem is that your code is the correct answer to another question.
you compute the maximum of each lines and then add the maximums while checking they respect the secondary constraint.

You have a goal:

Compute the maximum possible value of E1 + E2 + ... + EN. If it's impossible to pick the elements E1, E2, ..., EN, print -1 instead.



和约束:


and a constraint:

You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1.



您从未被告知使用每行的最大值。

你必须使用尊重约束的最大值。




You have never been told to use the maximum of each line.
You have to use the maximum value that respect the constraint.

Input:
1
3
 6 2 3
11 5 6
 7 8 9

Output:
3 + 6 + 9 = 18





[更新]

你必须明白完整的解释意味着你没有参加比赛。



[Update]
You must understand that a full explanation means that you failed the contest.

You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1.



约束的构造方式意味着计算每行的最大允许顺序相反。

出于实际考虑,您必须将约束反转为:


The constraint is constructed in such a way that it imply to compute the maximum allowed of each line in reverse order.
For practical considerations, you must reverse the constrain to:

For each i (1 ≤ i ≤ N-1), Ei should be strictly lower than Ei+1.



最后一行没有约束。


And last line have no constraint.

Input:
1
3
 6 2 3
11 5 6
 7 8 9



求解:


Solving:

 7 8 9: no constraint,  7 8 9 qualified, maximum is 9.
11 5 6: constraint is < 9,  5 6 qualified, maximum is 6.
 6 2 3: constraint is < 6, 2 3 qualified, maximum is 3.
output is: 9+6+3=18




1
3
6 10 12
8 15 7
8 19 10



求解:


Solving:

8 19 10: no constraint, 8 19 10 qualified, maximum is 19.
8 15 7: constraint is < 19,  8 15 7 qualified, maximum is 15.
6 10 12: constraint is < 15, 6 10 12 qualified, maximum is 12.
output is: 19+15+12=46


1
3
6 10 12
4 5 7
8 9 10
-1



输出应为6 + 7 + 10 = 23


ouput should be 6+7+10=23


这篇关于有人可以告诉我为什么这个代码不被接受?注意:我不是要求解决方案,只是告诉我这段代码失败的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆