제출 #1193427

#제출 시각아이디문제언어결과실행 시간메모리
1193427avighnaSnail (NOI18_snail)C++20
11 / 100
1 ms584 KiB
#include <bits/stdc++.h> using int64 = int64_t; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int64 h; int n; std::cin >> h >> n; std::vector<int64> p(n); for (auto &i : p) { std::cin >> i; } std::vector<int64> p_o = p; int64 pos = 0, init = 0; auto output = [&](int64 day) { pos = init; for (int i = 0; i < n; ++i) { if ((pos = std::max(pos + p_o[i], int64(0))) >= h) { return i; } } return -1; }; int64 t = output(0); if (t != -1) { std::cout << 0 << ' ' << t << '\n'; return 0; } if (pos == 0) { std::cout << "-1 -1\n"; return 0; } auto transform = [&p]() { std::vector<int64> p_n; int64 cur = 0; for (int i = 0; i < p.size(); ++i) { if ((cur >= 0 and p[i] >= 0) or (cur <= 0 and p[i] <= 0)) { cur += p[i]; } else { p_n.push_back(cur); cur = p[i]; } } p = p_n; }; auto fix = [&]() { for (int i = 0; i < p.size() - 1; ++i) { if (p[i] <= 0 and p[i + 1] >= 0 and p[i] + p[i + 1] >= 0) { p[i] += p[i + 1]; p.erase(p.begin() + i + 1); i = -1; transform(); } } }; // pos, neg, pos, neg, pos int64 day = 0; while (!p.empty()) { output(day); if (*std::max_element(p.begin(), p.end()) >= h) { std::cout << day << ' ' << output(day) << '\n'; return 0; } if (p[0] >= 0 or p.size() == 1) { day += (h - p[0] + pos - 1) / pos; init += (h - p[0] + pos - 1) / pos * pos; p[0] += (h - p[0] + pos - 1) / pos * pos; } else { int64 del = -(p[0] + p[1]); day += (del + pos - 1) / pos; init += (del + pos - 1) / pos * pos; p[0] += (del + pos - 1) / pos * pos; } } }
#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...