제출 #1261510

#제출 시각아이디문제언어결과실행 시간메모리
1261510namhhGroup Photo (JOI21_ho_t3)C++20
100 / 100
185 ms67488 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fi first #define se second const int N = 5e3+5; int n,a[N],rem[N],dp[N],emilia[N][N]; // ga qua phai chef code huhu :< int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; rem[a[i]] = i; } for(int i = 2; i <= n; i++){ int dem = 0; for(int j = i-1; j >= 1; j--){ if(rem[i] < rem[j]) ++dem; emilia[j][i] = emilia[j][i-1]+dem; } } for(int i = 2; i <= n; i++) dp[i] = 1e9; for(int i = 2; i <= n; i++){ for(int j = i-1; j >= 0; j--){ int cr = emilia[1][i]-emilia[1][j]-emilia[j+1][i]; int cost = ((i-j)*(i-j-1))/2-emilia[j+1][i]; dp[i] = min(dp[i],dp[j]+cr+cost); } } cout << dp[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...