c++中tle是什么意思_如何在竞争性编程中克服TLE?

c++中tle是什么意思

什么是TLE? (What is TLE?)

TLE means "Time Limit Exceed". So, in competitive programming, there are some constraints with a specific time limit (normally for each input 1 sec) and your task is to write your code in such a way that all test cases are passed within that time limit for each input.

TLE的意思是“超过时间限制” 。 因此,在竞争性编程中,存在一些特定时间限制的约束(通常每个输入1秒钟),您的任务是编写代码,使所有测试用例均在该时间限制内通过每个输入。

If it does not, then obviously you will get TLE (if there is no compiler or runtime error).

如果没有,那么显然您将获得TLE (如果没有编译器或运行时错误)。

The main problem in TLE is, you will not be able to know whether your code is generating the right output or not.

TLE中的主要问题是,您将无法知道代码是否生成正确的输出。

Because they first check your compiler error (if any) then runtime error (if any), then TLE (if any) and at last right or wrong answer your code is generating.

因为他们首先检查您的编译器错误(如果有),然后是运行时错误(如果有),然后是TLE (如果有),最后是您生成的代码的正确或错误答案。

为什么TLE来? (Why TLE comes?)

There might be various reasons behind it that your TLE is coming. Some of the important reasons are:

TLE即将到来可能有多种原因。 一些重要的原因是:

1) Online Judge:

1)在线评委:

This is the main reason you can say. An online judge ( like codechef, hackerrank , hackerearth, etc) gives TLE on a question because there are some restrictions in each input with a specific time limit. If your program exceeds that time limit you will get TLE.

这是您可以说的主要原因。 一位在线法官(例如codechef,hackerrank,hackerearth等)对TLE进行提问,因为每个输入都有特定的时间限制。 如果您的程序超过了该时间限制,您将获得TLE。

2) Reading input and output slowly:

2)缓慢读取输入和输出:

Sometimes your code takes input slowly ( though you are responsible for that:). However, if you use Fast Input-Output method (FastIO) your program always runs faster.

有时,您的代码输入很慢(尽管您对此负责)。 但是,如果您使用快速输入输出方法(FastIO),则程序始终会运行得更快。

To add fast IO in your code you have to write the following lines in main() in your code:

要在代码中添加快速IO,您必须在代码的main()中编写以下几行:

C / C++

C / C ++

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL) ;

Python

Python

    import psyco
    psyco.full()

Java Do not use Scanner class, use BufferedReader instead.

Java不要使用Scanner类,而应使用BufferedReader 。

3) Server Configuration

3)服务器配置

Sometimes, the server takes time to run your code. So, it might depend on their CPU, OS, etc. For this reason, the different platform gives you TLE in different cases.

有时,服务器需要一些时间来运行您的代码。 因此,这可能取决于其CPU,操作系统等。因此,不同的平台会在不同情况下为您提供TLE。

4) Bound of loops

4)循环界限

This is one of the main reason for competitive programming for getting TLE.

这是获得TLE竞争性编程的主要原因之一。

Suppose you are given a time limit of 1 sec for a value N. So you can run a loop at max range 10^7. Below table defines the complexity and value of N what should be for a time limit of 1 sec:

假设您为N设置了1秒的时间限制。因此,您可以在最大范围10 ^ 7处运行循环。 下表定义了N的复杂度和值,在1秒的时间限制内应该是:

Max value of NSuggested Max Complexity to overcome TLE
10^2O(N^3)
10^3O(N^2)
10^5O(N * log (N))
10^6O(N) [Perfectly accepted]
10^7O(N) [ Use FastIO]
10^8O(N) [ Border case ]
10^9log (N) or sqrt(N)
N的最大值 建议的最大复杂度以克服TLE
10 ^ 2 O(N ^ 3)
10 ^ 3 O(N ^ 2)
10 ^ 5 O(N *对数(N))
10 ^ 6 O(N)[完全接受]
10 ^ 7 O(N)[使用FastIO]
10 ^ 8 O(N)[边境案件]
10 ^ 9 对数(N)或sqrt(N)

Please Note that, a loop value (N) cannot be greater than 10^9 if N is an integer. Because an integer can take up to 10^9.

请注意,如果N为整数,则循环值(N)不能大于10 ^ 9。 因为整数最多可以占用10 ^ 9。

So, if you get TLE in any question always refer to the above table and try to optimize your solution. A program can be done in various ways and using various algorithms. Also always use FastIO for each problem you are solving.

因此,如果您在任何问题上都获得TLE,请始终参考上表并尝试优化您的解决方案。 可以通过各种方式和使用各种算法来完成程序。 对于要解决的每个问题,也请始终使用FastIO。

All the best for your coding life.

祝您编程生活一切顺利。

翻译自: https://www.includehelp.com/icp/how-to-overcome-tle-in-competitive-programming.aspx

c++中tle是什么意思

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值