This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int N = 3e4 + 5;
pair <int, int> p[N];
int n, m;
int main () {
// freopen ("input.txt", "r", stdin);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> p[i].ff >> p[i].ss;
}
// cout << "men";
// return 0;
if (m == 2) {
int x = abs (p[0].ff - p[1].ff);
if (x % p[0].ss) {
cout << "-1\n";
}
else {
cout << x / p[0].ss << "\n";
}
}
else {
// return 0;
int x = abs (p[0].ff - p[1].ff);
int jogap = 1e9;
if (x % p[0].ss == 0) jogap = x / p[0].ss;
// cout << "men";
int a1 = abs (p[2].ff - p[0].ff);
int a2 = abs (p[2].ff - p[1].ff);
if ((a1 % p[0].ss == 0) and (a2 % p[2].ss == 0)) {
jogap = min (jogap, a1 / p[0].ss + a2 / p[2].ss);
}
if (jogap == 1e9) jogap = -1;
cout << jogap << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |