QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497168 | #8829. Aibohphobia | kmiao | WA | 0ms | 3784kb | C++14 | 2.8kb | 2024-07-28 20:32:24 | 2024-07-28 20:32:24 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include "/home/kmiao/codes/debugtemplate.cpp"
#else
#define debug(...)
#endif
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define endl '\n'
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const ll INF = (ll)1e18;
class HashedString {
private:
// change M and B if you want
static const ll M = (1LL << 61) - 1;
static const ll B;
// pow[i] contains B^i % M
static vector<ll> pow;
// p_hash[i] is the hash of the first i characters of the given string
vector<ll> p_hash;
__int128 mul(ll a, ll b) { return (__int128)a * b; }
ll mod_mul(ll a, ll b) { return mul(a, b) % M; }
public:
HashedString(const string &s) : p_hash(s.size() + 1) {
while (pow.size() < s.size()) { pow.push_back(mod_mul(pow.back(), B)); }
p_hash[0] = 0;
for (int i = 0; i < s.size(); i++) {
p_hash[i + 1] = (mul(p_hash[i], B) + s[i]) % M;
}
}
ll get_hash(int start, int end) {
ll raw_val =
p_hash[end + 1] - mod_mul(p_hash[start], pow[end - start + 1]);
return (raw_val + M) % M;
}
};
mt19937 RNG((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
vector<ll> HashedString::pow = {1};
const ll HashedString::B = uniform_int_distribution<ll>(0, M - 1)(RNG);
void solve() {
string s;
cin >> s;
vi cnt(26, 0);
int n = s.length();
int typ = 0;
for (int i = 0; i < n; i++) {
if (cnt[s[i]-'a'] == 0)
typ++;
cnt[s[i]-'a']++;
}
if (typ == 1) {
if (n == 1) cout << "YES" << endl << s << endl;
else cout << "NO" << endl;
}
else if (typ == 2) {
char c;
bool found = false;
for (int i = 0; i < n; i++) {
if (cnt[s[i] - 'a'] == 1) {
c = s[i];
cout << "YES" << endl;
cout << c;
cnt[c-'a']--;
found = true;
}
}
if (found) {
for (int i = 0; i < n; i++) {
if (s[i] != c) cout << s[i];
}
cout << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "YES" << endl;
for (int i = 0; i < 26; i++) {
if (cnt[i]) {
char c = 'a' + i;
cout << c;
cnt[i]--;
}
}
for (int i = 0; i < 26; i++) {
char c = 'a' + i;
for (int j = 0; j < cnt[i]; j++)
cout << c;
}
cout << endl;
}
}
int main() {
// read read read
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
// read the thing at the bottom
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
input:
5 a sos abba icpc tenet
output:
YES a YES oss NO YES cipc YES entet
result:
ok Correct (5 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
18 qnx oooo tvttj zzzzz pvlne iijt hjhjj loo hh uq mgvgv ewwe iii kykk o mmumm aetvv xntl
output:
YES nqx NO YES jtvtt NO YES elnpv YES ijti NO YES loo NO YES uYES qu YES gmvgv NO NO YES ykkk YES o YES ummmm YES aetvv YES lntx
result:
wrong answer Not a permutation (test case 10)