結果

問題 No.884 Eat and Add
ユーザー ateate
提出日時 2019-09-13 22:47:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,746 bytes
コンパイル時間 2,063 ms
コンパイル使用メモリ 202,216 KB
実行使用メモリ 5,276 KB
最終ジャッジ日時 2023-09-17 14:56:00
合計ジャッジ時間 2,839 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 6 ms
4,756 KB
testcase_04 AC 6 ms
4,756 KB
testcase_05 AC 6 ms
4,760 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 5 ms
5,276 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   18 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  string s;
  cin>>s;
  ll n=s.size();

  vector<ll> a;
  ll num=1;
  rep(i,n-1){
    if(s[i]!=s[i+1]){
      a.push_back(num);
      num=1;
    }
    else num++;
  }
  a.push_back(num);
  //for(auto& x:a)x=min(x,2LL);
  
  ll m=a.size();
  vector<ll> b,c;
  b.push_back(a[0]);
  c.push_back(0);
  for(ll i=1;i<m-1;i+=2){
    if(a[i]==1){
      b[b.size()-1]+=a[i+1]+1;
      c[c.size()-1]++;
    }
    else{
      b.push_back(a[i+1]);
      c.push_back(0);
    }
    //cout<<i<<" "<<b.size()<<endl;
  }

  ll ans=0,k=b.size();
  rep(i,k){
    if(c[i]==0)b[i]=min(b[i],2LL);
    ans+=min({b[i],c[i]+2,b[i]-c[i]});
  }
  ll g=0;
  for(auto c:s)if(c=='1')g++;
  cout<<min(ans,g)<<endl;

  //for(auto x:a)cout<<x<<" ";cout<<endl;
  //for(auto x:b)cout<<x<<" ";cout<<endl;
  //for(auto x:c)cout<<x<<" ";cout<<endl;


}
0