ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1264. Workdays

TLE
Posted by Ehsan Raeyatpisheh 7 Jun 2015 11:32
I'm getting time limit exceeded using this algorithm, any optimization suggestions? This problem is taking almost a week 8-|

total = 0
for i from 1 to N
  for j from 0 to M
    total++
print total

Edited by author 07.06.2015 11:34
Re: TLE
Posted by Md. Shahedul Islam (Shahed) 8 Jun 2015 22:42
why using loop, just simply, we have N element array.
And we have (M+1) integers, as numaration starts form 0 to M.
so, (M+1) integers will be checked in every element of the array.
as, there's N elements in the array, so, final result is N*(M+1).  :)
------------------------------------
#include <iostream>
using namespace std;

int main()
{
    int n, m;

    cin >> n >> m;

    cout << n * (m + 1) << '\n';

    return 0;
}
---------------------------------------

Edited by author 08.06.2015 22:43