Problem:
Problem A:
Dance Dance Revolution
Dance Dance Revolution
is one of the most popular arcade games in Japan. The rule of this game is very
simple. A series of four arrow symbols,
up
,
down
,
left
and
right
, flows downwards on the screen in time
to music. The machine has four panels under your foot, each of which corresponds to one of the four
arrows, and you have to make steps on these panels according to the arrows displayed on the screen. The
more accurate in timing, the higher score you will mark.
Figure 1: Layout of Arrow Panels and Screen
Each series of arrows is commonly called a score. Difficult scores usually have hundreds of arrows, and
newbies will often be scared when seeing those arrows fill up the monitor screen. Conversely, scores
with fewer arrows are considered to be easy ones.
One day, a friend of yours, who is an enthusiast of this game, asked you a favor. What he wanted is an
automated method to see if given scores are
natural
. A score is considered as natural when there is a
sequence of steps that meets all the following conditions:
left-foot steps and right-foot steps appear in turn;
the same panel is not stepped on any two consecutive arrows;
a player can keep his or her upper body facing forward during a play; and
his or her legs never cross each other.
Your task is to write a program that determines whether scores are natural ones.
Input
The first line of the input contains a positive integer. This indicates the number of data sets.
Each data set consists of a string written in a line. Each string is made of four letters, “U” for up, “D”
for down, “L” for left and “R” for right, and specifies arrows in a score. No string contains more than
100,000 characters.
Output
For each data set, output in a line “Yes” if the score is natural, or “No” otherwise.
Sample Input
3
UU
RDUL
ULDURDULDURDULDURDULDURD
Output for the Sample Input
No
Yes
Yes

Submitted solutions:

code_snippet: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		for (int j = 0; j < s.size() - 1; j++) {
			if (s[j] == s[j + 1]) {
				cout << "No\n";
				goto end;
			}
		}
		cout << "Yes\n";
	end:;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3280
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int q;
  cin>>q;
  while(q--){
    string s;
    cin>>s;
    string t=s;
    t.erase(unique(t.begin(),t.end()),t.end());
    if(s.size()!=t.size()){
      cout<<"No"<<endl;
      continue;
    }
    if((int)s.size()<3){
      cout<<"Yes"<<endl;
      continue;
    }
    bool f=0;
    for(int k=0;k<2;k++){
      bool ff=1;
      char l=s[k],r=s[!k];
      if(l=='R'||r=='L'){
	ff=0;
      }
      for(int i=2;i<(int)s.size();i++){
	if((i+k)%2) r=s[i];
	else l=s[i];
	if(l=='R'||r=='L'){
	  ff=0;
	  break;
	}
      }
      f|=ff;
    }
    if(f) cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3280
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
int ctoi(char);
int main(){
  int n;
  cin >> n;
  for(int I=0;I<n;I++){
    string st;
    cin >> st;
    int f=0;
    for(int j=0;j<2;j++){
      int r=-1;
      int l=-1;
      int t=j;
      for(int i=0;i<st.size();i++){
	//	cout << t;
	if(t==0){
	  r=ctoi(st[i]);
	  if(r==l||r==4){
	    f++;
	    break;
	  }
	}
	else{
	  l=ctoi(st[i]);
	  if(l==r||l==2){
	    f++;
	    break;
	  }
	}
	if(t==1)t=0;
	else t=1;
      }
    }
    if(f!=2)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;


}
int ctoi(char a){
  if(a=='U')return 1;
  if(a=='R')return 2;
  if(a=='D')return 3;
  if(a=='L')return 4;
}
accuracy: 1
time_ms: 10
memory_kb: 3256
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;

string S;

int ch(char c){
  if( c == 'L' ) return 0;
  if( c == 'U' ) return 1;
  if( c == 'D' ) return 1;
  if( c == 'R' ) return 2;
}

bool solve(int f){
  int d[4]={};
  int ft[2]; ft[0] = ft[1] = -1;
  for(int i=0;i<(int)S.size();i++){
    ft[f] = ch(S[i]);
    f = 1-f;
    if(i && S[i] == S[i-1]) return false;
    if( ft[0] == -1 || ft[1] == -1 ) continue;
    if( ft[0] > ft[1] ) return false;
  }
  return true;
}

int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> S;
    if( solve(0) || solve(1) ) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3252
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
string str;

bool sim(bool turn){

  int n = str.size();
  char pos = str[0];
  for(int i=1;i<n;i++){
    if(pos == str[i]) return 0;
    if(turn == 1 && str[i] == 'R') return 0;
    if(turn == 0 && str[i] == 'L') return 0;
    pos = str[i];
    turn = !turn;
  }
  return 1;
}

int main(){
  int q;
  cin>>q;
  while(q--){
  cin>>str;
  int ans = sim(0)|sim(1);
  cout<< (ans? "Yes":"No")<<endl;
  }
  

  return 0;  
}
accuracy: 1
time_ms: 10
memory_kb: 3240
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define rep( i, begin, end ) for( int i = begin; i < end; i++ )
using namespace std;
 
bool scores( string input ) {
    int length = input.size();
    bool left = true, right = true;
    input += '!';
    rep( i, 0, length) {
        if( input[ i ] == input[ i + 1 ] )
            return false;
        if( input[ i ] == 'L' && i % 2 == 1 )
            left = false; 
        if( input[ i ] == 'R' && i % 2 == 0 )
            left = false;
        if( input[ i ] == 'L' && i % 2 == 0 )
            right = false; 
        if( input[ i ] == 'R' && i % 2 == 1 )
            right = false; 
    }
 
    return ( left | right );
}
 
int main() {
    int n;
    string input;
    cin >> n;
    rep( i, 0, n) {
        cin >> input;
        cout << ( scores( input ) ? "Yes":"No") << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3268
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;string S;
	for(int i=0;i<n;i++){
		cin>>S;bool OK=true;
		for(int j=0;j<S.size()-1;j++){
			if(S[j]==S[j+1])OK=false;
		}
		if(OK==true)cout<<"Yes"<<endl;else cout<<"No"<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1324
final_rank: 5

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int q;
	cin>>q;
	while(q--){
		string s;
		cin>>s;
		bool h=true;
		rep(i,s.size()-1)if(s[i]==s[i+1])h=false;
		if(h)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;	
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1328
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        string steps;
        cin >> steps;

        char ss = '\0';
        int lr = 0; // -1: left, 0: both, 1: right
        REP(j, steps.size()) {
            char s = steps[j];
            if (s == ss) goto NO;
            if (lr > 0) {
                if (s == 'L') goto NO;
            } else if (lr < 0) {
                if (s == 'R') goto NO;
            } else {
                if (s == 'R') {
                    lr = 1;
                } else if (s == 'L') {
                    lr = -1;
                }
            }
            ss = s;
            lr = -lr;
        }
        cout << "Yes" << endl;
        continue;
    NO:
        cout << "No" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3184
final_rank: 13

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

enum { U = 0, D = 1, L = 2, R = 3 };

/* global variables */

bool mtx[4][4] = {{0, 1, 0, 1}, {1, 0, 0, 1}, {1, 1, 0, 1}, {0, 0, 0, 0}};
int ch2d[26];

/* subroutines */

/* main */

int main() {
  ch2d['U' - 'A'] = U;
  ch2d['D' - 'A'] = D;
  ch2d['L' - 'A'] = L;
  ch2d['R' - 'A'] = R;

  int c;
  cin >> c;

  while (c--) {
    string score;
    cin >> score;

    int len = score.length();
    bool yes = false;
    
    for (int st = 0; st <= 1; st++) {
      int prvd = ch2d[score[0] - 'A'];
      int prvf = st;
      int ok = true;

      for (int i = 1; ok && i < len; i++) {
	int curd = ch2d[score[i] - 'A'];
	if ((prvf == 0 && ! mtx[prvd][curd]) ||
	    (prvf == 1 && ! mtx[curd][prvd])) {
	  ok = false;
	  break;
	}
	prvd = curd;
	prvf ^= 1;
      }

      if (ok) {
	yes = true;
	break;
      }
    }

    cout << (yes ? "Yes" : "No") << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1328
final_rank: 7

code_snippet: #include <iostream>
#include <string>
#include <cstring>
using namespace std;

char s[100010];

int main(void){
  int rightFlag;
  int j,i,n;
  int foot[2];
  char before;
  cin>>n;
  while(n--){
    cin>>s;
    for(j = 0 ; j < 2 ; j ++){
      foot[0] = -1;
      foot[1] = 1;
      rightFlag = j;
      before = 0;
      for(i = 0 ; i < strlen(s) ; i ++){
        if(before == s[i])break;
        switch(s[i]){
          case 'U' :
          case 'D' :
            foot[rightFlag] = 0;
            break;
          case 'R' :
            foot[rightFlag] = 1;
            break;
          case 'L' :            
            foot[rightFlag] = -1;
            break;
        }
        if(foot[0] > foot[1]) break;
        before = s[i];
        rightFlag = !rightFlag;
      }
      if(i == strlen(s)) break;
    }
    cout<<(j<2?"Yes":"No")<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 2820
memory_kb: 1252
final_rank: 20

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

bool check_sequence(const string& command){
  for(int i=0;i+1<command.size();i++){
    if(command[i] == command[i+1]) return false;
  }
  return true;
}

bool check_cross(int lpos,int rpos){
  if(lpos == -1 || rpos == -1) return true;
  if(lpos !=0 && lpos < rpos) return false;
  if(lpos == 0 && rpos == 3) return false;
  return true;
}

int compute_pos(char dir){
  int pos = 0;
  if(dir == 'U'){
    pos = 0;
  }
  else if(dir == 'R'){
    pos= 1;
  }
  else if(dir == 'D'){
    pos = 2;
  }
  else if(dir == 'L'){
    pos = 3;
  }

  return pos;
}

int main(){
  int N;
  while(~scanf("%d",&N)){
    for(int i = 0; i < N; i++){
      bool isok = true;
      string command;
      cin >> command;

      int lpos = -1;
      int rpos = -1;
      int flag = 0;

      if(!check_sequence(command)){
        isok = false;
        goto gameover;
      }

      for(int command_i = 0; command_i < command.size(); command_i++){
        if(command_i % 2 == 1) {
          lpos = compute_pos(command[command_i]);
        }
        else {
          rpos = compute_pos(command[command_i]);
        }

        if(!check_cross(lpos,rpos)){
          flag |= (1<<0);
        }
      }

      lpos = -1;
      rpos = -1;

      for(int command_i = 0; command_i < command.size(); command_i++){
        if(command_i % 2 == 0) {
          lpos = compute_pos(command[command_i]);
        }
        else {
          rpos = compute_pos(command[command_i]);
        }

        if(!check_cross(lpos,rpos)){
          flag |= (1<<1);
        }
      }

    gameover:;
      printf("%s\n",(!isok || (flag == (1<<2) - 1)) ? "No" : "Yes");
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 1336
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        string input;
        cin >> input;

        bool firstIsNatural = true;
        for(int i=0; i < input.size(); i++){
            if(i%2 == 0 && input.substr(i,1) == "L") firstIsNatural = false;
            else if(i%2 == 1 && input.substr(i,1) == "R") firstIsNatural = false;

            if(i != 0) if(input[i] == input[i-1]) firstIsNatural = false;
        }
        bool secondIsNatural = true;
        for(int i=0; i < input.size(); i++){
            if(i%2 == 1 && input.substr(i,1) == "L") secondIsNatural = false;
            else if(i%2 == 2 && input.substr(i,1) == "R") secondIsNatural = false;
            if(i != 0) if(input[i] == input[i-1]) secondIsNatural = false;
        }
        if(firstIsNatural || secondIsNatural) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 1340
final_rank: 12

code_snippet: #include <iostream>

using namespace std;

bool is_natural(const string& score, char cur) {
    char prev = score[0];
    for (int i = 1; i < score.size(); i++) {
        if (prev == score[i]) {
            return false;
        }
        prev = score[i];
    }

    char l = 'm';
    char r = 'm';
    for (int i = 0; i < score.size(); i++) {
        if (cur == 'l') {
            l = score[i];
            cur = 'r';
        } else {
            r = score[i];
            cur = 'l';
        }

        if (l == 'U') {
            if (r == 'L') {
                return false;
            }
        } else if (l == 'R') {
            return false;
        } else {
            if (r == 'L') {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string score; cin >> score;
        cout << ((is_natural(score, 'l') || is_natural(score, 'r')) ? "Yes" : "No") << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1328
final_rank: 7

code_snippet: //49
#include<iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    char s[100001];
    cin>>s;
    int i[2];
    for(int j=0;j<2;j++){
      char l=0,r=0;
      for(i[j]=0;s[i[j]];i[j]++){
	((i[j]%2^j)?r:l)=s[i[j]];
	if(l==r)break;
	if(s[j]>0&&(l=='U'&&(r=='L')||l=='R'||l=='D'&&(r=='L')))break;
      }
    }
    cout<<(s[i[0]]&&s[i[1]]?"No":"Yes")<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1248
final_rank: 4

code_snippet: #include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

string solve(string s)
{
    int n = s.size();
    for(int i=0; i<n-1; ++i){
        if(s[i] == s[i+1])
            return "No";
    }

    bool ok = true;
    for(int i=0; i<n; ++i){
        if(i % 2 == 0 && s[i] == 'R')
            ok = false;
        if(i % 2 == 1 && s[i] == 'L')
            ok = false;
    }
    if(ok)
        return "Yes";

    ok = true;
    for(int i=0; i<n; ++i){
        if(i % 2 == 1 && s[i] == 'R')
            ok = false;
        if(i % 2 == 0 && s[i] == 'L')
            ok = false;
    }
    if(ok)
        return "Yes";

    return "No";
}

int main()
{
    int d;
    cin >> d;

    while(--d >= 0){
        string s;
        cin >> s;
        cout << solve(s) << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1340
final_rank: 10

code_snippet: #include<iostream>

using namespace std;

int main(){
  int n;
  string s;
  char prev;
  bool yes_or_no;
  cin >> n;
  while(n-- > 0){
    cin >> s;
    prev = s[0];
    yes_or_no = true;
    for(int i=1;i<s.length();i++){
      if(prev == s[i]){
	yes_or_no = false;
	break;
      }
	prev = s[i];
    }
    if(yes_or_no)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1324
final_rank: 5

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int n; cin>>n;
  string s;
  REP(i,n){
    cin>>s;
    bool ok = true;
    REP(i,s.size()-1)if(s[i]==s[i+1])ok = false;
    bool t[2]={};
    REP(i,s.size()){
      if(s[i]=='L')t[(i+0)%2] = true;
      else if(s[i]=='R')t[(i+1)%2] = true;
    }
    if(t[0]&&t[1])ok = false;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1140
final_rank: 3

code_snippet: #include <iostream>
#include <string>
using namespace std;

bool solve(string s)
{
	int len = s.size();
	bool l = true, r = true;

	s+='!';

	for(int i=0; i<len; i++) {
		if(s[i]==s[i+1]) return false;

		if(s[i] == 'L' && i%2 == 1) l = false; 
		if(s[i] == 'R' && i%2 == 0) l = false;

		if(s[i] == 'L' && i%2 == 0) r = false; 
		if(s[i] == 'R' && i%2 == 1) r = false; 

	}

	return (l|r);
}

int main()
{
	int N;
	cin >> N;
	while(N--) {
		string s;
		cin >> s;

		cout << (solve(s)? "Yes":"No") << endl;
	
	}
}
accuracy: 1
time_ms: 20
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

bool func(const string &s, bool left) {
  REP(i, s.size()) {
    if (i&&s[i]==s[i-1]) return 0;
    if (left && s[i] == 'R' || !left && s[i] == 'L') {
      return 0;
    }
    left ^= 1;
  }
  return 1;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string s;
    cin >> s;
    if (func(s, 0) || func(s, 1)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 1036
final_rank: 2