Codeforces Round 828 (Div. 3) 1744A Number Replacement Solution
Problem Link : https://codeforces.com/contest/1744/problem/A
Solution in C++:
- #include<bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t; cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- std::vector<int> a(n);
- for ( int i = 0 ; i < n ; i++) {
- cin >> a[i] ;
- }
- string s ;
- cin >> s ;
- bool ok = true ;
- for ( int i = 0 ; i < n and ok ; i++ ){
- for ( int j = i + 1 ; j < n ; j++) {
- if ( a[i] == a[j] && s[i] != s[j]) {
- ok = false ;
- break ;
- }
- }
- }
- if ( ok ) cout <<"YES\n";
- else cout <<"NO\n";
- }
- }
No comments