Problem p02719 (C++) — buggy submission, verdict: Runtime Error

// Author - Sumit

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx")

#define ll long long
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define F first
#define S second
#define mii map<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int, int>>
#define itr ::iterator it
#define WL(t) while (t--)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define debug(x) cout << x << "\\n";
#define debug2(x, y) cout << x << " " << y << "\\n";
#define debug3(x, y, z) cout << x << " " << y << " " << z << endl;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

template <typename T, typename U> inline void remin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> inline void remax(T &x, U y) {
  if (x < y)
    x = y;
}
template <typename T> T pow(T a, T b, int m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1)
      ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}

void solve() {
  int n, m;
  cin >> n >> m;
  int x = n / m;
  int mm = (x * m);
  int ans = abs(mm - n);
  ans = min(m - ans, ans);
  debug(ans);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  clock_t clk = clock();

  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  cerr << ((long double)(1.00 * clock() - clk) / CLOCKS_PER_SEC) << "\\n";
}

Error: 0
4.9e-05


Fixed submission:

// Author - Sumit

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx")

#define ll long long
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define F first
#define S second
#define mii map<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int, int>>
#define itr ::iterator it
#define WL(t) while (t--)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define debug(x) cout << x << "\\n";
#define debug2(x, y) cout << x << " " << y << "\\n";
#define debug3(x, y, z) cout << x << " " << y << " " << z << endl;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

template <typename T, typename U> inline void remin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> inline void remax(T &x, U y) {
  if (x < y)
    x = y;
}
template <typename T> T pow(T a, T b, int m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1)
      ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}

void solve() {
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    debug(0);
    return;
  }
  m = abs(n - m);
  int x = (n % m);
  x = min(x, m - x);
  debug(x);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  clock_t clk = clock();

  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  cerr << ((long double)(1.00 * clock() - clk) / CLOCKS_PER_SEC) << "\\n";
}