?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
143888120 |
Practice: SpartanWarrior |
1627E - 78 | C++14 (GCC 6-32) | Runtime error on test 1 | 0 ms | 0 KB | 2022-01-24 18:05:42 | 2022-01-24 18:05:42 |
#include "bits/stdc++.h" using namespace std; typedef long long ll ; int main() { ios::sync_with_stdio( false ); cin.tie(nullptr ); cout.tie(nullptr); ll t ; cin>> t ; while( t-- ) { ll n , m , k ; cin >> n >> m >> k ; ll x[n+1] ; for(ll i =1 ; i <= n ; i ++ ) cin>> x[i] ; map< ll , map<ll,ll> > dp ; map<ll, vector<ll> > room ; map< pair<ll,ll> , vector<ll> > ladder ; for(ll i = 0 ; i<k;i++ ) { ll a , b , c , d , h ; cin >>a>> b>> c>> d>> h; room[a].push_back( b ) ; room[ c ].push_back( d ) ; dp[a][b] = INT_MAX ; dp[c][d] = INT_MAX ; ladder[ {a , b } ] = { c,d,h} ; } dp[1][1] = 0 ; room[1].push_back( 1 ); room[n].push_back( m ) ; for(int i = 1 ; i <= n ; i ++ ) { if( room[i].empty() ) continue; sort( room[i].begin() , room[i].end() ) ; } dp[n][m] = INT_MAX ; for(ll i =1 ; i <= n ; i ++ ) { ll mn = INT_MAX , index =0 ; for(ll j =0 ; j < room[i].size() ; j ++ ) { ll col = room[i][j] ; if( dp[i][col] <= mn ) { mn = dp[i][ col ] ; index = col ; } else dp[i][col] = min( dp[i][col] , mn + abs(col-index)*x[i] ) ; if( ladder.find( {i,col} ) != ladder.end() ) { ll nrow =ladder[{i,col}][0] ; ll ncol =ladder[{i,col}][1] ; ll health = ladder[{i,col}][2] ; dp[ nrow ][ ncol ] = min( dp[nrow][ncol] , dp[i][col] - health ) ; } if( dp[i][col] <= mn ) { mn = dp[i][ col ] ; index = col ; } } mn = INT_MAX ; index =0 ; for(ll j = room[i].size() -1 ; j >=0 ; j-- ) { ll col = room[i][j] ; if( dp[i][col] <= mn ) { mn = dp[i][ col ] ; index = col ; } else dp[i][col] = min( dp[i][col] , mn + abs(col-index)*x[i] ) ; if( ladder.find( {i,col} ) != ladder.end() ) { ll nrow =ladder[{i,col}][0] ; ll ncol =ladder[{i,col}][1] ; ll health = ladder[{i,col}][2] ; dp[ nrow ][ ncol ] = min( dp[nrow][ncol] , dp[i][col] - health ) ; } if( dp[i][col] <= mn ) { mn = dp[i][ col ] ; index = col ; } } } if( dp[n][m] == INT_MAX ) cout<<"NO ESCAPE\n" ; else cout<<dp[n][m] <<"\n" ; } }
?
?
?
?