34112023-02-27 13:28:46CWMTáblajátékcpp17Részben helyes 29/503ms4172 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;
				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;
				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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base29/50
1Elfogadva0/03ms1816 KiB
2Elfogadva0/03ms2004 KiB
3Részben helyes1/33ms2404 KiB
4Elfogadva3/33ms2444 KiB
5Elfogadva3/33ms2552 KiB
6Részben helyes1/33ms2796 KiB
7Elfogadva3/33ms3016 KiB
8Részben helyes1/33ms2940 KiB
9Részben helyes1/33ms3112 KiB
10Részben helyes1/33ms3324 KiB
11Elfogadva3/33ms3536 KiB
12Részben helyes1/33ms3776 KiB
13Elfogadva4/43ms3768 KiB
14Részben helyes1/43ms3832 KiB
15Elfogadva4/43ms3948 KiB
16Részben helyes1/43ms4172 KiB
17Részben helyes1/43ms4120 KiB