結果

問題 No.2142 Segment Zero
ユーザー twooimp2twooimp2
提出日時 2024-02-23 18:01:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 6,447 ms
コンパイル使用メモリ 305,056 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 18:01:08
合計ジャッジ時間 7,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 8 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 8 ms
6,676 KB
testcase_04 AC 9 ms
6,676 KB
testcase_05 AC 9 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 WA -
testcase_08 AC 8 ms
6,676 KB
testcase_09 WA -
testcase_10 AC 8 ms
6,676 KB
testcase_11 AC 8 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 8 ms
6,676 KB
testcase_14 AC 8 ms
6,676 KB
testcase_15 AC 8 ms
6,676 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 5 ms
6,676 KB
testcase_21 WA -
testcase_22 AC 6 ms
6,676 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 4 ms
6,676 KB
testcase_29 AC 5 ms
6,676 KB
testcase_30 AC 6 ms
6,676 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 7 ms
6,676 KB
testcase_36 AC 4 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

void rle(string s, vector<pair<char, ll>> &vec){
  ll cnt=1;
  for(ll i=1;i<(ll)s.size();i++){
    if(s[i]!=s[i-1]){
      vec.push_back({s[i-1],cnt});
      cnt=0;
    }
    cnt++;
  }
  vec.push_back({s.back(),cnt});
}

int main(){
  IO();
  ll n,k;
  cin>>n>>k;
  vector<char> v(n+1,'0');
  ll rest=k;
  for(ll i=n;i>=1;i--){
    if(rest-i>=0){
      rest-=i;
      v[i]='1';
    }
  }
  string s;
  for(ll i=1;i<=n;i++){
    s+=v[i];
  }
  vector<pair<char,ll>> svec;
  rle(s,svec);
  ll ans=0;
  for(ll i=0;i<(ll)svec.size();i++){
    if(svec[i].first=='0'){
      ans++;
    }
  }
  cout<<ans<<endl;
}
0