제출 #704646

#제출 시각아이디문제언어결과실행 시간메모리
704646Alihan_8수열 (APIO14_sequence)C++17
0 / 100
9 ms1620 KiB
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector <int> p(n); for ( auto &i: p ) cin >> i; priority_queue <tuple<pair<int,int>,int,int>> q; auto f = [&](int l, int r){ int pref = 0, cnt = 0, it = 0, Mx = 0; for ( int i = l; i <= r; i++ ) pref += p[i]; for ( int i = l; i <= r; i++ ){ cnt += p[i]; if ( Mx < (pref-cnt)*cnt ){ Mx = (pref-cnt)*cnt; it = i; } } pair <int,int> ans = {Mx, it}; return ans; }; q.push({f(0, n-1), 0, n-1}); int cnt = 0; vector <int> res; while ( !q.empty() and k > 0 ){ auto [val, L, R] = q.top(); q.pop(); if ( L >= R ) continue; auto [Mx, it] = val; res.pb(it); cnt += Mx; k--; q.push({f(L, it), L, it}); q.push({f(it+1, R), it+1, R}); } cout << cnt << ln; for ( auto i: res ) cout << ++i << ' '; cout << '\n'; } /* 7 3 4 1 3 4 0 2 3 */

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

sequence.cpp: In function 'void IO(std::string)':
sequence.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").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...