Submission #1255003

#TimeUsernameProblemLanguageResultExecution timeMemory
1255003krit3379Feast (NOI19_feast)C++20
4 / 100
1093 ms16856 KiB
#ifdef LOCAL #define DEBUG 1 #else #define DEBUG 0 #endif #include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") const int MOD = 998244353; mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define mid (l+(r-l)/2) using ll = long long; using ld = long double; using str = string; using i128 = __int128; using pii = pair<int,int>; using pll = pair<ll,ll>; using pd = pair<ld,ld>; #define f first #define s second #define cf cout<<flush template <class T> using V = vector<T>; using vi = V<int>; using vvi = V<vi>; using vl = V<ll>; using vvl = V<vl>; using vd = V<ld>; using vpi = V<pii>; using vpl = V<pll>; #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sor(x) sort(all(x)) #define sorr(x) sort(all(x)),reverse(all(x)) #define uniq(x) sor(x), x.resize(unique(all(x))-x.begin()) #define pb push_back #define ft front() #define bk back() #define chmi(x,y, ...) x = min(__VA_OPT__({) x,y __VA_OPT__(,)__VA_ARGS__ __VA_OPT__(})) #define chma(x,y, ...) x = max(__VA_OPT__({) x,y __VA_OPT__(,)__VA_ARGS__ __VA_OPT__(})) #define lwb(x,y) (int)(lower_bound(all(x),y)-x.begin()) #define upb(x,y) (int)(upper_bound(all(x),y)-x.begin()) #define compress(v) {auto _t=v;uniq(_t);for(auto &x:v)x=lwb(_t,x);} #define in(x,y,n,m) (x>=0&&x<n&&y>=0&&y<m) #define retu(args, ...) {ps(args __VA_OPT__(,)__VA_ARGS__);return ;} #define For(i,a,b) for(int i = (a); i <= (b); i++) #define F0r(i,a) for(int i = 0; i < (a); i++) #define Rof(i,a,b) for(int i = (b); i >= (a); i--) #define R0f(i,a) for(int i = (a)-1; i >= 0; i--) #define rep(a) F0r(_,a) #define each(a,x) for(auto &a:x) const int dx[4]{1,0,-1,0},dy[4]{0,1,0,-1}; const int dx8[8]{1,1,0,-1,-1,-1,0,1},dy8[8]{0,1,1,1,0,-1,-1,-1}; template <class T> using pqg = priority_queue<T,vector<T>,greater<T>>; constexpr int pct(int x){return __builtin_popcount(x);} constexpr int pctll(long long x){return __builtin_popcountll(x);} constexpr int bits(int x){return 31-__builtin_clz(x);} #define SFINAE(x, ...) \ template <class, class = void> struct x : std::false_type {}; \ template <class T> struct x<T, std::void_t<__VA_ARGS__>> : std::true_type {} SFINAE(DefaultI, decltype(std::cin >> std::declval<T &>())); SFINAE(DefaultO, decltype(std::cout << std::declval<T &>())); SFINAE(IsTuple, typename std::tuple_size<T>::type); SFINAE(Iterable, decltype(std::begin(std::declval<T>()))); template <auto &is> struct Reader { template <class T> void Impl(T &t) { if constexpr (DefaultI<T>::value) is >> t; else if constexpr (Iterable<T>::value) { for (auto &x : t) Impl(x); } else if constexpr (IsTuple<T>::value) { std::apply([this](auto &...args) { (Impl(args), ...); }, t); } else static_assert(IsTuple<T>::value, "No matching type for read"); } template <class... Ts> void read(Ts &...ts) { ((Impl(ts)), ...); } }; template <class... Ts> void re(Ts &...ts) { Reader<cin>{}.read(ts...); } #define def(t, args...) \ t args; \ re(args); template <auto &os, bool debug, bool print_nd> struct Writer { string comma() const { return debug ? "," : ""; } template <class T> constexpr char Space(const T &) const { return print_nd && (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; } template <class T> void Impl(T const &t) const { if constexpr (DefaultO<T>::value) os << t; else if constexpr (Iterable<T>::value) { if (debug) os << '{'; int i = 0; for (auto &&x : t) ((i++) ? (os << comma() << Space(x), Impl(x)) : Impl(x)); if (debug) os << '}'; } else if constexpr (IsTuple<T>::value) { if (debug) os << '('; std::apply( [this](auto const &...args) { int i = 0; (((i++) ? (os << comma() << " ", Impl(args)) : Impl(args)), ...); }, t); if (debug) os << ')'; } else static_assert(IsTuple<T>::value, "No matching type for print"); } template <class T> void ImplWrapper(T const &t) const { if (debug) os << "\033[0;31m"; Impl(t); if (debug) os << "\033[0m"; } template <class... Ts> void print(Ts const &...ts) const { ((Impl(ts)), ...); } template <class F, class... Ts> void print_with_sep(const std::string &sep, F const &f, Ts const &...ts) const { ImplWrapper(f), ((os << sep, ImplWrapper(ts)), ...), os << '\n'; } void print_with_sep(const std::string &) const { os << '\n'; } }; template <class... Ts> void pr(Ts const &...ts) { Writer<cout, false, true>{}.print(ts...); } template <class... Ts> void ps(Ts const &...ts) { Writer<cout, false, true>{}.print_with_sep(" ", ts...); } template <class... Ts> void psd(Ts const &...ts) { if(DEBUG) Writer<cout, true, true>{}.print_with_sep(" ", ts...); } void setIn(str s) { freopen(s.c_str(), "r", stdin); } void setOut(str s) { freopen(s.c_str(), "w", stdout); } void setIO(str s = "") { cin.tie(0)->sync_with_stdio(0); cout << fixed << setprecision(12); if (sz(s)) setIn(s + ".in"), setOut(s + ".out"); } //#include<atcoder/all> //using namespace atcoder; #define N 200005 void solve(){ def(ll,n,k); vl a(n); re(a); auto sol = [&](ll x) -> pll { V<vpl> dp(2,vpl(n+1,{-1e18,0})); dp[0][0]={0,0}; F0r(i,n){ auto [v0,c0]=dp[0][i]; auto [v1,c1]=dp[1][i]; chma(dp[0][i+1],dp[0][i]); chma(dp[1][i+1],{v0+a[i]-x,c0+1}); chma(dp[0][i+1],dp[1][i]); chma(dp[1][i+1],{v1+a[i],c1}); } return max(dp[0][n],dp[1][n]); }; ll l=0,r=1e18; while(l<r){ auto [v,c]=sol(mid); if(c>=k)l=mid; else r=mid-1; } ps(sol(l).f+l*k); return ; } int main(){ setIO(); int t=1; //re(t); while(t--)solve(); return 0; }

Compilation message (stderr)

feast.cpp: In function 'void setIn(str)':
feast.cpp:147:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  147 | void setIn(str s) { freopen(s.c_str(), "r", stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
feast.cpp: In function 'void setOut(str)':
feast.cpp:148:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  148 | void setOut(str s) { freopen(s.c_str(), "w", stdout); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...