Submission #1670897
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
vector<int> from(n), to(n);
to[0] = (s[0] == '1');
from[n - 1] = (s[n - 1] == '1');
for (int i = 1; i < n; i++) to[i] = (s[i] == '1') ? to[i - 1] + 1 : 0;
for (int i = n - 2; i >= 0; i--) from[i] = (s[i] == '1') ? from[i + 1] + 1 : 0;
vector<vector<int>> blocks(n);
for (int i = 1; i < n - 1; i++) {
if (s[i] == '0' && s[i - 1] == '1' && s[i + 1] == '1') {
for (int j = 1; j <= to[i - 1]; j++) {
blocks[i + 1].push_back(j);
}
for (int j = 1; j <= from[i + 1]; j++) {
blocks[i + j].push_back(j);
}
}
}
vector<int> dp(n);
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1];
for (int b : blocks[i]) {
if (i - b - 2 >= 0) dp[i] = max(dp[i], dp[i - b - 2] + b);
else dp[i] = max(dp[i], b);
}
}
cout << dp[n - 1] << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - 101 to 010 |
| User | pauljgblt |
| Language | C++14 (GCC 5.4.1) |
| Score | 700 |
| Code Size | 1055 Byte |
| Status | AC |
| Exec Time | 47 ms |
| Memory | 36636 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 700 / 700 | ||||
| Status |
|
|
| 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 | 7 ms | 9364 KiB |
| 001.txt | AC | 5 ms | 5200 KiB |
| 002.txt | AC | 9 ms | 9236 KiB |
| 003.txt | AC | 8 ms | 5712 KiB |
| 004.txt | AC | 11 ms | 7888 KiB |
| 005.txt | AC | 17 ms | 11284 KiB |
| 006.txt | AC | 5 ms | 2816 KiB |
| 007.txt | AC | 11 ms | 6736 KiB |
| 008.txt | AC | 2 ms | 896 KiB |
| 009.txt | AC | 36 ms | 26388 KiB |
| 010.txt | AC | 12 ms | 18460 KiB |
| 011.txt | AC | 14 ms | 18460 KiB |
| 012.txt | AC | 17 ms | 18972 KiB |
| 013.txt | AC | 22 ms | 19740 KiB |
| 014.txt | AC | 27 ms | 20892 KiB |
| 015.txt | AC | 33 ms | 22428 KiB |
| 016.txt | AC | 36 ms | 24348 KiB |
| 017.txt | AC | 40 ms | 26652 KiB |
| 018.txt | AC | 43 ms | 29468 KiB |
| 019.txt | AC | 47 ms | 32796 KiB |
| 020.txt | AC | 13 ms | 18460 KiB |
| 021.txt | AC | 21 ms | 23188 KiB |
| 022.txt | AC | 29 ms | 27288 KiB |
| 023.txt | AC | 38 ms | 32412 KiB |
| 024.txt | AC | 46 ms | 35736 KiB |
| 025.txt | AC | 42 ms | 34076 KiB |
| 026.txt | AC | 45 ms | 35868 KiB |
| 027.txt | AC | 46 ms | 35868 KiB |
| 028.txt | AC | 46 ms | 36124 KiB |
| 029.txt | AC | 46 ms | 36380 KiB |
| 030.txt | AC | 44 ms | 36508 KiB |
| 031.txt | AC | 44 ms | 36636 KiB |
| 032.txt | AC | 45 ms | 36636 KiB |
| 033.txt | AC | 46 ms | 36508 KiB |
| 034.txt | AC | 46 ms | 36124 KiB |
| 035.txt | AC | 47 ms | 35484 KiB |
| 036.txt | AC | 47 ms | 34076 KiB |
| example0.txt | AC | 1 ms | 256 KiB |
| example1.txt | AC | 1 ms | 256 KiB |