提出 #39214632


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ull unsigned LL
#define db double
#define ldb long double
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define complete_unique(x) (x).erase(unique(all(x)),(x).end());
#define fr(x) freopen(x,"r",stdin);
#define fw(x) freopen(x,"w",stdout);
#define mst(x,a) memset(x,a,sizeof(x));
#define lowbit(x) ((x) & (-(x)))
#define ex0 exit(0);
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define inf 0x3f3f3f3f
#define yes std::cout << "Yes\n"
#define no std::cout << "No\n"
//#pragma GCC optimize(2) // if CE please delete
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
const int base1 = 131;
const int base2 = 13331;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
typedef pair<int, int> hashv;
hashv operator + (hashv a, hashv b) {
	int c1 = a.fi + b.fi, c2 = a.se + b.se;
	if (c1 >= mod1) c1 -= mod1;
	if (c2 >= mod2) c2 -= mod2;
	return mp(c1, c2);
}
hashv operator - (hashv a, hashv b) {
	int c1 = a.fi - b.fi, c2 = a.se - b.se;
	if (c1 < 0) c1 = c1 + mod1;
	if (c2 < 0) c2 = c2 + mod2;
	return mp(c1, c2);
}
hashv operator * (hashv a, hashv b) {
	return mp(1ll * a.fi * b.fi % mod1, 1ll * a.second * b.second % mod2);
}
template <typename T>
inline T qpow(T a, int b, const int mod = 1e9 + 7) //quick_pow
{
	T res = 1;
	while (b)
	{
		if (b & 1) res = (1ll * res * a) % mod;
		a = (1ll * a * a) % mod;
		b >>= 1;
	}
	return res;
}
LL gcd(LL a, LL b)
{
	return b == 0 ? a : gcd(b, a % b);
}
inline char gc() {
	static char buf[1000000], * p1 = buf, * p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
inline T read()
{
	T x = 0, flag = 1;
	char c = gc();
	while (c < '0' || c > '9')
	{
		if (c == '-') flag = -1;
		c = gc();
	}
	while (c >= '0' && c <= '9')
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = gc();
	}
	return x * flag;
}
template <typename T>
inline void pr(T x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9) pr(x / 10);
	putchar(x % 10 + '0');
}
const int N = 2E6 + 10;
const int M = 4e6 + 10;
int a[N];
int len[N];
int n, m, k;
string s;
int main()
{
	IOS;
	cin >> n >> k;
	cin >> s;
	s = '/' + s + '/';
	int c = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'X') c++;
	}
	if (k > c) {
		for (int i = 1; i <= n; i++) s[i] = (s[i] == 'X') ? 'Y' : 'X';
		k = n - k;
	}
	if (c == n) {
		cout << min(k - 1, 0);
		return 0;
	}
	int i = 1;
	for (; i <= n; i++) if (s[i] == 'Y') break;
	for (int i = 1; i <= n;) {
		int j = i + 1;
		while (j <= n && s[j] == 'X') {
			j++;
		}
		if (s[j] == 'Y' && s[i] == 'Y') {
			len[j - i - 1]++;
		}
		i = j;
	}
	int ans = 0;
	for (int i = 1; i <= n && k > 0; i++) {
		while (len[i] > 0 && k > 0) {
			if (k >= i) {
				k -= i;
				len[i]--;
				ans += i + 1;
			}
			else {
				ans += k;
				k = 0;
			}
		}
	}
	if (k > 0) ans += k;
	for (int i = 1; i <= n; i++) if (s[i] == s[i - 1] && s[i] == 'Y') ans++;
	cout << ans << endl;
	return 0;
}

提出情報

提出日時
問題 B - XYYYX
ユーザ tulsy_
言語 C++ (GCC 9.2.1)
得点 0
コード長 3299 Byte
結果 WA
実行時間 10 ms
メモリ 3856 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 500
結果
AC × 2
AC × 44
WA × 8
セット名 テストケース
Sample 00-sample-001.txt, 00-sample-002.txt
All 00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt, 01-044.txt, 01-045.txt, 01-046.txt, 01-047.txt, 01-048.txt, 01-049.txt, 01-050.txt
ケース名 結果 実行時間 メモリ
00-sample-001.txt AC 10 ms 3584 KiB
00-sample-002.txt AC 2 ms 3532 KiB
01-001.txt AC 2 ms 3536 KiB
01-002.txt WA 2 ms 3520 KiB
01-003.txt AC 2 ms 3516 KiB
01-004.txt AC 2 ms 3516 KiB
01-005.txt AC 2 ms 3488 KiB
01-006.txt WA 2 ms 3420 KiB
01-007.txt AC 2 ms 3460 KiB
01-008.txt AC 5 ms 3532 KiB
01-009.txt AC 2 ms 3472 KiB
01-010.txt WA 2 ms 3456 KiB
01-011.txt AC 7 ms 3720 KiB
01-012.txt AC 10 ms 3620 KiB
01-013.txt AC 7 ms 3732 KiB
01-014.txt AC 5 ms 3688 KiB
01-015.txt AC 4 ms 3732 KiB
01-016.txt AC 4 ms 3680 KiB
01-017.txt AC 4 ms 3688 KiB
01-018.txt AC 5 ms 3844 KiB
01-019.txt AC 8 ms 3788 KiB
01-020.txt AC 6 ms 3816 KiB
01-021.txt AC 4 ms 3692 KiB
01-022.txt AC 4 ms 3852 KiB
01-023.txt AC 4 ms 3844 KiB
01-024.txt AC 4 ms 3720 KiB
01-025.txt AC 6 ms 3792 KiB
01-026.txt AC 7 ms 3680 KiB
01-027.txt AC 9 ms 3784 KiB
01-028.txt AC 6 ms 3848 KiB
01-029.txt AC 5 ms 3784 KiB
01-030.txt AC 5 ms 3788 KiB
01-031.txt AC 5 ms 3856 KiB
01-032.txt AC 5 ms 3676 KiB
01-033.txt AC 5 ms 3788 KiB
01-034.txt AC 6 ms 3728 KiB
01-035.txt AC 4 ms 3720 KiB
01-036.txt AC 5 ms 3808 KiB
01-037.txt AC 7 ms 3724 KiB
01-038.txt AC 4 ms 3692 KiB
01-039.txt AC 7 ms 3852 KiB
01-040.txt AC 6 ms 3744 KiB
01-041.txt AC 5 ms 3812 KiB
01-042.txt WA 4 ms 3852 KiB
01-043.txt WA 4 ms 3676 KiB
01-044.txt AC 4 ms 3848 KiB
01-045.txt WA 8 ms 3856 KiB
01-046.txt WA 6 ms 3792 KiB
01-047.txt AC 5 ms 3740 KiB
01-048.txt WA 3 ms 3856 KiB
01-049.txt AC 2 ms 3592 KiB
01-050.txt AC 2 ms 3548 KiB