# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527778 | boris_mihov | Diamond Hands (innopolis2021_final_B) | C++14 | 45 ms | 5388 KiB |
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 <iostream>
#include <vector>
const int maxn = 2e5+10;
int n;
std::pair < int, int > d[maxn];
std::vector < std::pair < int, char > > ans;
void invalid() {
std::cout << -1 << '\n';
exit(0);
}
void solve() {
for (int i = 1 ; i <= n ; ++i) {
int diff = d[i].first - d[i-1].first;
int desired = d[i].second - d[i-1].second;
if (!(-diff <= desired && desired <= diff && (diff - desired) % 2 == 0)) invalid();
if (desired == diff) {
if (i == 2 && ans.size() == 2) swap(ans.front(), ans.back());
if (!ans.empty() && ans.back().second == '+') ans.back().first += diff;
else ans.push_back({diff, '+'});
continue;
}
if (desired == -diff) {
if (!ans.empty() && ans.back().second == '-') ans.back().first += diff;
else ans.push_back({diff, '-'});
continue;
}
int subtract = (diff - desired) / 2;
int add = diff - subtract;
if (i == 1) {
ans.push_back({add, '+'});
ans.push_back({subtract, '-'});
continue;
}
if (ans.back().second == '+') {
ans.back().first += add;
ans.push_back({subtract, '-'});
continue;
}
ans.back().first += subtract;
ans.push_back({add, '+'});
}
std::cout << ans.size() << '\n';
for (int i = 0 ; i < ans.size() ; ++i)
std::cout << ans[i].first << ' ' << ans[i].second << '\n';
}
void read() {
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
std::cin >> d[i].first >> d[i].second;
}
void fast_io() {
std::ios_base :: sync_with_stdio(0);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
}
int t;
int main () {
fast_io();
read();
solve();
return 0;
}
Compilation message (stderr)
# | 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... |