提出 #23721015


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 998244353
#define maxn 4010

ll i, i1, j, k, k1, t, n, m, res, flag[10], a[maxn], b[maxn], dp[maxn][maxn];
ll ps[maxn][2][2010], ty, f[2][maxn];
char c;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    cin >> n;
    for (i = 1; i <= 2 * n; i++) {
        cin >> c >> b[i]; a[i] = (c == 'W');
        f[a[i]][b[i]] = i;
    }

    for (i = 2 * n; i >= 1; i--) {
        for (ty = 0; ty <= 1; ty++) {
            for (j = 1; j <= n; j++) {
                ps[i][ty][j] = ps[i + 1][ty][j];
            }
        }
        ps[i][a[i]][b[i]]++;
    }

    for (i = 1; i <= 2 * n; i++) {
        for (ty = 0; ty <= 1; ty++) {
            for (j = 1; j <= n; j++) {
                ps[i][ty][j] += ps[i][ty][j - 1];
            }
        }
    }

    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dp[i][j] = INF;
            if (i + j == 0) dp[i][j] = 0;
            if (i != 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + ps[f[0][i]][0][i - 1] + ps[f[0][i]][1][j]);
            if (j != 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + ps[f[1][j]][0][i] + ps[f[1][j]][1][j - 1]);
        }
    }

    cout << dp[n][n] << nl;

    return 0;
}

提出情報

提出日時
問題 E - Sorted and Sorted
ユーザ TheScrasse
言語 C++ (GCC 9.2.1)
得点 600
コード長 1521 Byte
結果 AC
実行時間 211 ms
メモリ 168500 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 36
セット名 テストケース
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt
ケース名 結果 実行時間 メモリ
0_000.txt AC 8 ms 3592 KiB
0_001.txt AC 2 ms 3608 KiB
0_002.txt AC 4 ms 3628 KiB
1_003.txt AC 2 ms 3592 KiB
1_004.txt AC 3 ms 3560 KiB
1_005.txt AC 2 ms 3696 KiB
1_006.txt AC 2 ms 3676 KiB
1_007.txt AC 2 ms 3740 KiB
1_008.txt AC 2 ms 3716 KiB
1_009.txt AC 2 ms 3596 KiB
1_010.txt AC 2 ms 3564 KiB
1_011.txt AC 2 ms 3612 KiB
1_012.txt AC 2 ms 3548 KiB
1_013.txt AC 2 ms 3496 KiB
1_014.txt AC 180 ms 146072 KiB
1_015.txt AC 32 ms 34788 KiB
1_016.txt AC 139 ms 123396 KiB
1_017.txt AC 67 ms 60252 KiB
1_018.txt AC 4 ms 5968 KiB
1_019.txt AC 24 ms 26820 KiB
1_020.txt AC 158 ms 134940 KiB
1_021.txt AC 74 ms 65552 KiB
1_022.txt AC 41 ms 39808 KiB
1_023.txt AC 136 ms 124272 KiB
1_024.txt AC 195 ms 164756 KiB
1_025.txt AC 210 ms 168468 KiB
1_026.txt AC 207 ms 168388 KiB
1_027.txt AC 207 ms 168484 KiB
1_028.txt AC 207 ms 168472 KiB
1_029.txt AC 210 ms 168500 KiB
1_030.txt AC 211 ms 168500 KiB
1_031.txt AC 205 ms 168456 KiB
1_032.txt AC 202 ms 168408 KiB
1_033.txt AC 199 ms 168492 KiB
1_034.txt AC 205 ms 168480 KiB
1_035.txt AC 201 ms 168480 KiB