Submission #64777990


Source Code Expand

#include <iostream>
using namespace std;
int n, k, K = 0, cnt;
char s[200005];
int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> s[i];
	
	for(int i = 1; i <= n; i++) {
		if (s[i] == 'o') {
			k--; // 需要新增的'o'的数量
			s[i-1] = '.';
			s[i+1] = '.';
		}
	}
	if (k == 0) {
		for(int i = 1; i <= n; i++) {
			if (s[i] == '?') s[i] = '.';
			cout << s[i];
		}
		return 0;
	}
	for(int i = 1; i <= n; i++) {
		if (s[i] == '?') cnt++;
		else {
			K += (cnt+1) / 2; // 最多增加的'o'的数量
			cnt = 0;
		}
	}
	K += (cnt+1) / 2;
	if (K == k) { // 唯一填写方案
		cnt = 0;
		for(int i = 1; i <= n; i++) {
			if (s[i] == '?') cnt++;
			else {
				if (cnt % 2 == 1) {
					int j = i-1;
					for(int w = 1; w <= cnt; w++) {
						if (w % 2 == 1) s[j] = 'o';
						else s[j] = '.';
						j--;
					}
				}
				cnt = 0;
			}
		}
		if (cnt % 2 == 1) {
			int j = n;
			for(int w = 1; w <= cnt; w++) {
				if (w % 2 == 1) s[j] = 'o';
				else s[j] = '.';
				j--;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		cout << s[i];
	}
	return 0;
}

Submission Info

Submission Time
Task D - Logical Filling
User gobywind
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1121 Byte
Status AC
Exec Time 11 ms
Memory 3868 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 43
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3636 KiB
00_sample_01.txt AC 1 ms 3524 KiB
00_sample_02.txt AC 1 ms 3452 KiB
01_random_00.txt AC 4 ms 3664 KiB
01_random_01.txt AC 11 ms 3832 KiB
01_random_02.txt AC 10 ms 3676 KiB
01_random_03.txt AC 1 ms 3608 KiB
01_random_04.txt AC 5 ms 3548 KiB
01_random_05.txt AC 5 ms 3504 KiB
01_random_06.txt AC 8 ms 3792 KiB
01_random_07.txt AC 8 ms 3596 KiB
01_random_08.txt AC 1 ms 3460 KiB
01_random_09.txt AC 8 ms 3816 KiB
01_random_10.txt AC 10 ms 3744 KiB
01_random_11.txt AC 10 ms 3684 KiB
01_random_12.txt AC 11 ms 3664 KiB
01_random_13.txt AC 10 ms 3796 KiB
01_random_14.txt AC 10 ms 3636 KiB
01_random_15.txt AC 10 ms 3740 KiB
01_random_16.txt AC 10 ms 3676 KiB
01_random_17.txt AC 10 ms 3744 KiB
01_random_18.txt AC 10 ms 3684 KiB
01_random_19.txt AC 11 ms 3804 KiB
01_random_20.txt AC 10 ms 3708 KiB
01_random_21.txt AC 10 ms 3672 KiB
01_random_22.txt AC 10 ms 3868 KiB
01_random_23.txt AC 1 ms 3636 KiB
01_random_24.txt AC 1 ms 3452 KiB
01_random_25.txt AC 1 ms 3488 KiB
01_random_26.txt AC 1 ms 3432 KiB
01_random_27.txt AC 10 ms 3664 KiB
01_random_28.txt AC 10 ms 3796 KiB
01_random_29.txt AC 10 ms 3664 KiB
01_random_30.txt AC 10 ms 3712 KiB
01_random_31.txt AC 10 ms 3740 KiB
01_random_32.txt AC 10 ms 3676 KiB
01_random_33.txt AC 11 ms 3644 KiB
01_random_34.txt AC 10 ms 3724 KiB
01_random_35.txt AC 11 ms 3728 KiB
01_random_36.txt AC 11 ms 3664 KiB
01_random_37.txt AC 10 ms 3644 KiB
01_random_38.txt AC 10 ms 3644 KiB
01_random_39.txt AC 10 ms 3676 KiB