Submission #1359984


Source Code Expand

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

string S;
bool single(string s, int c) {
  rep(i, s.length()) {
    if (s[i] != c) return false;
  }
  return true;
}

int solve(int c) {
  string s(S);
  int ctr = 0;
  while (!single(s, c)) {
    string t = "";
    rep(i, (int)s.length()-1) {
      if (s[i] == c || s[i+1] == c) t += c;
      else t += 30;
    }
    ctr++;
    s = t;
  }
  return ctr;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S;
  rep(i, S.length()) S[i] -= 'a';
  int m = INF;
  rep(c, 26) {
    m = min(m, solve(c));
  }
  cout << m << "\n";
  return 0;
}

Submission Info

Submission Time
Task A - Shrinking
User funcsr
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1094 Byte
Status AC
Exec Time 3 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 14
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 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
Case Name Status Exec Time Memory
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 3 ms 256 KB
1_02.txt AC 3 ms 256 KB
1_03.txt AC 2 ms 256 KB
1_04.txt AC 3 ms 256 KB
1_05.txt AC 2 ms 256 KB
1_06.txt AC 2 ms 256 KB
1_07.txt AC 2 ms 256 KB
1_08.txt AC 2 ms 256 KB
1_09.txt AC 2 ms 256 KB