Submission #533632

#TimeUsernameProblemLanguageResultExecution timeMemory
533632CaroLindaTeams (CEOI11_tea)C++14
70 / 100
2581 ms52444 KiB
#include <bits/stdc++.h> #define mk make_pair #define lp(i,a,b) for(int i = a ; i < b; i++ ) #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() using namespace std ; int main(){ ios_base::sync_with_stdio(false ); cin.tie(0) ; int N ; cin >> N ; vector<int> arr(N) , idx(N) ; iota(all(idx) , 0) ; vector<int> corte(N) , mx(N) , tam(N) ; for(auto &e : arr ) cin >> e ; sort(all(idx),[&](int a, int b) { return arr[a] < arr[b] ; }) ; vector<int> dp(N) ; for(int i = 0 ; i < N ; i++){ tam[i] = i+1 ; corte[i] = -1 ; if( i+1 < arr[idx[i]] ){ dp[i] = mx[i] = 0 ; if(i) mx[i] = max(mx[i] , mx[i-1]) ; } else{ dp[i] = mx[i] = max(1, mx[i-arr[idx[i]]]+1) ; if(i) mx[i] = max(mx[i] , mx[i-1]) ; } } vector<vector<int> > sweep(N+1, vector<int>()) ; for(int i = 0 ; i < N ; i++ ) sweep[dp[i]].push_back(i) ; for(int i = 1 ; i <= N ; i++ ){ sort(all(sweep[i]) , [&](int a, int b){ return a-arr[idx[a]] < b-arr[idx[b]] ; }) ; } auto getPair = [&](int x){ return make_pair( tam[x]+x , x-tam[x] ) ; } ; vector<pair<int,int> > vec ; vector<int> indices ; for(int i = 2 ; i <= N ; i++ ){ int ptr = 0 ; sort(all(sweep[i-1])) ; vec.clear() ; indices.clear() ; for(auto e : sweep[i] ) { while(ptr < sz(sweep[i-1]) && sweep[i-1][ptr] <= e-arr[idx[e]] ){ indices.push_back(sweep[i-1][ptr]) ; vec.push_back(getPair(sweep[i-1][ptr++])) ; } tam[e] = N*2 ; for(int a = 0 ; a < sz(vec) ; a++){ pair<int,int> p = vec[a] ; int dx = abs(p.first-e) ; int dy = abs(p.second-e) ; if( ((dx+dy)>>1) < tam[e]){ tam[e] = (dx+dy)>>1 ; corte[e] = indices[a] ; } } } } vector<vector<int> > ans ; int x = N-1 ; while(x != -1){ ans.push_back(vector<int>()) ; for(int i = corte[x]+1 ; i <= x ; i++ ) ans.back().push_back(idx[i]+1) ; x = corte[x] ; } cout << sz(ans) <<"\n" ; for(auto e : ans ){ cout << sz(e) <<" " ; for(auto ee : e ) cout << ee <<" " ; cout << "\n" ; } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...