34232023-02-27 13:55:02CWMTáblajátékcpp17Partially correct 31/503ms4144 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 / 2;
int level = 0;
string ConvertToBits(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<int> move(vector<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] != INT_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] = INT_MAX;
			}
			else {
				base[i]--;
				return base;
			}
		}
		return base;
	}
	if (instructionNum == 4) {
		for (size_t i = 0; i < 16; i++)
		{
			if (base[i] == INT_MAX) {
				base[i] = 0;
			}
			else {
				base[i]++;
				return base;
			}
		}
	}
}
int main()
{
	vector<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
base31/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2056 KiB
3Partially correct1/33ms2300 KiB
4Accepted3/33ms2512 KiB
5Accepted3/33ms2756 KiB
6Partially correct1/33ms2892 KiB
7Accepted3/33ms2980 KiB
8Accepted3/33ms3076 KiB
9Partially correct1/33ms3292 KiB
10Partially correct1/33ms3372 KiB
11Accepted3/33ms3620 KiB
12Partially correct1/32ms3700 KiB
13Accepted4/42ms3700 KiB
14Partially correct1/43ms3712 KiB
15Accepted4/43ms3824 KiB
16Partially correct1/43ms3908 KiB
17Partially correct1/43ms4144 KiB