Time Limit Exceeded

Pages: 12
Mar 24, 2020 at 8:34pm
now test 11 is ok but the 3 other are giving errors ; ) jsu tleave it imma figure it out somehow
Mar 24, 2020 at 8:56pm
Why can't you have i=0 or j=0?
Mar 24, 2020 at 9:56pm
Why can't you have i=0 or j=0?

Wouldn't that imply that the distance is 0? -1 is likely used because you can't have negative distance.
Mar 24, 2020 at 10:05pm
hey zapshe can u take a look at this (this one is a serious one i only have 4 hrs to solve it i would be appreciate it ) :



https://cplusplus.com/forum/beginner/269010/
Mar 24, 2020 at 10:06pm
lastchance if u dont mind can u help me with this one ? (just leave this thread imma solve it later somehoe ; ) )
Mar 24, 2020 at 10:08pm
This any better?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;

//======================================================================

bool trial( int &i, int &j, int x, int y, int n )
{
   if ( !x )
   {
      i = 0;
      j = n / y;
      return !( n % y );
   }
   else
   {
      int ip, jp;
      bool result = trial( ip, jp, y % x, x, n );
      j = ip;
      i = jp - j * ( y / x );
      return result;
   }
}

//======================================================================

int hcf( int a, int b ) { return b == 0 ? a : hcf( b, a % b ); }

//======================================================================

int main()
{
   int x, y, n, i, j;

   cin >> n >> x >> y;


   int h = hcf( x, y );
   if ( n % h )
   {
      cout << -1 << '\n';
      return 0;
   }
   n /= h;   x /= h;   y /= h;


   if ( !trial( i, j, x, y, n ) )
   {
      cout << -1 << '\n';
   }
   else
   {
      if      ( j < 0 ) { j += ( i / y ) * x;  i %= y; }
      else if ( i < 0 ) { i += ( j / x ) * y;  j %= x; }
      if ( i >= 0 && j >= 0 ) cout << i << " " << j << '\n';
      else                    cout << -1 << '\n';
   }
}


zapshe wrote:
Wouldn't that imply that the distance is 0?

Pardon?
Last edited on Mar 24, 2020 at 10:09pm
Mar 24, 2020 at 10:12pm
lastchance NJ what u just wrote is beyond me (im a 100 newbie) . can u take a look at this as well :


https://cplusplus.com/forum/beginner/269010/


i only have 4 hrs to solve it

ty in advance
Mar 24, 2020 at 10:13pm
Well, did it work or didn't it?

Would you mind not writing in "text-speak"; I'm too old to understand it.
Last edited on Mar 24, 2020 at 10:14pm
Mar 24, 2020 at 10:14pm
hell yeah it did 100% nj
Topic archived. No new replies allowed.
Pages: 12