結果

問題 No.78 クジ付きアイスバー
ユーザー koba-e964koba-e964
提出日時 2016-11-30 23:00:58
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,283 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 88,668 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 14:05:38
合計ジャッジ時間 1,648 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  ll k;
  cin >> n >> k;
  string s;
  cin >> s;
  int tot = 0;
  REP(i, 0, n) {
    tot += s[i] - '0';
  }
  if (tot >= n) {
    int acc = 0;
    int last = 0;
    REP(i, 0, n) {
      if (i + 1 > acc) {
	last = max(last, i + 1 - acc);
      }
      acc += s[i] - '0';
    }
    cout << last << endl;
    return 0;
  }
  int r = k % n;
  ll acc = k - k / n * tot;
  VI te(2 * n);
  int cur = 0;
  int cnt = 0;
  REP(i, 0, 2 * n) {
    if (cur >= 1) {
      cur--;
      cnt++;
    }
    cur += s[i % n] - '0';
    te[i] = cur;
  }
  //acc -= cnt;
  cout << (k >= n ? acc - te[n + r - 2] + tot : k - (k >= 2 ? te[k - 2] : 0)) << endl;
}
0