Submission #1691347


Source Code Expand

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	string s;
	cin >> s;
	s += "00";
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == '1') {
			for (int j = i; j < N; j++) {
				if (s[j + 1] == s[j + 2] && s[j + 1] == '0') {
					int box = 0;
					vector<int>place;
					for (int k = i; k <= j; k++) {
						if (s[k] == '0') {
							box++;
							place.push_back(k);
						}
					}
					if (box == 0) {
						i = j + 1;
						break;
					}
					if (box == 1) {
						ans += max(j - place[0], place[0] - i);
						//	cout << ans << endl;
						i = j + 1;
						break;
					}
					vector<int>bf(box);
					vector<int>nx(box);
					bf[0] = place[0] - i;
					nx[0] = place[1] - place[0] - 1;
					for (int k = 1; k < box - 1; k++) {
						bf[k] = nx[k - 1];
						nx[k] = place[k + 1] - place[k] - 1;
					}
					bf[box - 1] = nx[box - 2];
					nx[box - 1] = j - place[box - 1];
					vector<vector<int>>dp(box, vector<int>(5, 0));
					if (bf[0] > 1) {
						dp[0][0] = bf[0];
					}
					else {
						dp[0][1] = bf[0];
					}
					dp[0][2] = nx[0];
					if (nx[0] > 1) {
						dp[0][3] = nx[0] - 1;
					}
					for (int k = 1; k < box; k++) {
						if (nx[k] > 1) {
							dp[k][0] = max({ dp[k - 1][0] - 1 + bf[k], dp[k - 1][4] + bf[k] ,dp[k - 1][3] + 1 });
						}
						else {
							dp[k][1] = max(max(dp[k - 1][0] - 1, dp[k - 1][4]) + bf[k], dp[k - 1][3] + 1);
						}
						dp[k][2] = max({ dp[k - 1][0],dp[k - 1][3],dp[k - 1][4] }) + nx[k];
						if (nx[k] > 1) {
							dp[k][3] = dp[k][2] - 1;
						}
						dp[k][4] = max({ dp[k - 1][0],dp[k - 1][1],dp[k - 1][2],dp[k - 1][3],dp[k - 1][4] });
					}
					ans += max({ dp[box - 1][0],dp[box - 1][1],dp[box - 1][2],dp[box - 1][3],dp[box - 1][4] });
					//	cout << ans << endl;
					i = j + 1;
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 101 to 010
User olphe
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2341 Byte
Status WA
Exec Time 16 ms
Memory 1172 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 18
WA × 21
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 720 KB
001.txt WA 3 ms 512 KB
002.txt WA 4 ms 720 KB
003.txt WA 4 ms 512 KB
004.txt WA 6 ms 592 KB
005.txt WA 9 ms 720 KB
006.txt WA 3 ms 384 KB
007.txt WA 5 ms 512 KB
008.txt WA 2 ms 256 KB
009.txt WA 5 ms 788 KB
010.txt AC 4 ms 1172 KB
011.txt WA 5 ms 1172 KB
012.txt WA 6 ms 1172 KB
013.txt WA 9 ms 1172 KB
014.txt WA 12 ms 1172 KB
015.txt WA 14 ms 1172 KB
016.txt WA 16 ms 1172 KB
017.txt WA 15 ms 1172 KB
018.txt WA 13 ms 1172 KB
019.txt WA 9 ms 1172 KB
020.txt AC 4 ms 1172 KB
021.txt AC 4 ms 1172 KB
022.txt AC 4 ms 1172 KB
023.txt AC 4 ms 1172 KB
024.txt AC 4 ms 1172 KB
025.txt AC 4 ms 1172 KB
026.txt AC 4 ms 1172 KB
027.txt AC 4 ms 1172 KB
028.txt AC 4 ms 1172 KB
029.txt AC 4 ms 1172 KB
030.txt AC 4 ms 1172 KB
031.txt AC 4 ms 1172 KB
032.txt AC 4 ms 1172 KB
033.txt AC 5 ms 1172 KB
034.txt WA 5 ms 1172 KB
035.txt WA 6 ms 1172 KB
036.txt WA 7 ms 1172 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB