Submission #1871016


Source Code Expand

#include <bits/stdc++.h>
#define rank tipa_rank
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 1000000000
#define EPS 1e-6
#define free tipa_free
#define EPS2 1e-8
using namespace std;
const ll MOD = INF + 7;
using namespace std;
string s;
string ans;
int n , k;
deque<pair<char , int> > v;
bool swapped = false;
int main()
{
	//freopen("output.txt" , "w" , stdout);
	cin >> n >> k;
	cin >> s;
	for(int i = 0; i < s.size(); i++)
	{
		if(v.size() && v.back().first == s[i])
			v.back().second++;
		else
			v.push_back(mp(s[i] , 1));
	}
	if(n == 1)
	{
		cout << char(((s[0] - 'A') ^ (k % 2)) + 'A');
		return 0;
	}
	/*for(int i = 0; i < v.size(); i++)
		cout << v[i].first << " " << v[i].second << endl;
	cout << endl;*/
	int cnt = 0;
	while(k--)
	{

		if(v.front().first == 'A' + swapped)
		{
			v.front().second--;
			if(!v.front().second)
				v.pop_front();
			if(v.front().first == 'B' - swapped)
			{
				v.front().second++;
			}
			else
				v.push_front(mp('B' - swapped , 1));
		}
		else
		{
			//v.pop_front();
			v.front().second--;
			if(!v.front().second)
				v.pop_front();
			swapped = !swapped;
			if(v.back().first == swapped + 'A')
				v.back().second++;
			else
				v.push_back(mp(swapped + 'A' , 1));
		}
		/*cout << swapped << endl;
		for(int i = 0; i < v.size(); i++)
			cout << v[i].first << " " << v[i].second << endl;
		cout << endl;*/
		cnt++;
		if(cnt == 500000)
		{
			break;
		}
	}
	if(k % 2 && k > 0 && n % 2)
	{
		if(v.front().second == 1)
		{
			v.pop_front();
			v.front().second++;
		}
		else
		{
			v.front().second--;
			v.push_front(mp('A' + swapped , 1));
		}
	}

	//cout << v[0].first - 'A' << endl;
	for(int i = 0; i < v.size(); i++)
	{
		if(!swapped)
		{
			for(int j = 0; j < v[i].second; j++)
				cout << v[i].first;
		}
		else
		{
			for(int j = 0; j < v[i].second; j++)
				cout << char(((v[i].first - 'A') ^ 1) + 'A');
		}
	}
}

Submission Info

Submission Time
Task D - Half Reflector
User vjudge4
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1929 Byte
Status AC
Exec Time 22 ms
Memory 2308 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 50
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in5.txt, in543.txt, in557.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 1 ms 256 KB
in10.txt AC 18 ms 2308 KB
in11.txt AC 20 ms 2308 KB
in12.txt AC 18 ms 2308 KB
in13.txt AC 18 ms 2308 KB
in14.txt AC 19 ms 2308 KB
in15.txt AC 18 ms 2308 KB
in16.txt AC 19 ms 2308 KB
in17.txt AC 19 ms 2052 KB
in18.txt AC 19 ms 2308 KB
in19.txt AC 19 ms 2308 KB
in2.txt AC 9 ms 896 KB
in20.txt AC 19 ms 2052 KB
in21.txt AC 19 ms 2308 KB
in22.txt AC 21 ms 2308 KB
in23.txt AC 21 ms 2308 KB
in24.txt AC 22 ms 2308 KB
in25.txt AC 21 ms 2308 KB
in26.txt AC 21 ms 2308 KB
in27.txt AC 21 ms 2308 KB
in28.txt AC 18 ms 1796 KB
in29.txt AC 18 ms 1796 KB
in3.txt AC 19 ms 2052 KB
in30.txt AC 18 ms 1796 KB
in31.txt AC 19 ms 1924 KB
in32.txt AC 19 ms 1924 KB
in33.txt AC 19 ms 2052 KB
in34.txt AC 19 ms 2180 KB
in35.txt AC 19 ms 2180 KB
in36.txt AC 20 ms 2308 KB
in37.txt AC 20 ms 2308 KB
in38.txt AC 21 ms 2308 KB
in39.txt AC 18 ms 1796 KB
in4.txt AC 22 ms 2308 KB
in40.txt AC 18 ms 1796 KB
in41.txt AC 18 ms 1796 KB
in42.txt AC 18 ms 1796 KB
in5.txt AC 21 ms 2308 KB
in543.txt AC 18 ms 1412 KB
in557.txt AC 18 ms 1412 KB
in6.txt AC 6 ms 256 KB
in7.txt AC 19 ms 2052 KB
in8.txt AC 22 ms 2308 KB
in9.txt AC 19 ms 1924 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 6 ms 256 KB