Submission #527778

#TimeUsernameProblemLanguageResultExecution timeMemory
527778boris_mihov Diamond Hands (innopolis2021_final_B)C++14
24 / 100
45 ms5388 KiB
#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)

Main.cpp: In function 'void solve()':
Main.cpp:66:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0 ; i < ans.size() ; ++i)
      |                      ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...