Bug(?) in Dev C++

Правка en1, от 014-12352-09-Nursultan, 2018-02-19 06:37:12

Hello Codeforces!

I found a bug(?) while I was solving 939B - Hamster Farm, and my code:

1)

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll INF = 1e18 + 1;
main()
{
   	ll n, m, r = 0;
    cin >> n >> m;
    ll x[m + 1];
	double mn = -INF;
    for(int i = 1; i <= m; i ++)
    {
        cin >> x[i];
        if(n % x[i] == 0)
            r = 1;
    }
    double d;
    for(int i = 1; i <= m; i ++)
    {
        if(r == 0)
            mn = max(mn, double(n) / double(x[i]));
        else if(r == 1 && n % x[i] == 0)
            mn = max(mn, n / double(x[i]));
    }
    if(n == 0)
    {
        cout << 1 << " " << 0;
        return 0;
    }
    double u = double(double(n) / mn);
    cout << u << "\n";
    for(int i = 1; i <= m; i ++)
    {
        if(u == double(x[i]))
        {
            cout << i << " ";
            break;
        }
    }
    ll t = mn;
    cout << t;
}
/*
120 7
109 92 38 38 49 38 92


*/

And another one is bit changed.

2)

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll INF = 1e18 + 1;
main()
{
   	ll n, m, r = 0;
    cin >> n >> m;
    ll x[m + 1];
	double mn = -INF;
    for(int i = 1; i <= m; i ++)
    {
        cin >> x[i];
        if(n % x[i] == 0)
            r = 1;
    }
    double d;
    for(int i = 1; i <= m; i ++)
    {
        if(r == 0)
            mn = max(mn, double(n) / double(x[i]));
        else if(r == 1 && n % x[i] == 0)
            mn = max(mn, n / double(x[i]));
    }
    if(n == 0)
    {
        cout << 1 << " " << 0;
        return 0;
    }
    double u = double(double(n) / mn);
    //cout << u << "\n";
    for(int i = 1; i <= m; i ++)
    {
        if(u == double(x[i]))
        {
            cout << i << " ";
            break;
        }
    }
    ll t = mn;
    cout << t;
}
/*
120 7
109 92 38 38 49 38 92


*/

1) Input

28 3
5 6 30

Output

5
1 5

2) Input

28 3
5 6 30

Output

5

How?

Теги bug, devc++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский 014-12352-09-Nursultan 2018-02-19 09:24:29 44 Tiny change: '~~\n\nHow?' -> '~~\n\nHow?\n\n**UPD:** It works only in 32bit compiler'
en3 Английский 014-12352-09-Nursultan 2018-02-19 06:41:26 2 Tiny change: 'n[cut]\n\n1)\n\n' -> 'n[cut]\n\n\n1)\n\n'
en2 Английский 014-12352-09-Nursultan 2018-02-19 06:40:39 9 Tiny change: ' code:\n\n1)\n\n' -> ' code:\n\n[cut]\n\n1)\n\n'
en1 Английский 014-12352-09-Nursultan 2018-02-19 06:37:12 2137 Initial revision (published)