34262023-02-27 14:03:52CWMTáblajátékcpp17Részben helyes 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base43/50
1Elfogadva0/03ms1808 KiB
2Elfogadva0/03ms2060 KiB
3Részben helyes1/33ms2220 KiB
4Elfogadva3/33ms2464 KiB
5Elfogadva3/33ms2708 KiB
6Elfogadva3/33ms2760 KiB
7Elfogadva3/32ms2752 KiB
8Elfogadva3/33ms2844 KiB
9Részben helyes1/33ms3096 KiB
10Elfogadva3/33ms2968 KiB
11Elfogadva3/33ms3072 KiB
12Elfogadva3/33ms3216 KiB
13Elfogadva4/43ms3380 KiB
14Elfogadva4/43ms3464 KiB
15Elfogadva4/43ms3708 KiB
16Elfogadva4/43ms3792 KiB
17Részben helyes1/43ms4024 KiB