Submission #1686548


Source Code Expand

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>
#include <numeric>

using namespace std;

long long n;
char s[500001];
long long z[500001];
vector<vector<long long>> v;

long long solve(const vector<long long> &a) {
  size_t a_len = a.size();
  long long l, r1, r2, l_prev, r1_prev, r2_prev;
  l_prev = 0;
  r1_prev = 0;
  r2_prev = a[0];
  for (long long i=1;i<(a_len-1);i++) {
    if (a[i] > 1) {
      // l:left pattern O
      l = max(l_prev + a[i] - 1, max(r1_prev, r2_prev));
      // r1:left pattern X, segment length not decrease
      r1 = max(l_prev + a[i], max(r1_prev, r2_prev));
      // r2:left pattern X, segment length decrease
      r2 = max(l_prev, max(r1_prev, r2_prev - 1)) + a[i];
    } else {
      // l:left pattern O
      l = max(l_prev, r1_prev);
      // r1:left pattern X, segment length not decrease
      r1 = max(l_prev + a[i], r2_prev);
      // r2:left pattern X, segment length decrease
      r2 = max(l_prev, r1_prev) + a[i];
    }
    l_prev = l;
    r1_prev = r1;
    r2_prev = r2;
  }
  l = l_prev + a[a_len-1] ;
  r1 = r1_prev;
  r2 = r2_prev;
  return(max(l, max(r1, r2)));
}

int main(){
  cin >> n;
  cin >> s;
  long long l1 = 0;
  long long r1 = 0;
  long long c1 = 0;
  long long ioi = 0;
  long long tot = 0;
  vector<long long> tmpv;
  for (long long i=0;i<n;i++) {
    if (s[i] == '1') {
      c1++;
    } else {
      if (c1==0) {
	if (tmpv.size()>0)
	if (tmpv.size()>1) {
	  tot += solve(tmpv);
	}
	tmpv.clear();
      } else if (c1>0) {
	tmpv.push_back(c1);
      }
      c1 = 0;
    }
  }
  if (c1>0) 
    tmpv.push_back(c1);
  if (tmpv.size() > 1)
    tot += solve(tmpv);
  cout << tot << endl;
}

Submission Info

Submission Time
Task D - 101 to 010
User ntgo
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1828 Byte
Status AC
Exec Time 19 ms
Memory 2560 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 9 ms 2304 KB
001.txt AC 6 ms 2304 KB
002.txt AC 9 ms 2304 KB
003.txt AC 6 ms 2304 KB
004.txt AC 8 ms 2304 KB
005.txt AC 10 ms 2304 KB
006.txt AC 3 ms 2304 KB
007.txt AC 5 ms 2304 KB
008.txt AC 2 ms 2304 KB
009.txt AC 13 ms 2432 KB
010.txt AC 17 ms 2560 KB
011.txt AC 17 ms 2560 KB
012.txt AC 18 ms 2560 KB
013.txt AC 18 ms 2560 KB
014.txt AC 18 ms 2560 KB
015.txt AC 19 ms 2560 KB
016.txt AC 19 ms 2560 KB
017.txt AC 18 ms 2560 KB
018.txt AC 18 ms 2560 KB
019.txt AC 17 ms 2560 KB
020.txt AC 16 ms 2560 KB
021.txt AC 17 ms 2560 KB
022.txt AC 19 ms 2560 KB
023.txt AC 16 ms 2560 KB
024.txt AC 16 ms 2560 KB
025.txt AC 16 ms 2560 KB
026.txt AC 16 ms 2560 KB
027.txt AC 16 ms 2560 KB
028.txt AC 16 ms 2560 KB
029.txt AC 16 ms 2560 KB
030.txt AC 17 ms 2560 KB
031.txt AC 16 ms 2560 KB
032.txt AC 16 ms 2560 KB
033.txt AC 16 ms 2560 KB
034.txt AC 17 ms 2560 KB
035.txt AC 17 ms 2560 KB
036.txt AC 17 ms 2560 KB
example0.txt AC 2 ms 2304 KB
example1.txt AC 2 ms 2304 KB