結果

問題 No.884 Eat and Add
ユーザー amaridekinaiamaridekinai
提出日時 2019-09-13 22:59:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 145,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 15:05:14
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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