Submission #1048184

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10481842024-08-08 04:25:24thangdz2k7Line Town (CCO23_day1problem3)C++17
0 / 25
1 ms348 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, a[N], sr[N];
int dp[N][N];
void solve(){
cin >> n;
for (int i = 1; i <= n; ++ i) cin >> a[i], sr[i] = i;
sort(sr + 1, sr + n + 1, [&](int u, int v){
return abs(a[u]) > abs(a[v]);
});
for (int i = 0; i <= n; ++ i) for (int j = 0; j <= n; ++ j) dp[i][j] = 1e9;
dp[0][0] = 0;
for (int i = 0; i < n; ++ i){
int id = sr[i + 1];
//cout << id << endl;
for (int j = 0; j <= i; ++ j){
int l = j + 1;
int r = n - (i - j);
//if (i == 1 && j == 0) cout << l << ' ' << r << ' ' << id << endl;
int tus = ((l ^ id) & 1) ^ (a[id] < 0);
if (a[id] == 0) tus = 1;
if (tus) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + abs(id - l));
tus = ((r ^ id) & 1) ^ (a[id] > 0);
if (a[id] == 0) tus = 1;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...