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>
#include "trilib.h"
using namespace std;
int n;
vector<int> up, dn;
void solve() {
n = get_n();
for (int i = 3; i <= n; i++) {
if (is_clockwise(1, 2, i)) dn.push_back(i);
else up.push_back(i);
}
sort(up.begin(), up.end(), [](int i, int j){ return is_clockwise(i, 1, j); });
sort(dn.begin(), dn.end(), [](int i, int j){ return !is_clockwise(i, 1, j); });
stack<int> stk;
deque<int> dq;
dq.push_back(1);
dq.push_back(2);
for (int i = 0; i < up.size(); i++) {
int a = dq.back(); dq.pop_back();
while (dq.size() >= 1 && is_clockwise(dq.back(), a, up[i])) {
a = dq.back(); dq.pop_back();
}
dq.push_back(a);
dq.push_back(up[i]);
}
dq.pop_front();
dq.push_back(1);
stk.push(1);
stk.push(2);
for (int i = 0; i < dn.size(); i++) {
int a = stk.top(); stk.pop();
while (stk.size() >= 1 && !is_clockwise(stk.top(), a, dn[i])) {
a = stk.top(); stk.pop();
}
stk.push(a);
stk.push(dn[i]);
}
while (stk.size() > 2) {
int v = stk.top();
stk.pop();
int a = dq.back(); dq.pop_back();
while (dq.size() >= 1 && is_clockwise(dq.back(), a, v)) {
a = dq.back(); dq.pop_back();
}
dq.push_back(a);
dq.push_back(v);
}
while (dq.size() > 2) {
int a = dq.front(); dq.pop_front();
if (is_clockwise(dq.back(), a, dq.front())) continue;
dq.push_front(a);
a = dq.back(); dq.pop_back();
if (is_clockwise(dq.back(), a, dq.front())) continue;
dq.push_back(a);
break;
}
give_answer(dq.size());
}
int main() {
solve();
}
Compilation message (stderr)
tri.cpp: In function 'void solve()':
tri.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < up.size(); i++) {
| ~~^~~~~~~~~~~
tri.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 0; i < dn.size(); i++) {
| ~~^~~~~~~~~~~
# | 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... |