Untitled
unknown
c_cpp
a year ago
2.2 kB
4
Indexable
Never
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(x...) #endif void solve() { int n; string s; cin >> n >> s; if (n & 1) { vector<int> cnteven(26), cntodd(26); for (int i = 0; i < n; i++) { if (i & 1) { cntodd[s[i] - 'a']++; } else { cnteven[s[i] - 'a']++; } } debug(cnteven); debug(cntodd); bool f = false; if ((n / 2) & 1) { for (int i = 0; i < 26; i++) { if (cnteven[i] & 1) { cout << "NO\n"; return; } if (cntodd[i] & 1) { if (f) { cout << "NO\n"; return; } else { f = true; } } } } else { for (int i = 0; i < 26; i++) { if (cntodd[i] & 1) { cout << "NO\n"; return; } if (cnteven[i] & 1) { if (f) { cout << "NO\n"; return; } else { f = true; } } } } if (f) { cout << "YES\n"; } else { cout << "NO\n"; } } else { vector<int> cnteven(26), cntodd(26); for (int i = 0; i < n; i++) { if (i & 1) { cntodd[s[i] - 'a']++; } else { cnteven[s[i] - 'a']++; } } for (int i = 0; i < 26; i++) { if (cntodd[i] != cnteven[i]) { cout << "NO\n"; return; } } cout << "YES\n"; } } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); int tests = 1; cin >> tests; while (tests--) { solve(); } return 0; }