9061 | 2024-02-13 14:19:01 | Qkrisi | 2016. április | cpp17 | Time limit exceeded on test 2 | 2.099s | 1700 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const pair<int, int> pairs[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
void run(string* moves, size_t N, set<pair<ll, ll>>* endings)
{
int direction = 1;
ll X = 0;
ll Y = 0;
for(size_t i = 0;i<N;i++)
{
switch(moves->at(i))
{
case 'F':
X += pairs[direction].first;
Y += pairs[direction].second;
break;
case 'R':
if(++direction == 5)
direction = 1;
break;
case 'L':
if(--direction == 0)
direction = 4;
break;
}
}
endings->insert({X, Y});
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string moves;
getline(cin, moves);
size_t N = moves.size();
set<pair<ll, ll>> endings;
for(size_t i = 0;i<N;i++)
{
char original = moves[i];
pair<char, char> PossibleMoves;
switch(original)
{
case 'F':
PossibleMoves = {'L', 'R'};
break;
case 'L':
PossibleMoves = {'F', 'R'};
break;
case 'R':
PossibleMoves = {'L', 'F'};
break;
}
moves[i] = PossibleMoves.first;
run(&moves, N, &endings);
moves[i] = PossibleMoves.second;
run(&moves, N, &endings);
moves[i] = original;
}
cout << endings.size();
return 0;
}
3
Expected output:3
Checker output:ok 1 number(s): "3"
Expected output:34389
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output:
Expected output:
Checker output: