結果

問題 No.145 yukiover
ユーザー knewknowlknewknowl
提出日時 2015-02-10 15:26:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 64,348 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-05 22:46:47
合計ジャッジ時間 17,153 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
char S[100010];
int num[26];
int tmp[26];

int stronger(string str,int m){ //idxはアルファベット
  if(str.length()==0 || m<=0){
    int cnt = 0;
    for(int i=0;i<=25;++i) cnt+=num[i];
    int rest = max(0,cnt-m);
    return min(cnt,m)+rest/5;
  }
  int c = str[0]-'a';
  int cnt = 0;
  for(int i=c+1;i<=25;++i) cnt+=num[i];
  if(cnt>=m) return m;
  for(int i=c+1;i<=25;++i){
    tmp[i] = num[i];
    num[i]=0;
  }
  m-=cnt;
  int ret = 0;
  if(num[c]==0){
    int rest = 0;
    for(int i=0;i<=25;++i) rest+=num[i];
    return rest/str.length();
  }
  for(int k=1;k<=min(num[c],m);++k){
    num[c]-=k;
    ret = max(ret,stronger(str.substr(1,str.length()-1),k));
    num[c]+=k;
  }
  for(int i=c+1;i<=25;++i) num[i] = tmp[i];
  return ret+cnt;
}

void solve(){
  sort(S,S+n);
  for(int i=0;i<n;++i) num[S[i]-'a']++;  
  cout <<  stronger("yuki",n) << endl;
}

int main(){
  scanf("%d",&n);
  scanf("%s",S);
  solve();
  return 0;
}
0