Submission #204011

#TimeUsernameProblemLanguageResultExecution timeMemory
204011CaroLindaWombats (IOI13_wombats)C++14
21 / 100
320 ms21672 KiB
#include "wombats.h" #include <bits/stdc++.h> #define debug #define lp(i,a,b) for(int i = a ; i < b ; i++ ) const int inf = 1e9+10 ; const int MAXN = 5005 ; const int MAXM = 205 ; using namespace std ; int N , M ; int ini_bucket[MAXN] , end_bucket[MAXN]; int my_block[MAXN ] ; int resp[MAXM][MAXM] ; int opt[MAXM][MAXM] ; int h[MAXN][MAXM] ; int v[MAXN][MAXM] ; int tree[130*4][MAXM][MAXM] ; //Esta funcao recebe um pedaco do meu grid maior //Com esse pedaco, ela calcula a dp //Stora o resultado na matriz resp[MAXM][MAXM] void calc(int n_menor , int n_maior ) { int dp[MAXN][MAXM] ; for(int curr_c = 0 ; curr_c < M ; curr_c++ ) { //Calculando a distancia de [n_menor][i] para [n_maior][j] , qualquer j lp(i,n_menor, n_maior + 1) lp(j,0,M) dp[i][j] = inf ; dp[n_menor][ curr_c ] = 0 ; for(int i = n_menor ; i <= n_maior ; i++ ) { for(int j = 0 ; j < M ; j++ ) { if( i >= 1 ) dp[i][j] = min( dp[i][j] , dp[i-1][j] + v[i-1][j] ) ; if( j >= 1 ) dp[i][j] = min( dp[i][j] , dp[i][j-1] + h[i][j-1] ) ; } for(int j = M-2 ; j >= 0 ; j-- ) dp[i][j] = min( dp[i][j] , dp[i][j+1] + h[i][j] ) ; } for(int j = 0 ; j < M ; j++ ) resp[ curr_c ][j] = dp[n_maior][j] ; } } int m(int l, int r) { return (l+r)>>1 ; } void tres_colunas( int adj_left[][MAXM] ,int adj_right[][MAXM] ) { //opt(i-1,j) <= opt(i,j) <= opt(i,j+1) //opt(i,j+1) <= opt(i+1,j+1) <= opt(i+1,j+2) for(int diff = M-1 ; diff >= 0 ; diff -- ) { for(int x = 0 ; x < N ; x++ ) { int y = x+ diff ; if( y >= M ) continue ; //calc opt[x][y] int opt_min = 0 , opt_max = N-1 ; if( x-1 >= 0 ) opt_min = opt[x-1][y] ; if( y+1 < N ) opt_max = opt[x][y+1] ; int opt_val = inf ; for(int i = opt_min ; i <= opt_max ; i++ ) if( adj_left[x][i] + adj_right[i][y] < opt_val ) { opt_val = adj_left[x][i] + adj_right[i][y] ; resp[x][y] = opt_val ; opt[x][y] = i ; } } } } int adj_aux[MAXM][MAXM] ; void merge(int pos, int l, int r) { int coluna_menor = end_bucket[ m(l,r) ] ; int coluna_maior = ini_bucket[ m(l,r)+1 ] ; calc(coluna_menor , coluna_maior ) ; for(int i = 0 ; i < M ; i++ ) for(int j = 0 ; j < M ; j++ ) adj_aux[i][j] = resp[i][j] ; tres_colunas( tree[pos*2] , adj_aux ) ; for(int i = 0 ; i < M ; i++ ) for(int j = 0 ; j < M ; j++ ) adj_aux[i][j] = resp[i][j] ; tres_colunas( adj_aux, tree[pos*2+1] ) ; for(int i = 0 ; i < M ; i++ ) for(int j = 0 ; j < M ; j++ ) tree[pos][i][j] = resp[i][j] ; } void build_seg(int pos, int l, int r) { if( l == r ) { calc( ini_bucket[l] , end_bucket[l] ) ; for(int i = 0 ; i < M ; i++ ) for(int j = 0 ; j < M ; j++ ) tree[pos][i][j] = resp[i][j] ; return ; } build_seg( pos*2,l, m(l,r) ) ; build_seg( pos*2+1, m(l,r)+1 , r ) ; merge(pos, l, r ) ; } void upd(int pos, int l, int r, int idx ) { if( l == r ) { calc( ini_bucket[l] , end_bucket[l] ) ; for(int i = 0 ; i < M ; i++ ) for(int j = 0 ; j < M ; j++ ) tree[pos][i][j] = resp[i][j] ; return ; } if( idx <= m(l,r) ) upd(pos*2,l,m(l,r),idx ); else upd(pos*2+1,m(l,r)+1, r, idx ) ; merge(pos,l,r) ; } inline void print() { debug("Printing\n" ) ; for(int i = 0 ; i < M ; i++ , debug("\n") ) for(int j = 0 ; j < M ; j++ ) debug("%d " , tree[1][i][j] ) ; debug("\n") ; } 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++ ) for(int j = 0 ; j < M ; j++ ) { h[i][j] = H[i][j] ; v[i][j] = V[i][j] ; } ini_bucket[1] = 0 ; for(int i = 0 , j = 0 , k = 1 ; i < N ; i++ , j++ ) { if( j == 40 ) { k++ ; j = 0 ; ini_bucket[k] = i ; } my_block[i] = k ; end_bucket[k] = i ; } build_seg(1,1, my_block[N-1] ) ; for(int i = 0 ; i < M ; i++, debug("\n") ) for(int j = 0 ; j < M ; j++ ) debug("%d " , tree[1][i][j] ) ; } void changeH(int P, int Q, int W) { h[P][Q] = W ; upd( 1 , 1 , my_block[ N-1 ] , my_block[P] ) ; //print() ; } void changeV(int P, int Q, int W) { v[P][Q] = W ; upd( 1 , 1, my_block[N-1] , my_block[P] ) ; //print() ; } int escape(int V1, int V2) { return tree[1][V1][V2] ; }

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
wombats.cpp: In function 'void print()':
wombats.cpp:182:23: warning: statement has no effect [-Wunused-value]
  debug("Printing\n" ) ;
                       ^
wombats.cpp:183:42: warning: right operand of comma operator has no effect [-Wunused-value]
  for(int i = 0 ; i < M ; i++ , debug("\n") )
                                          ^
wombats.cpp:184:59: warning: left operand of comma operator has no effect [-Wunused-value]
   for(int j = 0 ; j < M ; j++ ) debug("%d " , tree[1][i][j] ) ;
                                                           ^
wombats.cpp:185:14: warning: statement has no effect [-Wunused-value]
  debug("\n") ;
              ^
wombats.cpp: In function 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:220:41: warning: right operand of comma operator has no effect [-Wunused-value]
  for(int i = 0 ; i < M ; i++, debug("\n") )
                                         ^
wombats.cpp:221:59: warning: left operand of comma operator has no effect [-Wunused-value]
   for(int j = 0 ; j < M ; j++ ) debug("%d " , tree[1][i][j] ) ;
                                                           ^
#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...