Submission #7423

# Submission time Handle Problem Language Result Execution time Memory
7423 2014-08-05T06:20:40 Z mrcamel 배열 탈출 (GA8_array) C++
0 / 100
0 ms 65536 KB
#include <iostream>
#include <cstdio>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

#define in cin
#define out cout

struct RR
{
    int w, cost;
};
RR room[3000][3000];

int main()
{
    int n; scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            scanf("%d", &room[i][j].w);
            room[i][j].cost = 0;
        }
    }
    for(int i=0; i<=n; i++)
    {
        room[0][i].w = 300;
        room[i][0].w = 300;
    }

    //
    for(int i=2; i<=n; i++)
    {
        if(room[1][i-1].w <= room[1][i].w)
            room[1][i].cost = room[1][i].w - room[1][i-1].w + 1;
        if(room[i-1][1].w <= room[i][1].w)
            room[i][1].cost = room[i][1].w - room[i-1][1].w + 1;

        room[1][i].cost += room[1][i-1].cost;
        room[i][1].cost += room[i-1][1].cost;
    }

    for(int i=2; i<=n; i++)
    {
        for(int j=2; j<=n; j++)
        {
            RR &r0 = room[i][j];
            RR &r1 = room[i-1][j];
            RR &r2 = room[i][j-1];

            int r1c = 0;
            int r2c = 0;

            if(r0.w >= r1.w) r1c = r0.w - r1.w + 1;
            r1c += r1.cost;
            if(r0.w >= r2.w) r2c = r0.w - r2.w + 1;
            r2c += r2.cost;

            if(r1c < r2c) r0.cost = r1c;
            else r0.cost = r2c;
        }
    }

    printf("%d", room[n][n].cost);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -