-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjuryjeopardy.cpp
120 lines (102 loc) · 3.2 KB
/
juryjeopardy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
ll i, j, k;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll cases;
string path;
cin >> cases;
map<char, int> directionMapping;
directionMapping['F'] = 0;
directionMapping['R'] = 1;
directionMapping['B'] = 2;
directionMapping['L'] = 3;
map<pair<ll, ll>, int> reverseDirectionMapping;
reverseDirectionMapping[make_pair(-1, 0)] = 0;
reverseDirectionMapping[make_pair(0, 1)] = 1;
reverseDirectionMapping[make_pair(1, 0)] = 2;
reverseDirectionMapping[make_pair(0, -1)] = 3;
// clockwise from 'up' is 0-4, first entry being current direction and second being new
vector<vector<pair<ll, ll>>> newDirections(4);
newDirections[0].push_back(make_pair(-1, 0));
newDirections[0].push_back(make_pair(0, 1));
newDirections[0].push_back(make_pair(1, 0));
newDirections[0].push_back(make_pair(0, -1));
newDirections[1].push_back(make_pair(0, 1));
newDirections[1].push_back(make_pair(1, 0));
newDirections[1].push_back(make_pair(0, -1));
newDirections[1].push_back(make_pair(-1, 0));
newDirections[2].push_back(make_pair(1, 0));
newDirections[2].push_back(make_pair(0, -1));
newDirections[2].push_back(make_pair(-1, 0));
newDirections[2].push_back(make_pair(0, 1));
newDirections[3].push_back(make_pair(0, -1));
newDirections[3].push_back(make_pair(-1, 0));
newDirections[3].push_back(make_pair(0, 1));
newDirections[3].push_back(make_pair(1, 0));
cout << cases << "\n";
for(i = 0; i < cases; i++)
{
cin >> path;
ll lastDirection = 1;
vector<pair<ll, ll>> reached;
reached.push_back(make_pair(0, 0));
pair<ll, ll> currentLoc = make_pair(0, 0);
for(auto step : path)
{
pair<ll, ll> nextMove = newDirections[lastDirection][directionMapping[step]];
currentLoc.first += nextMove.first;
currentLoc.second += nextMove.second;
reached.push_back(currentLoc);
lastDirection = reverseDirectionMapping[nextMove];
}
ll furthestUp = 999999;
ll furthestdown = -999999;
ll furthestright = -999999;
for(auto locPair : reached)
{
furthestUp = min(furthestUp, locPair.first);
furthestdown = max(furthestdown, locPair.first);
furthestright = max(furthestright, locPair.second);
}
for(j = 0; j < (int)reached.size(); j++)
{
reached[j].first += -furthestUp;
}
ll rowResult = -furthestUp + furthestdown + 3;
ll colResult = furthestright + 2;
vector<string> outArr(rowResult);
for(j = 0; j < rowResult; j++)
{
outArr[j].resize(colResult, '#');
}
for(auto locPair : reached)
{
outArr[locPair.first+1][locPair.second] = '.';
}
cout << rowResult << " " << colResult << "\n";
for(auto rowString : outArr)
{
cout << rowString << "\n";
}
}
return 0;
}