Reduce execution time
Date : March 29 2020, 07:55 AM
around this issue As the different types of elements that you can have is really small, you can easily use a simple array instead of a hashset(an approach similar to set or counting sort). If you only care for the non-capital English letters declare an array boolean met[26];, if you need to be able to support all characters use an boolean met[256];. Than iterate over the array and only add a character to the result if its met value is false. When adding the character to the result don't forget to mark it as used. boolean met[] = new boolean[256]; // Replace 256 with the size of alphabet you are using
List<Character> res = new ArrayList<Character>();
for(Character c:data){
int int_val = (int)c.charValue();
if (!met[int_val]) {
met[int_val] = true;
res.add(c);
}
}
// res holds the answer.
|
how to reduce execution time
Tag : cpp , By : Matt Watson
Date : March 29 2020, 07:55 AM
I hope this helps you . Currently the following problem is taking 3.008** seconds to execute for some testcase provided on hackerearth.com where allowed time is 3.0 seconds so i get time limit error. Please help to reduce execution time. , I believe this should get the job done (idea from @zch's answer): #include <iostream>
#include <cmath>
auto MAX = [] (int A, int B) -> bool { return A > B ? A : B; };
auto MIN = [] (int A, int B) -> bool { return A < B ? A : B; };
using std::cout;
using std::cin;
int main() {
long long Z, M, N, T, low, high, temp, div;
int ans;
for (cin >> T; T--; ) {
cin >> Z >> M >> N;
temp = MIN(M, N);
low = MIN(sqrt(Z), temp);
high = MAX(M, N);
for( ans = 0; low > 0 && (Z / low) <= high; --low ) {
if ( Z % low == 0) {
++ans;
div = Z / low;
ans += (div != low && div <= temp);
}
//cout << temp << " * " << Z / temp << " = " << Z << "\n";
}
cout << ans << "\n";
}
return 0;
}
#include <iostream>
#include <cmath>
auto MAX = [] (int A, int B) -> bool { return A > B ? A : B; };
auto MIN = [] (int A, int B) -> bool { return A < B ? A : B; };
using std::cout;
using std::cin;
int main() {
long long Z, M, N, T, low, high, temp, div;
int ans;
for (cin >> T; T--; ) {
cin >> Z >> M >> N;
temp = MIN(M, N);
low = MIN(sqrt(Z), temp);//Lowest value <--We start iteration from this number
high = MAX(M, N); //Maximum value
for( ans = 0; low > 0 && (Z / low) <= high; --low ) {
//Number of things going on in this for-loop
//I will start by explaining the condition:
//We want to keep iterating until either low is below 1
// or when the expression (Z / low) > high.
//Notice that as the value of low approaches 0,
//the expression (Z / low) approaches inf
if ( Z % low == 0) {
//If this condition evaluates to true, we know 2 things:
/*Z is divisible by this value of low and
low is in the range of MIN(M,N) <--true*/
/*Because of our condition, (Z / low) is
within the range of MAX(M, N) <--true*/
++ans;
div = Z / low;
//This second part checks if the opposite is true i.e.
/*the value of low is in the range of
MAX(M, N) <--true*/
/*the value (Z / low) is in the range of
MIN(M, N) <--true only in some cases*/
ans += (div != low && div <= temp);
//(div != low) is to avoid double counting
/*An example of this is when Z, M, N have the values:
1000000, 1000000, 1000000
The value of low at the start is 1000 */
}
}
cout << ans << "\n";
}
return 0;
}
|
Reduce PHP execution time
Date : March 29 2020, 07:55 AM
it fixes the issue You should not rely on the third-party web-site for building your own content. They could even block you if your server makes too many requests; when several visitors open the page around the same time for example. Instead, you should schedule a background job (using cron on Linux or task scheduler on Windows) to periodically get the records (or only updated ones if possible) and add / replace these in your own database.
|
How to Reduce Execution Time
Tag : sql , By : user121350
Date : March 29 2020, 07:55 AM
hop of those help? It's just my startup in SQL, I have 4.5 GB database from that I am trying to select records from specific dates and its 25 seconds execute. Is there a way to make it faster? , You can try query like this: SELECT a.*,
b.ModelName
FROM Scan_Data_For_Century sd
INNER JOIN Validation a
ON a.STB = sd.STB AND a.date between '2015-01-14' and '2015-01-14'
LEFT JOIN ModelMaster b
ON SUBSTRING(a.STB,11,2) = b.ProductCode AND Convert(int,substring(a.STB,9,2)) = b.BrandCode
|
How to increase the execution speed and reduce execution time of a social website like 'Facebook' developed in PHPFox?
Tag : php , By : Funkwarrior
Date : March 29 2020, 07:55 AM
|