답안 #968263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968263 2024-04-23T09:07:43 Z Pring Line Town (CCO23_day1problem3) C++17
0 / 25
1 ms 2396 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;

const int MXN = 2005, INF = 1e9;
int n, a[MXN];
int alive[MXN];
pii dist[MXN];
int dpl[MXN][MXN], dpr[MXN][MXN];
int L, R;

int prt(int pos, int tg) {
    return ((pos - tg) & 1) ? -1 : 1;
}

void DP(int x) {
    int id = dist[x].sc;
    x++;
    debug(x, id);
    alive[id]--;
    L = 0;
    FOR(i, 0, id) L += alive[i];
    R = 0;
    FOR(i, id + 1, n) R += alive[i];
    FOR(i, 0, x + 1) {
        dpl[i][x - i] = INF;
        dpr[i][x - i] = INF;
    }
    dpl[x][0] = min(dpl[x][0], dpl[x - 1][0] + ((a[id] * prt(id, x - 1)) <= 0 ? L : INF));
    dpr[0][x] = min(dpr[0][x], dpr[0][x - 1] + ((a[id] * prt(id, n - x)) >= 0 ? R : INF));
    FOR(i, 1, x) {
        dpl[i][x - i] = min(dpl[i][x - i], min(dpl[i - 1][x - i], dpr[i - 1][x - i]) + ((a[id] * prt(id, i - 1)) <= 0 ? L : INF));
        dpr[i][x - i] = min(dpr[i][x - i], min(dpl[i][x - i - 1], dpr[i][x - i - 1]) + ((a[id] * prt(id, n - x + i)) >= 0 ? R : INF));
    }
}

void miku() {
    cin >> n;
    FOR(i, 0, n) {
        cin >> a[i];
        dist[i] = mp(abs(a[i]), i);
    }
    sort(dist, dist + n, greater<pii>());
    fill(alive, alive + n, 1);
    FOR(i, 0, n) {
        DP(i);
    }
    // FOR(i, 0, n + 1) {
    //     FOR(j, 0, n + 1 - i) cout << setw(3) << (dpl[i][j] == INF ? -1 : dpl[i][j]) << ' ';
    //     cout << endl;
    // }
    // cout << endl;
    // FOR(i, 0, n + 1) {
    //     FOR(j, 0, n + 1 - i) cout << setw(3) << (dpr[i][j] == INF ? -1 : dpr[i][j]) << ' ';
    //     cout << endl;
    // }
    // cout << endl;
    int ans = INF;
    FOR(i, 0, n + 1) ans = min(ans, dpl[i][n - i]);
    FOR(i, 0, n + 1) ans = min(ans, dpr[i][n - i]);
    cout << ans << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}

Compilation message

Main.cpp: In function 'void DP(int)':
Main.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
Main.cpp:35:5: note: in expansion of macro 'debug'
   35 |     debug(x, id);
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -