Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int n;
- cin>>n;
- if(n==1 ){
- char a;
- cin>>a;
- if(a=='1'){
- cout<<"Yes";
- }
- else{
- cout<<"No";
- }
- }
- else{
- char a;
- char b;
- int k=1;
- for(int i=0;i<n;i++){
- cin>>b;
- if(b=='0'){
- k++;
- if(k==3){
- cout<<"No";
- return 0;
- }
- }
- else{
- k=0;
- }
- if(i>=1){
- if(a==b && a=='1'){
- cout<<"No";
- return 0;
- }
- }
- if(i!=n-1){
- a=b;
- }
- }
- if(a==b && a=='0'){
- cout<<"No";
- return 0;
- }
- cout<<"Yes";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement