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 rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1e6;
const int inf = 1e9;
void solve() {
int n, m;
cin >> n >> m;
vector<int> x = {-1}, y = {-1};
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
if (sz(x) > 2) {
if (x[sz(x) - 2] == x[sz(x) - 1] && x[sz(x) - 1] == a) x.pop_back();
else if (y[sz(y) - 2] == y[sz(y) - 1] && y[sz(y) -1] == b) y.pop_back();
}
x.push_back(a);
y.push_back(b);
}
n = sz(x) - 1;
if (n & 1) cout << 5 / 0;
if (n <= 4) {
sort(all(y));
if ((y[n] - y[1]) & 1) cout << 0 << ' ';
else cout << m - (m & 1);
return;
}
for (int i = 1; i <= n; i++) {
if (i > 1 && i < n && ((x[i - 1] == x[i] && x[i] == x[i + 1]) || (y[i - 1] == y[i] && y[i] == y[i + 1]))) continue;
if ((y[i] & 1) || (x[i] & 1)) {
cout << x[i] - (x[i] & 1);
return;
}
}
cout << m - (m & 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:33:23: warning: division by zero [-Wdiv-by-zero]
33 | if (n & 1) cout << 5 / 0;
| ~~^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |