137172025-01-08 13:49:50Leventusz09Táblajátékcpp17Accepted 50/501ms500 KiB
#include <iostream>
#include <bitset>
#include <string>

using namespace std;

void add(bitset<501> &bs, bool n = false) {
	int c = 0;
	if(!n)
		while(true){
			if (bs[c]) {
				bs.reset(c);
				c++;
			}else{
				bs.set(c);
				break;
			}
		}
	else
		while (true){
			if (bs[c]) {
				bs.reset(c);
				break;
			}
			else {
				bs.set(c);
				c++;
			}
		}
}

int main() {
	int K;
	cin >> K;

	int lv = 0;
	bitset<501> p;

	for (int i = 0, s; i < K; i++) {
		cin >> s;
		switch (s){
		case 0:	lv++;	p<<=1;	break;
		case 1:	lv++;	p<<= 1;	p.set(0);  break;
		case 2:	lv--;	p>>= 1;	break;
		case 3: add(p, 1);	break;
		case 4:	add(p);	break;
		}
	}
	for (int i = 500; i >= 0; i--) {
		if (p[i]) {
			cout << lv << "\n" << p.to_string().substr(500 - i) << "\n";
			return 0;
		}
	}
	cout << lv << "\n" << 0 << "\n";
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms500 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/31ms316 KiB
9Accepted3/31ms380 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms356 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Accepted4/41ms316 KiB
16Accepted4/41ms316 KiB
17Accepted4/41ms316 KiB