Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; struct node { int ci, cj; int cost; node() {} node(int _ci, int _cj, int _cost) { ci = _ci; cj = _cj; cost = _cost; } bool operator < (const node &t) const { return cost > t.cost; } }; class TimeMaze { public: int minTime(vector
mat, int htime, int vtime) { int n = mat.size(), m = mat[0].size(); int si, sj, ei, ej; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(mat[i][j] == 'S') { si = i; sj = j; } if(mat[i][j] == 'E') { ei = i; ej = j; mat[i][j] = '0'; } } } int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; bool visited[n][m]; memset(visited, false, sizeof visited); priority_queue
pq; pq.push(node(si, sj, 0)); while(!pq.empty()) { node c = pq.top(); pq.pop(); visited[c.ci][c.cj] = true; if(c.ci == ei and c.cj == ej) { return c.cost; } for(int i = 0; i < 4; i++) { int ti = c.ci + di[i]; int tj = c.cj + dj[i]; if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj] and mat[ti][tj] != '#') { int t = -1; if(i < 2) { t = vtime; } else { t = htime; } pq.push(node(ti, tj, c.cost + (mat[ti][tj] - '0') + t)); } } } return -1; } }; int main() { return 0; } /* 111#SE#222 S111111 9#####1 99E1111 **/
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)