1520A - Do Not Be Distracted - CodeForces Solution


brute force implementation *800

Please click on ads to support us..

Python Code:

t=int(input())
result=[]
for i1 in range(t):
    n=int(input())
    task_list=input()
    current_task=task_list[0]
    tasks_done=[current_task]
    pointer=1
    while pointer<n:
        if current_task!=task_list[pointer]:
            if task_list[pointer] in tasks_done:
                result.append("NO")
                break
            else:
                tasks_done.append(current_task)
                current_task=task_list[pointer]
        pointer+=1
    else:
        result.append("YES")

for i2 in result:
    print(i2)
                

C++ Code:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define pb push_back

int main()
{
    ll t,n;string s;cin>>t;
    while(t--){
        cin>>n>>s;
        vector<ll> v;set<ll> l;
        for(ll i = 0;i<n;i++){
            v.pb(s[i]);l.insert(s[i]);
            while(i+1<n&&s[i]==s[i+1]){
                i++;

            }
        }
        if(l.size()==v.size()){
            cout<<"YES";
        }
        else{
            cout<<"NO";
        }
        cout<<'\n';

    }
    

}


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament