Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <list>
- #include <map>
- #include <set>
- #include <queue>
- #include <deque>
- #include <stdio.h>
- #include <string.h>
- #include <stack>
- #include <bitset>
- #include <algorithm>
- #include <functional>
- #include <numeric>
- #include <utility>
- #include <sstream>
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- string way;
- bool ok;
- const int N = 80;
- char dp[N][N][N][N];
- int l;
- class ExplodingRobots {
- public:
- int dfs(int x1,int y1,int x2,int y2){
- if (x1 == x2 && y1 == y2){
- ok = 1;
- return dp[x1][y1][x2][y2] = 1;
- }
- if (dp[x1][y1][x2][y2] == -1){
- if (l < way.size()) {
- int dx = 0,dy = 0;
- if (way[l] == 'U'){
- dy = 1;
- }
- if (way[l] == 'D'){
- dy = -1;
- }
- if (way[l] == 'R'){
- dx = 1;
- }
- if (way[l] == 'L'){
- dx = -1;
- }
- l++;
- dfs(x1 + dx,y1 + dy, x2, y2);
- dfs(x1,y1, x2 + dx, y2 + dy);
- dfs(x1 + dx,y1 + dy, x2 + dx, y2 + dy);
- l--;
- }
- return dp[x1][y1][x2][y2] = 1;
- }
- else return dp[x1][y1][x2][y2];
- }
- string canExplode(int x1, int y1, int x2, int y2, string instructions) {
- way = instructions;
- memset(dp,-1,sizeof dp);
- dfs(x1,y1,x2,y2);
- if (ok){
- return "Explosion";
- }
- else
- return "Safe";
- }
- };
- <%:testing-code%>
- //Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement