QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497173#8829. AibohphobiakmiaoCompile Error//C++202.8kb2024-07-28 20:35:442024-07-28 20:35:44

Judging History

你现在查看的是最新测评结果

  • [2024-07-28 20:35:44]
  • 评测
  • [2024-07-28 20:35:44]
  • 提交

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];
				cnt[c-'a']--;
				found = true;
			}
		}
		if (found) {
			cout << YES << endl;
			cout << c;
			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
*/

詳細信息

answer.code: In function ‘void solve()’:
answer.code:90:33: error: ‘YES’ was not declared in this scope
   90 |                         cout << YES << endl;
      |                                 ^~~