Submission #7496

# Submission time Handle Problem Language Result Execution time Memory
7496 2014-08-09T12:09:08 Z baneling100 배열 탈출 (GA8_array) C++
49 / 100
2000 ms 40200 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#define INF 0x7fffffff

using namespace std;

typedef pair <int,int> ppair;
typedef pair <int,ppair> pppair;
priority_queue <pppair,vector<pppair>,greater<pppair> > Q;
int N, A[2223][2223], D[2223][2223];

void input(void)
{
    int i, j;

    scanf("%d",&N);
    for(i=1 ; i<=N ; i++)
        for(j=1 ; j<=N ; j++)
        {
            scanf("%d",&A[i][j]);
            D[i][j]=INF;
        }
}

void process(void)
{
    int i, y, x, ty, tx;

    D[1][1]=0;
    Q.push(make_pair(0,make_pair(1,1)));
    while(!Q.empty())
    {
        y=Q.top().second.first;
        x=Q.top().second.second;
        Q.pop();
        ty=y;
        tx=x+1;
        if(ty>=1 && ty<=N && tx>=1 && tx<=N)
        {
            if(A[y][x]>A[ty][tx])
            {
                if(D[ty][tx]>D[y][x])
                {
                    D[ty][tx]=D[y][x];
                    Q.push(make_pair(D[ty][tx],make_pair(ty,tx)));
                }
            }
            else
                if(D[ty][tx]>D[y][x]+A[ty][tx]-A[y][x]+1)
                {
                    D[ty][tx]=D[y][x]+A[ty][tx]-A[y][x]+1;
                    Q.push(make_pair(D[ty][tx],make_pair(ty,tx)));
                }
        }
        ty=y+1;
        tx=x;
        if(ty>=1 && ty<=N && tx>=1 && tx<=N)
        {
            if(A[y][x]>A[ty][tx])
            {
                if(D[ty][tx]>D[y][x])
                {
                    D[ty][tx]=D[y][x];
                    Q.push(make_pair(D[ty][tx],make_pair(ty,tx)));
                }
            }
            else
                if(D[ty][tx]>D[y][x]+A[ty][tx]-A[y][x]+1)
                {
                    D[ty][tx]=D[y][x]+A[ty][tx]-A[y][x]+1;
                    Q.push(make_pair(D[ty][tx],make_pair(ty,tx)));
                }
        }
    }
}

void output(void)
{
    printf("%d",D[N][N]);
}

int main(void)
{
    input();
    process();
    output();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 39816 KB Output is correct
2 Correct 0 ms 39816 KB Output is correct
3 Correct 0 ms 39816 KB Output is correct
4 Correct 0 ms 39816 KB Output is correct
5 Correct 0 ms 39816 KB Output is correct
6 Correct 0 ms 39816 KB Output is correct
7 Correct 0 ms 39816 KB Output is correct
8 Correct 0 ms 39816 KB Output is correct
9 Correct 0 ms 39816 KB Output is correct
10 Correct 0 ms 39816 KB Output is correct
11 Correct 0 ms 39816 KB Output is correct
12 Correct 0 ms 39816 KB Output is correct
13 Correct 0 ms 39816 KB Output is correct
14 Correct 0 ms 39816 KB Output is correct
15 Correct 0 ms 39816 KB Output is correct
16 Correct 0 ms 39816 KB Output is correct
17 Correct 0 ms 39816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 39816 KB Output is correct
2 Correct 0 ms 39816 KB Output is correct
3 Correct 0 ms 39816 KB Output is correct
4 Correct 0 ms 39816 KB Output is correct
5 Correct 0 ms 39816 KB Output is correct
6 Correct 0 ms 39816 KB Output is correct
7 Correct 0 ms 39816 KB Output is correct
8 Correct 0 ms 39816 KB Output is correct
9 Correct 0 ms 39816 KB Output is correct
10 Correct 0 ms 39816 KB Output is correct
11 Correct 0 ms 39816 KB Output is correct
12 Correct 0 ms 39816 KB Output is correct
13 Correct 0 ms 39816 KB Output is correct
14 Correct 0 ms 39816 KB Output is correct
15 Correct 0 ms 39816 KB Output is correct
16 Correct 0 ms 39816 KB Output is correct
17 Correct 0 ms 39816 KB Output is correct
18 Correct 0 ms 39816 KB Output is correct
19 Correct 0 ms 39816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39816 KB Output is correct
2 Correct 8 ms 39816 KB Output is correct
3 Correct 16 ms 39816 KB Output is correct
4 Correct 16 ms 39816 KB Output is correct
5 Correct 16 ms 39816 KB Output is correct
6 Correct 16 ms 39816 KB Output is correct
7 Correct 12 ms 39816 KB Output is correct
8 Correct 12 ms 39816 KB Output is correct
9 Correct 12 ms 39816 KB Output is correct
10 Correct 12 ms 39816 KB Output is correct
11 Correct 12 ms 39816 KB Output is correct
12 Correct 8 ms 39816 KB Output is correct
13 Correct 12 ms 39816 KB Output is correct
14 Correct 12 ms 39816 KB Output is correct
15 Correct 12 ms 39816 KB Output is correct
16 Correct 12 ms 39816 KB Output is correct
17 Correct 12 ms 39816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 40200 KB Program timed out
2 Halted 0 ms 0 KB -