結果

問題 No.78 クジ付きアイスバー
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-11-15 18:15:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,118 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 87,684 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-16 01:58:12
合計ジャッジ時間 11,472 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000009

int f1(int n, int k, string s){
  int ans = 0;
  long long atari = 0;
  int index = 0;
  for(;;){
    if(s[index]=='0'){
      if(atari==0){
        ans++;
      }
      else{
        atari--;
      }
    }
    if(s[index]=='1'){
      if(atari==0){
        ans++;
        atari++;
      }
    }
    if(s[index]=='2'){
      if(atari==0){
        ans++;
        atari+=2;
      }
      else{
        atari++;
      }
    }
    k--;
    if(k==0)break;
    index++;
    index%=n;
  }
  return ans;
}

int f2(int n, int k, string s){
  int ans = 0;
  int atari = 0;
  for(int i = 0; i < n; i++){
    if(s[i]=='0'){
      if(atari==0){
        ans++;
      }
      else{
        atari--;
      }
    }
    if(s[i]=='1'){
      if(atari==0){
        ans++;
        atari++;
      }
    }
    if(s[i]=='2'){
      if(atari==0){
        ans++;
        atari+=2;
      }
      else{
        atari++;
      }
    }
  }
  int d = max(0,ans-atari);
  int c = max(0,k%n-10);
  return f1(n,k-c*n,s)+c*d;
}

int main(){
  srand((unsigned)time(NULL));
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  //cout << f1(n,k,s) << endl;
  cout << f2(n,k,s) << endl;
  return 0;
}

/*
最初と最後のパターンと中間の繰り返しのパターンを別に考えて解く解法です。
Div2のMedあたりではよく見かけたアイデアのように思います。
*/
0