34242023-02-27 14:01:54CWMTáblajátékcpp17Partially correct 43/503ms4092 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[15] *= 2;
		for (int i = 14; 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[15] *= 2;
		for (int i = 14; 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 < 15; 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 < 16; 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 < 16; 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 < 16; i++)
		{
			if (base[i] == UINT_MAX) {
				base[i] = 0;
			}
			else {
				base[i]++;
				return base;
			}
		}
	}
}
int main()
{
	vector<unsigned int> base(16);
	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 < 16; i++)
	{
		r += ConvertToBits(base[15 - 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/03ms2024 KiB
3Partially correct1/33ms2256 KiB
4Accepted3/33ms2440 KiB
5Accepted3/33ms2672 KiB
6Accepted3/33ms2796 KiB
7Accepted3/33ms3008 KiB
8Accepted3/33ms3224 KiB
9Partially correct1/33ms3360 KiB
10Accepted3/33ms3488 KiB
11Accepted3/33ms3608 KiB
12Accepted3/33ms3820 KiB
13Accepted4/43ms4004 KiB
14Accepted4/43ms4084 KiB
15Accepted4/42ms4084 KiB
16Accepted4/43ms4092 KiB
17Partially correct1/43ms4088 KiB