Submission #739270

#TimeUsernameProblemLanguageResultExecution timeMemory
739270vjudge1Split the sequence (APIO14_sequence)C++17
0 / 100
45 ms84368 KiB
#include <bits/stdc++.h> #include <math.h> //in the name of god,aka allah //** har vaght m2 ghabool shodi javabetoo midam (radal) ** #pragma GCC optimize("unroll-loops") using namespace std; #define pi pair<ll , ll> #define pii pair<long long , pair<long long , long long>> const int maxm = 5e5 + 6; const long long mod = 998244353; typedef long long ll; #define pb push_back #define fi first #define se second ll l,r,mid; ll n,m; ll dis[maxm] , sum[maxm]; bool isval(int mid){ //cout << mid <<" " << mid*mid-mid <<endl; if (((mid-1)*mid)/2 < m) return 0; return 1; } ll darage[maxm] , ss , mm; queue<int> q; vector<ll> g[maxm] , z[maxm]; ll sath[maxm]; bool vis[maxm] , gos[maxm]; ll pedaret[maxm]; ll get_par(ll v){ if (pedaret[v]==v) return v; return pedaret[v] = get_par(pedaret[v]); } void merge(ll r , ll q){ if (get_par(r)!=get_par(q))l+=max(darage[r],darage[q])*1ll*sath[r]*1ll*sath[q]; r = get_par(r) , q = get_par(q); if (r!=q){ if (sath[r]<sath[q]) swap(r,q); pedaret[q] = r; sath[r] += sath[q]; } return ; } ll pars1[maxm] , pars2[maxm]; vector<ll> se[maxm]; set<ll> st , wtf , ajab; ll rp[maxm]; pi w[maxm],ww[maxm]; //ll rw[maxm][maxm]; set<ll> ts[maxm] , jav[maxm]; ll rgh[maxm] , lft[maxm]; ll pw(ll x , ll y){ ll ans = 1 , ok = x; while (y){ if (y%2) ans *= ok; ans %= mod; ok *= ok; ok %= mod; y/=2; } return ans; } ll fact[5005] , rev[5005]; ll c(ll x , ll y){ if (y>x) return 0; if (y==x) return 1ll; if (!y) return 1ll; return (fact[x] * rev[y] % mod) * rev[x-y] % mod; } ll mx(vector<int> vec){ ll ans = 0; for (auto x : vec) ans+=pedaret[x]; ll ko = 0 , ok = 0; for (auto x : vec) ko += pedaret[x] , ok = max(ok , ko * (ans-ko)); return ok; } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >>n>>m; for (int i=1; i<=n; i++) cin >> pedaret[i]; vis[n] = 1; vis[n] = 1 , vis[0] = 1; vector<int> ans; for (int t=1; t<=m; t++){ vector<int> vec; r = 0; l = 0; for (int i=1; i<=n; i++){ if (vis[i]){ vec.pb(i); ll f = mx(vec); if (f>r){ r = f; ll sum = 0; for (auto x : vec) sum+=pedaret[x]; ll ok = 0 , ko = 0; for (auto x : vec){ ko += pedaret[x]; if (ko * (sum-ko)==f) l = x; } } vec.clear(); } else vec.pb(i); } ans.pb(l); vis[l] = 1; mid += r; } cout<<mid<<endl; for (auto x : ans) cout<<x<<" "; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:95:24: warning: unused variable 'ok' [-Wunused-variable]
   95 |                     ll ok = 0 , ko = 0;
      |                        ^~
#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...