Submission #3422131


Source Code Expand

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int rn = uniform_int_distribution<int>(0, MAXN)(rng);

    int n,x,y;
    char s;
    cin>>n;
    pii a[2*n];
    int b[2][n+1][n+1] , z[2][n+1];
    MEM(b,0); MEM(z,0);

    REP(i,2*n) {
        cin>>s>>y;
        if(s == 'W') x = 0;
        else x = 1;
        a[i] = MP(x,y);
    }

    REP(i,2*n) {
        REP(j,i) {
            if(a[j].x == a[i].x && a[j].y > a[i].y) z[a[i].x][a[i].y] += 1;
            else if(a[j].x != a[i].x) {
                b[a[i].x][a[i].y][a[j].y] += 1;
            }
        }
        REP(j,n+1) if(j) b[a[i].x][a[i].y][j] += b[a[i].x][a[i].y][j-1];
    }

    int dp[n][n];
    dp[0][0] = 0;
    FOR(i,1,n) dp[i][0] = dp[i-1][0] + z[0][i] + b[0][i][n];
    FOR(j,1,n) dp[0][j] = dp[0][j-1] + z[1][j] + b[1][j][n];
    
    FOR(i,1,n) {
        FOR(j,1,n) {
            int p = dp[i-1][j] + z[0][i] + b[0][i][n] - b[0][i][j];
            int q = dp[i][j-1] + z[1][j] + b[1][j][n] - b[1][j][i];
            dp[i][j] = min(p, q);
        }
    }
    
    cout<<dp[n][n];
    return 0;
}




Submission Info

Submission Time
Task E - Sorted and Sorted
User alokpatra1998
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2374 Byte
Status WA
Exec Time 108 ms
Memory 47232 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 23
WA × 13
Set Name Test Cases
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
Case Name Status Exec Time Memory
0_000.txt AC 2 ms 384 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 1 ms 256 KB
1_009.txt AC 1 ms 256 KB
1_010.txt AC 1 ms 256 KB
1_011.txt WA 1 ms 256 KB
1_012.txt AC 1 ms 256 KB
1_013.txt WA 1 ms 256 KB
1_014.txt AC 84 ms 36992 KB
1_015.txt AC 12 ms 5632 KB
1_016.txt WA 58 ms 27520 KB
1_017.txt AC 25 ms 11520 KB
1_018.txt WA 1 ms 384 KB
1_019.txt WA 8 ms 3968 KB
1_020.txt WA 72 ms 32128 KB
1_021.txt AC 20 ms 12800 KB
1_022.txt WA 10 ms 6784 KB
1_023.txt AC 40 ms 27776 KB
1_024.txt WA 73 ms 45440 KB
1_025.txt WA 106 ms 47232 KB
1_026.txt AC 106 ms 47232 KB
1_027.txt AC 108 ms 47232 KB
1_028.txt AC 106 ms 47232 KB
1_029.txt AC 106 ms 47232 KB
1_030.txt WA 107 ms 47232 KB
1_031.txt WA 106 ms 47232 KB
1_032.txt AC 75 ms 47232 KB
1_033.txt WA 80 ms 47232 KB
1_034.txt AC 73 ms 47232 KB
1_035.txt WA 76 ms 47232 KB