AtCoder Grand Contest 016

Submission #1589918

Source codeソースコード

#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

string s;
bool table[100];

inline bool check(string s,char a){
  for(int i=0;i<(int)s.length();i++){
    if(s[i]!=a)return 0;
  }
  return 1;
}
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
   cin>>s;
   for(int i=0;i<(int)s.length();i++){
     table[s[i]-'a']=1;
   }
   string ss;
   int ans=999999999;
  for(char now='a';now<='z';now++){
    if(!table[now-'a'])continue;
    ss=s;
    string t="";
    int nowans=0;
    while(!check(ss,now)){
      for(int i=0;i<(int)ss.length()-1;i++){
        if(ss[i]==(char)now || ss[i+1]==(char)now){
          t+=now;
        }else{
          t+=ss[i];
        }
      }
      ss=t;
      t="";
      nowans++;
    }
    ans=min(ans,nowans);
  }
  cout<<ans<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Submission

Task問題 A - Shrinking
User nameユーザ名 aim_cpo
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 300
Source lengthソースコード長 1461 Byte
File nameファイル名
Exec time実行時間 2 ms
Memory usageメモリ使用量 256 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt,0_03.txt
All 300 / 300 0_00.txt,0_01.txt,0_02.txt,0_03.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 1 ms 256 KB
1_08.txt AC 2 ms 256 KB
1_09.txt AC 2 ms 256 KB