Submission #1116051

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
11160512024-11-21 08:17:29LucaIlieGroup Photo (JOI21_ho_t3)C++17
64 / 100
5056 ms100700 KiB
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000;
int h[MAX_N + 1], p[MAX_N + 1], lower[MAX_N + 1][MAX_N + 1], cost[MAX_N + 1][MAX_N + 1], minCost[MAX_N + 1];
int main() {
int n;
cin >> n;
for ( int i = 1; i <= n; i++ ) {
cin >> h[i];
p[h[i]] = i;
}
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j < i; j++ )
lower[i][h[j]]++;
for ( int j = 1; j <= n; j++ )
lower[i][j] += lower[i][j - 1];
}
for ( int l = 1; l <= n; l++ ) {
for ( int r = l; r <= n; r++ ) {
for ( int i = 1; i <= n; i++ ) {
if ( l <= h[i] && h[i] <= r )
cost[l][r] += lower[i][h[i] - 1] - lower[i][l - 1] + lower[i][n] - lower[i][r];
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...