Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- int n;
- vector <int> a, res;
- vector <bool> was;
- bool sh = 0;
- void dfs(int i) {
- was[i] = 1;
- int to = i + a[i];
- if (res[to] != -1) {
- res[i] = res[to];
- return;
- }
- if (was[to]) {
- res[i] = 2;
- return;
- }
- dfs(to);
- res[i] = res[to];
- }
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- cin >> n;
- a.resize(n);
- res.assign(n, -1);
- for (int &i: a) cin >> i;
- for (int i = 0; i < n; ++i) {
- if (i + a[i] < 0) {
- res[i] = 0;
- }
- else if (i + a[i] >= n) {
- res[i] = 1;
- }
- }
- for (int i = 0; i < n; ++i) {
- if (res[i] != -1) {
- continue;
- }
- was.assign(n, 0);
- dfs(i);
- }
- if (sh) {
- cout << "a\n";
- cv(a);
- cout << "res\n";
- cv(res);
- }
- string s="";
- for (int i = 0; i < n; ++i) {
- if (res[i] == 0) {
- s += 'L';
- }
- else if (res[i] == 1) {
- s += 'R';
- }
- else {
- s += 'U';
- }
- }
- cout << s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement