34262023-02-27 14:03:52CWMTáblajátékcpp17Partially correct 43/503ms4024 KiB
// 0227.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <climits>
using namespace std;
using ll = long long;
int helpnum1 = INT_MAX;
int level = 0;
string ConvertToBits(unsigned int a) {
	ll divisor = INT_MAX;
	divisor++;
	string s = "";
	for (size_t i = 0; i < 32; i++)
	{
		if (a - divisor >= 0) {
			s += '1';
			a -= divisor;
		}
		else s += '0';
		divisor /= 2;
	}
	return s;
}
vector<unsigned int> move(vector<unsigned int> base, char instructionNum) {
	if (instructionNum == 0) {
		level++;
		base[16] *= 2;
		for (int i = 15; i >= 0; i--)
		{
			if (base[i] > helpnum1) {
				base[i] -= (helpnum1 + 1);
				base[i] *= 2;
				base[i + 1]++;
			}
			else base[i] *= 2;
		}
		return base;
	}
	if (instructionNum == 1) {
		level++;
		base[16] *= 2;
		for (int i = 15; i >= 0; i--)
		{
			if (base[i] > helpnum1) {
				base[i] -= (helpnum1+1);
				base[i] *= 2;
				base[i + 1]++;
			}
			else base[i] *= 2;
		}
		for (size_t i = 0; i < 16; i++)
		{
			if (base[i] != UINT_MAX) {
				base[i]++;
				break;
			}
			else base[i] = 0;
		}
		return base;
	}
	if (instructionNum == 2) {
		level--;
		base[0] /= 2;
		for (size_t i = 1; i < 17; i++)
		{
			if (base[i] % 2 == 1) base[i - 1] += (helpnum1 + 1);
			base[i] /= 2;
		}
		return base;
	}
	if (instructionNum == 3) {
		for (size_t i = 0; i < 17; i++)
		{
			if (base[i] == 0) {
				base[i] = UINT_MAX;
			}
			else {
				base[i]--;
				return base;
			}
		}
		return base;
	}
	if (instructionNum == 4) {
		for (size_t i = 0; i < 17; i++)
		{
			if (base[i] == UINT_MAX) {
				base[i] = 0;
			}
			else {
				base[i]++;
				return base;
			}
		}
	}
}
int main()
{
	vector<unsigned int> base(17);
	int num;
	cin >> num;
	for (size_t i = 0; i < num; i++)
	{
		int a;
		cin >> a;
		base = move(base, a);
	}
	string r = "";
	string re = "";
	for (size_t i = 0; i < 17; i++)
	{
		r += ConvertToBits(base[16 - i]);
	}
	for (size_t i = 0; i < r.size(); i++)
	{
		if (r[i] == '1') {
			re = r.substr(i, r.size() - 1);
			break;
		}
	}
	cout << level << "\n" << re;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/03ms1808 KiB
2Accepted0/03ms2060 KiB
3Partially correct1/33ms2220 KiB
4Accepted3/33ms2464 KiB
5Accepted3/33ms2708 KiB
6Accepted3/33ms2760 KiB
7Accepted3/32ms2752 KiB
8Accepted3/33ms2844 KiB
9Partially correct1/33ms3096 KiB
10Accepted3/33ms2968 KiB
11Accepted3/33ms3072 KiB
12Accepted3/33ms3216 KiB
13Accepted4/43ms3380 KiB
14Accepted4/43ms3464 KiB
15Accepted4/43ms3708 KiB
16Accepted4/43ms3792 KiB
17Partially correct1/43ms4024 KiB