QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#851363#5737. RemorseWeaRD276#AC ✓1ms3872kbC++201.8kb2025-01-10 18:11:432025-01-10 18:11:45

Judging History

This is the latest submission verdict.

  • [2025-01-10 18:11:45]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3872kb
  • [2025-01-10 18:11:43]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;

const int K = 26;

int solve()
{
	string str;
	string s = "";
	while ((cin >> str))
	{
		//cerr << "-_-\n";
		for (char ch: str)
		{
			if (ch >= 'A' && ch <= 'Z')
			{
				s += ch;
			}
			else if (ch >= 'a' && ch <= 'z')
			{
				s += (ch - 'a' + 'A');
			}
		}
	}
		
	//cerr << "s = " << s << '\n';	
	
	int n = sz(s);
	vector<int> cnt(K);
	FOR (i, 0, n)
		cnt[s[i] - 'A']++;
	
	vector<int> ord(K);
	iota(all(ord), 0);
	sort(all(ord), [&](int l, int r) -> bool
	{
		return cnt[l] > cnt[r];
	});
	
	vector<int> wei;
	FOR (len, 1, 8)
	{
		FOR (i, 0, 1 << len)
		{
			int cost = 0;
			FOR (j, 0, len)
			{
				if (i & 1 << j)
				{
					cost++;
				}
				else
				{
					cost += 3;
				}
			}
			cost += len - 1;
			wei.pb(cost);
		}
	}
	
	sort(all(wei));
	ll ans = 3 * (n - 1);
	FOR (i, 0, K)
	{
		//cerr << "wei = " << wei[i] << ' ' << "cnt = " << cnt[ord[i]] << '\n';
		ans += wei[i] * cnt[ord[i]];
	}
	cout << ans << '\n';
	
	return 0;
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int TET = 1;
	//cin >> TET;
	for (int i = 1; i <= TET; i++)
	{
		if (solve())
		{
			break;
		}
		#ifdef ONPC
			cerr << "_____________________________\n";
		#endif
	}
	#ifdef ONPC
		cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
	#endif
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3872kb

input:

ICPC

output:

17

result:

ok single line: '17'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

A

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

The quick brown dog jumps over the lazy fox.

output:

335

result:

ok single line: '335'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

Now is the time for all good men to come to the aid of their country. Fourscore and seven years ago our forefathers brought to this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal.

output:

1607

result:

ok single line: '1607'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for th...

output:

179819

result:

ok single line: '179819'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

QZciVKAgzAHHDgABJMhJvnKIwdSNqnnLPHnIAtGmsKUAxLBrzdLmsingreHuegdzTCnEMXLNFAILkhIuPvLzMefxpJIFNduQBnJAhsAkTRripMtFsfQaBxpyKnpvGEcgjClfxiuMLKuKwvfpbUwkeRsiEkcywOnsGmybWoWihMwhaRlAXOdoaZcsQSXfQfghItUnsEjvJhHAYEYSHRwidLDjIgKgkCkNaIXlylXOTAsUXeJwVMbiVHHvrQOmdlNjEFMvKCzlFCvtwwYZQoVjkoqSUZqCGIbMeCwNWOpuHHYG...

output:

347243

result:

ok single line: '347243'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

QbeEZdbSySOxwJrwsfzRlqnxuFvdFLukHwFtCUbFkbrOarmSeREicvBYfnUA

output:

549

result:

ok single line: '549'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

iMOMNqgkeWjFejBWIifAthLQOUkDwjvWwqIFRHvTupZmbmaMlGfqEKnQEQdRWNQfXgCDGsLKhjaLEcOrnZdHeeRxlaBiLBCnFKyJVmZbkRkkMePkWDczHEpTOkDQgHVyNVZEoqTTOBkLovaOeiqmuKtYBAPizRgMFDCVPthTCiLPItNkMpPCnffsvcwlxMnOxmBFbkHoNLCkuIqiTeaRSyvbycMCcZVzujKBDqwMGciKiTyrMjRsDrNDEDRBOrQwOUDiGCYdKKbGznSEpYMzwgZiyVzAWXKzNOjTUVamYoUR...

output:

21965

result:

ok single line: '21965'