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 N | Suggested Max Complexity to overcome TLE |
---|---|
10^2 | O(N^3) |
10^3 | O(N^2) |
10^5 | O(N * log (N)) |
10^6 | O(N) [Perfectly accepted] |
10^7 | O(N) [ Use FastIO] |
10^8 | O(N) [ Border case ] |
10^9 | log (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是什么意思