1474A - Puzzle From the Future - CodeForces Solution


greedy *800

Please click on ads to support us..

Python Code:

for s in[*open(0)][2::2]:
 r='';p=0
 for x in map(int,s[:-1]):p=x+(x+1!=p);r+=str(p-x)
 print(r)

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define mint(a,b,c) min(a,min(b,c))
#define maxt(a,b,c) max(a,max(b,c))
#define FOR(n) for(int i=0;i<n;i++)
#define rFOR(n) for(int i=n;i>=0;i--)
#define F(n) for(int j=0;j<n;j++)
#define rF(a,n) for(int i=n;i>=a;i--)
#define all(a) a.begin(),a.end()
using namespace std;

void tc(){
    int n;cin>>n;
    string b;cin>>b;
    string a="1";
    int c;
    if(b[0]=='1')c=2;
    else c=1;
    for(int i=1 ; i<b.length() ; i++){
        if(b[i] == '0')
            if(c != 1){
                c=1;
                a+='1';
            }else{
                c = 0;
                a+='0';
            
        }else{
            if(c  != 2){
                c = 2;
                a+='1';
            }else{
                c = 1;
                a+='0';
            }
        }
    }
    cout<<a<<"\n";
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        tc();
    }
}


Comments

Submit
0 Comments
More Questions

946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem
1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking