답안 #728554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728554 2023-04-22T15:40:58 Z Rasoul006 웜뱃 (IOI13_wombats) C++17
55 / 100
20000 ms 42256 KB
#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];
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28244 KB Output is correct
2 Correct 12 ms 28244 KB Output is correct
3 Correct 82 ms 31004 KB Output is correct
4 Correct 13 ms 28228 KB Output is correct
5 Correct 13 ms 28240 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 21 ms 508 KB Output is correct
5 Correct 13 ms 496 KB Output is correct
6 Correct 14 ms 468 KB Output is correct
7 Correct 22 ms 448 KB Output is correct
8 Correct 21 ms 492 KB Output is correct
9 Correct 24 ms 468 KB Output is correct
10 Correct 22 ms 468 KB Output is correct
11 Correct 11716 ms 2876 KB Output is correct
12 Correct 28 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 1228 KB Output is correct
2 Correct 220 ms 1508 KB Output is correct
3 Correct 193 ms 1108 KB Output is correct
4 Correct 201 ms 1152 KB Output is correct
5 Correct 193 ms 1144 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 193 ms 1236 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 32844 KB Output is correct
2 Correct 182 ms 32808 KB Output is correct
3 Correct 250 ms 32832 KB Output is correct
4 Correct 14422 ms 34184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 1108 KB Output is correct
2 Correct 215 ms 1508 KB Output is correct
3 Correct 186 ms 1152 KB Output is correct
4 Correct 195 ms 1144 KB Output is correct
5 Correct 192 ms 1228 KB Output is correct
6 Correct 153 ms 32932 KB Output is correct
7 Correct 158 ms 32828 KB Output is correct
8 Correct 156 ms 32836 KB Output is correct
9 Correct 15555 ms 34292 KB Output is correct
10 Correct 14 ms 28244 KB Output is correct
11 Correct 16 ms 28164 KB Output is correct
12 Correct 92 ms 31000 KB Output is correct
13 Correct 16 ms 28184 KB Output is correct
14 Correct 13 ms 28160 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 24 ms 512 KB Output is correct
19 Correct 14 ms 480 KB Output is correct
20 Correct 16 ms 448 KB Output is correct
21 Correct 23 ms 452 KB Output is correct
22 Correct 20 ms 468 KB Output is correct
23 Correct 24 ms 468 KB Output is correct
24 Correct 21 ms 468 KB Output is correct
25 Correct 11813 ms 2796 KB Output is correct
26 Correct 27 ms 468 KB Output is correct
27 Correct 197 ms 1356 KB Output is correct
28 Execution timed out 20096 ms 36000 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 1108 KB Output is correct
2 Correct 214 ms 1504 KB Output is correct
3 Correct 196 ms 1108 KB Output is correct
4 Correct 191 ms 1144 KB Output is correct
5 Correct 193 ms 1152 KB Output is correct
6 Correct 163 ms 32832 KB Output is correct
7 Correct 166 ms 32812 KB Output is correct
8 Correct 159 ms 32832 KB Output is correct
9 Correct 14255 ms 34392 KB Output is correct
10 Correct 13 ms 28244 KB Output is correct
11 Correct 13 ms 28164 KB Output is correct
12 Correct 80 ms 31012 KB Output is correct
13 Correct 13 ms 28244 KB Output is correct
14 Correct 13 ms 28244 KB Output is correct
15 Incorrect 439 ms 42256 KB Output isn't correct
16 Halted 0 ms 0 KB -