結果

問題 No.884 Eat and Add
ユーザー amaridekinai
提出日時 2019-09-13 22:59:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 1,312 ms
コンパイル使用メモリ 159,852 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-04 10:15:11
合計ジャッジ時間 1,767 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 2 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string S; cin >> S; int N= (int) S.size();
  
  int head = 0; int tail = 0;
  
  string T = "";
  
  while( head < N){
    if( S[head] == '0'){ head++; tail++; T += '0';}
    else{
     while( tail < N && S[tail] == '1'){ tail++;}
     T += '1';
     head = tail;}
     } 
 

   
   N = (int) T.size();
   head = 0; tail = 0; 

   string  U = "";
   int cnt = 0;
   while( head < N){
     int res = 0;
     if( T[head] == '1'){ head++; tail++; U += '1';}
     else{
       while( tail < N && T[tail] == '0'){ res++; tail++;}
       if( res > 1){ U += '0';} else{ cnt++;}
     }
     head = tail;
   }
  
  head = 0; tail = 0; N = (int) U.size();
  while( head < N){
    if( U[tail] == '0'){ head++; tail++;}
    else{
      while( tail < N && U[tail] == '1'){ tail++;}
         cnt+= 2;}
      
      head = tail;
  }
  
  cout << cnt << endl;
     
    
  return 0;}
0