제출 #498336

#제출 시각아이디문제언어결과실행 시간메모리
498336Ierus수열 (APIO14_sequence)C++17
11 / 100
1 ms280 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; #pragma GCC optimize ("unroll-loops,Ofast,O3") #pragma GCC target("avx,avx2,fma") #define F first #define S second #define sz(x) (int)x.size() #define pb push_back #define int long long #define eb emplace_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ; #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long ll; const int E = 1e6+777; const long long inf = 1e18+777; const int N = 2e5+777; const int MOD = 1e9+7; const bool I = 1; int n, pref[N], k; int get(int l, int r){ return pref[r] - (l - 1 < 0 ? 0 : pref[l-1]); } signed main(){ cin >> n >> k; if(n > 10) { cout << 0; return false; } vector<int> a(n); for(int i = 0; i < n; ++i){ cin >> a[i]; if(!i) pref[i] = a[i]; else pref[i] = pref[i-1] + a[i]; } // cerr << "pref\n"; // for(int i = 0; i < n; ++i){ // cerr << pref[i] << ' '; // }cerr << '\n'; int res = -1; vector<int> q; for(int mask = 0; mask < (1 << n); ++mask){ vector<int> r; for(int a = 0; a < n; ++a){ if((mask >> a) & 1){ r.push_back(a); } } if(sz(r) != k) continue; int last = 0, ans = 0; for(int i = 0; i < sz(r); ++i){ ans += get(last, r[i]) * get(r[i] + 1, n-1); last = r[i] + 1; } if(ans > res){ res = ans; q = r; } // for(auto it : r) cerr << it + 1 << ' '; cerr << ans << '\n'; } cout << res << '\n'; for(auto it : q){ cout << it + 1 << ' '; } } /* 7 3 4 1 3 4 0 2 3 */
#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...