Codeforces Round 828 (Div. 3) 1744A Number Replacement Solution


 

Problem Link :  https://codeforces.com/contest/1744/problem/A

Solution in C++:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t; cin >> t;
  8. while (t--) {
  9. int n ;
  10. cin >> n ;
  11. std::vector<int> a(n);
  12. for ( int i = 0 ; i < n ; i++) {
  13. cin >> a[i] ;
  14. }
  15. string s ;
  16. cin >> s ;
  17. bool ok = true ;
  18. for ( int i = 0 ; i < n and ok ; i++ ){
  19. for ( int j = i + 1 ; j < n ; j++) {
  20. if ( a[i] == a[j] && s[i] != s[j]) {
  21. ok = false ;
  22. break ;
  23. }
  24. }
  25. }
  26. if ( ok ) cout <<"YES\n";
  27. else cout <<"NO\n";
  28. }
  29. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.