제출 #728554

#제출 시각아이디문제언어결과실행 시간메모리
728554Rasoul006Wombats (IOI13_wombats)C++17
55 / 100
20096 ms42256 KiB
#include "wombats.h"

#include <bits/stdc++.h>

#define endl "\n"

#define F first

#define S second

#define pb push_back

#define all(x) x.begin() , x.end()

typedef long long ll;

using namespace std;

const int N = 6e3+5;

const long long oo = 1e18;

ll dx[] = {1 , -1 , 0} ;
ll dy[] = {0 , 0 , 1} ;

ll n , m , h[N][204] , v[N][204] , a[N][204] , cost[N] , sum , c , r ;

ll dis[105][105] ;

set < pair <ll, pair <ll, ll>> > st ;

void init(int R, int C, int H[5000][200], int V[5000][200]) {

    n = R , m = C ;

    for (int i = 0 ; i<n ; i++)
    {
        cost[i] = H[i][0];
        for (int j = 0 ; j<m ; j++)
        {
            v[i][j] = V[i][j] , h[i][j] = H[i][j] ;
            sum += v[i][j] ;
            a[i][j] = v[i][j];
        }
    }

}

void changeH(int P, int Q, int W) {
    h[P][Q] = W ;
    cost[P] = W ;
}

void changeV(int P, int Q, int W) {
    sum -= v[P][Q] ;
    sum += W ;
    v[P][Q] = W ;
    a[P][Q] = W ;
}

ll dp[N][2][2] ;

ll bt (ll i , bool is , bool is2)
{
    if (i == n)
        return ((is != is2) * cost[n-1]) ;

    ll &ret = dp[i][is][is2] ;

    if (~ret)
        return ret ;

    ret = bt(i+1 , is , is2) + a[i][is] ;
    ret = min(ret ,  bt(i+1 , !is , is2) + cost[i] + a[i][!is]);

    return ret ;
}

int escape(int V1, int V2)
{
    if (m == 1)
        return sum ;

    for (int i = 0 ; i<=n+9 ; i++)
    {
        dp[i][0][0] = -1 ;
        dp[i][0][1] = -1 ;
        dp[i][1][0] = -1 ;
        dp[i][1][1] = -1 ;
    }

    if (m == 2)
        return bt(0 , V1 , V2) ;

    for (int p = 0 ; p<n ; p++)
        for (int j = 0 ; j<m ; j++)
            dis[p][j] = oo ;

    st.insert({0 , {0 , V1}});

    while (!st.empty())
    {
        pair <ll , pair <ll,ll>> pr = *st.begin() ;

        st.erase(st.begin());

        ll cos = pr.F , x = pr.S.F , y = pr.S.S ;

        if (cos + v[x][y] < dis[x+1][y] && x+1 < n)
        {
            dis[x+1][y] = cos + v[x][y] ;
            st.insert({dis[x+1][y] , {x+1 , y}});
        }

        if (cos + h[x][y] < dis[x][y+1] && y+1<m)
        {
            dis[x][y+1] = cos + h[x][y] ;
            st.insert({dis[x][y+1] , {x , y+1}});
        }

        if (cos + h[x][y-1] < dis[x][y-1] && y-1 >= 0)
        {
            dis[x][y-1] = cos + h[x][y-1] ;
            st.insert({dis[x][y-1] , {x , y-1}});
        }
    }


    return dis[n-1][V2];
}

컴파일 시 표준 에러 (stderr) 메시지

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...