Submission #1666434


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int MX = 500000;

int solve(vector<int>& a) {
	if (a.empty()) return 0;
	
	int f = 0, g = -2 * MX, h = -2 * MX;
	for (int x : a) {
		int ff = max(max(f, h), g + x);
		int gg = max(f, g + x - 1);
		if (x > 1) gg = max(gg, h);
		int hh = max(f, max(g, h - 1)) + x;
		
		f = ff;
		g = gg;
		h = hh;
	}
	
	return max(f, g);
}

char s[MX + 2];

int main() {
	int n;
	ignore = scanf("%d %s", &n, s);
	s[n] = s[n + 1] = '0';
	n += 2;
	
	int ans = 0;
	vector<int> a;
	for (int i = 0, o = 0, z = 0; i < n; i++) {
		if (s[i] == '1') {
			o++;
			z = 0;
		}
		else {
			if (o != 0) {
				a.push_back(o);
				o = 0;
			}
			z++;
			if (z == 2) {
				ans += solve(a);
				a.clear();
				o = z = 0;
			}
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Submission Info

Submission Time
Task D - 101 to 010
User Alex_2oo8
Language C++14 (GCC 5.4.1)
Score 700
Code Size 847 Byte
Status AC
Exec Time 6 ms
Memory 768 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 39
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 3 ms 512 KB
001.txt AC 2 ms 384 KB
002.txt AC 3 ms 512 KB
003.txt AC 2 ms 384 KB
004.txt AC 3 ms 384 KB
005.txt AC 4 ms 512 KB
006.txt AC 2 ms 256 KB
007.txt AC 2 ms 384 KB
008.txt AC 1 ms 256 KB
009.txt AC 3 ms 640 KB
010.txt AC 4 ms 768 KB
011.txt AC 4 ms 768 KB
012.txt AC 5 ms 768 KB
013.txt AC 5 ms 768 KB
014.txt AC 6 ms 768 KB
015.txt AC 6 ms 768 KB
016.txt AC 6 ms 768 KB
017.txt AC 5 ms 768 KB
018.txt AC 5 ms 768 KB
019.txt AC 4 ms 768 KB
020.txt AC 4 ms 768 KB
021.txt AC 4 ms 768 KB
022.txt AC 4 ms 768 KB
023.txt AC 4 ms 768 KB
024.txt AC 4 ms 768 KB
025.txt AC 4 ms 768 KB
026.txt AC 4 ms 768 KB
027.txt AC 4 ms 768 KB
028.txt AC 4 ms 768 KB
029.txt AC 4 ms 768 KB
030.txt AC 4 ms 768 KB
031.txt AC 4 ms 768 KB
032.txt AC 4 ms 768 KB
033.txt AC 4 ms 768 KB
034.txt AC 4 ms 768 KB
035.txt AC 4 ms 768 KB
036.txt AC 4 ms 768 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB