제출 #1027824

#제출 시각아이디문제언어결과실행 시간메모리
1027824caterpillowSnail (NOI18_snail)C++17
37 / 100
1 ms680 KiB
#include <bits/stdc++.h> using namespace std; using db = long double; using ll = long long; using pl = pair<ll, ll>; using pi = pair<int, int>; #define vt vector #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define size(x) ((int) (x).size()) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define F0R(i, b) FOR (i, 0, b) #define endl '\n' const ll INF = 1e18; const int inf = 1e9; template<typename Tuple, size_t... Is> void print_tuple(const Tuple& t, index_sequence<Is...>) { ((cerr << (Is == 0 ? "{" : ", ") << get<Is>(t)), ...); cerr << "}"; } template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { print_tuple(t, index_sequence_for<Args...>{}); return os; } ostream& operator<<(ostream& os, string& s) { for (char c : s) os << c; return os; } template<template<typename> class Container, typename T> ostream& operator<<(ostream& os, Container<T> o) { os << "{"; int g = size(o); for (auto i : o) os << i << ((--g) == 0 ? "" : ", "); os << "}"; return os; } template<typename T, typename V> ostream& operator<<(ostream& os, const pair<T, V> p) { os << "{" << p.f << ", " << p.s << "}"; return os; } template <typename T, typename... V> void printer(const char *names, T &&head, V &&...tail) { int i = 0; while (names[i] != '\0' && names[i] != ',') i++; constexpr bool is_str = is_same_v<decay_t<T>, const char*>; if constexpr (is_str) cerr << head; // ignore directly passed strings else cerr.write(names, i) << " = " << head; if constexpr (sizeof...(tail)) cerr << (is_str ? "" : ","), printer(names + i + 1, tail...); else cerr << endl; } #ifdef LOCAL #define dbg(...) std::cerr << __LINE__ << ": ", printer(#__VA_ARGS__, __VA_ARGS__) #else #define dbg(x...) #define cerr if (0) std::cerr #endif /* if you ever touch the ground, you will "restart" from the min point in your pfx sum */ main() { cin.tie(0)->sync_with_stdio(0); ll h, n; cin >> h >> n; vt<ll> a(n), pfx(n); F0R (i, n) cin >> a[i]; F0R (i, n) pfx[i] = a[i] + (i ? pfx[i - 1] : 0); // check if you reach your goal on day 1 ll y = 0; F0R (i, n) { y = max(0ll, y + a[i]); if (y >= h) { cout << "0 " << i << endl; return 0; } } ll day = 1; ll mn = *min_element(all(pfx)); ll mx = *max_element(all(pfx)); if (y + mn <= 0) { // impossible cout << "-1 -1\n"; return 0; } // find first day where you start at a level >= h - mx ll jump = (h - mx - y + pfx.back() - 1) / pfx.back(); y += jump * pfx.back(); day += jump; if (y == h) { cout << day - 1 << " " << n - 1 << endl; return 0; } dbg(y, day); F0R (i, n) { y += a[i]; if (y >= h) { cout << day << " " << i << endl; return 0; } } assert(0); }

컴파일 시 표준 에러 (stderr) 메시지

snail.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main() {
      | ^~~~
#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...