Submission #1655472


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true

typedef long long ll;
typedef pair<int, int> ii;

string s;
int k;

/*
string checker(string ss, int kk){
  string ret = ss;
  int i = 0, j = 0;
  string fst, sec;
  while(s[i] != 'a'){
    i++;
    if(i == s.size()) break;
  }
  fst = ss.substr(0, i);
  while(s[i+j] == 'a'){
    j++;
    if(i+j == s.size()) break;
  }
  sec = ss.substr(i, j);
  if(sec.size() == 0 || fst.size() > kk || fst.size() > sec.size()) return ss;
  else if(fst.size() < sec.size()){
    k -= fst.size();
    return (sec + checker(ss.substr(i+j), kk - fst.size()));
  }
  else{
    string thi = ss.substr(i+j);
    if(thi < ss) {
      k -= fst.size();
      return (sec + checker(thi, kk - fst.size()));
    }

    string buff = checker(thi, kk - fst.size());
    if(buff == thi) return ss;
    k -= fst.size();
    return (sec + buff);
  }

  return ret;
}
*/

int main(){

  cin >> s >> k;

  int na_cnt = 0;
  rep(i, s.size()) if(s[i] != 'a') na_cnt++;
  if(na_cnt<= k){
    rep(i, s.size() - k) cout << 'a';
    cout << endl;
  }
  else{

    rep(i, s.size()){
      if(s[i] == 'a') continue;
      if(s.substr(i+1) < s.substr(i)) {
        s[i] = 'a';
        k--;
        if(k <= 0) break;
      }
      else break;
    }
    rep(i, k) cout << 'a';
    cout << s << endl;

    /*
    string ans = checker(s, k);
    rep(i, k) cout << 'a';
    cout << ans << endl;
    if(DEBUG) cout << k <<endl;
    */
  }


	return 0;
}

Submission Info

Submission Time
Task C - アメージングな文字列は、きみが作る!
User letter
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1717 Byte
Status WA
Exec Time 3155 ms
Memory 1284 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 All
Score / Max Score 0 / 0 0 / 10 0 / 10 0 / 20 0 / 60
Status
AC × 3
AC × 11
WA × 2
AC × 17
WA × 11
AC × 23
WA × 20
AC × 26
WA × 33
TLE × 3
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt
Subtask2 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt, 40_rand_01.txt, 40_rand_02.txt, 40_rand_03.txt, 40_rand_04.txt, 40_rand_05.txt, 40_rand_06.txt, 40_rand_07.txt, 40_rand_08.txt, 40_rand_09.txt, 40_rand_10.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 50_hand_04.txt, 50_hand_05.txt
Subtask3 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt, 40_rand_01.txt, 40_rand_02.txt, 40_rand_03.txt, 40_rand_04.txt, 40_rand_05.txt, 40_rand_06.txt, 40_rand_07.txt, 40_rand_08.txt, 40_rand_09.txt, 40_rand_10.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 50_hand_04.txt, 50_hand_05.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 60_rand_05.txt, 60_rand_06.txt, 60_rand_07.txt, 60_rand_08.txt, 70_hand_01.txt, 70_hand_02.txt, 70_hand_03.txt, 70_hand_04.txt, 70_hand_05.txt, 70_hand_06.txt, 70_hand_07.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt, 40_rand_01.txt, 40_rand_02.txt, 40_rand_03.txt, 40_rand_04.txt, 40_rand_05.txt, 40_rand_06.txt, 40_rand_07.txt, 40_rand_08.txt, 40_rand_09.txt, 40_rand_10.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 50_hand_04.txt, 50_hand_05.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 60_rand_05.txt, 60_rand_06.txt, 60_rand_07.txt, 60_rand_08.txt, 70_hand_01.txt, 70_hand_02.txt, 70_hand_03.txt, 70_hand_04.txt, 70_hand_05.txt, 70_hand_06.txt, 70_hand_07.txt, 80_rand_01.txt, 80_rand_02.txt, 80_rand_03.txt, 80_rand_04.txt, 80_rand_05.txt, 80_rand_06.txt, 80_rand_07.txt, 80_rand_08.txt, 80_rand_09.txt, 80_rand_10.txt, 90_hand_01.txt, 90_hand_02.txt, 90_hand_03.txt, 90_hand_04.txt, 90_hand_05.txt, 90_hand_06.txt, 90_hand_07.txt, 90_hand_08.txt, 90_hand_09.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
00_example_03.txt AC 1 ms 256 KB
10_rand_01.txt WA 1 ms 256 KB
10_rand_02.txt WA 1 ms 256 KB
10_rand_03.txt AC 1 ms 256 KB
10_rand_04.txt AC 1 ms 256 KB
10_rand_05.txt AC 1 ms 256 KB
20_hand_01.txt AC 1 ms 256 KB
20_hand_02.txt AC 1 ms 256 KB
20_hand_03.txt AC 1 ms 256 KB
20_hand_04.txt AC 1 ms 256 KB
20_hand_05.txt AC 1 ms 256 KB
40_rand_01.txt WA 1 ms 256 KB
40_rand_02.txt WA 1 ms 256 KB
40_rand_03.txt WA 1 ms 256 KB
40_rand_04.txt WA 1 ms 256 KB
40_rand_05.txt WA 1 ms 256 KB
40_rand_06.txt AC 1 ms 256 KB
40_rand_07.txt WA 1 ms 256 KB
40_rand_08.txt WA 1 ms 256 KB
40_rand_09.txt AC 1 ms 256 KB
40_rand_10.txt WA 1 ms 256 KB
50_hand_01.txt AC 1 ms 256 KB
50_hand_02.txt AC 1 ms 256 KB
50_hand_03.txt AC 1 ms 256 KB
50_hand_04.txt AC 1 ms 256 KB
50_hand_05.txt WA 1 ms 256 KB
60_rand_01.txt WA 1 ms 256 KB
60_rand_02.txt WA 1 ms 256 KB
60_rand_03.txt WA 1 ms 256 KB
60_rand_04.txt WA 1 ms 256 KB
60_rand_05.txt WA 1 ms 256 KB
60_rand_06.txt WA 1 ms 256 KB
60_rand_07.txt WA 1 ms 256 KB
60_rand_08.txt WA 1 ms 256 KB
70_hand_01.txt AC 1 ms 256 KB
70_hand_02.txt AC 1 ms 256 KB
70_hand_03.txt AC 1 ms 256 KB
70_hand_04.txt AC 2 ms 256 KB
70_hand_05.txt WA 1 ms 256 KB
70_hand_06.txt AC 2 ms 256 KB
70_hand_07.txt AC 1 ms 256 KB
80_rand_01.txt WA 10 ms 852 KB
80_rand_02.txt WA 9 ms 896 KB
80_rand_03.txt WA 17 ms 1156 KB
80_rand_04.txt WA 10 ms 900 KB
80_rand_05.txt WA 11 ms 1028 KB
80_rand_06.txt WA 11 ms 900 KB
80_rand_07.txt WA 12 ms 1028 KB
80_rand_08.txt WA 11 ms 900 KB
80_rand_09.txt WA 16 ms 1028 KB
80_rand_10.txt WA 8 ms 896 KB
90_hand_01.txt AC 18 ms 900 KB
90_hand_02.txt AC 13 ms 900 KB
90_hand_03.txt AC 20 ms 1284 KB
90_hand_04.txt TLE 3155 ms 1284 KB
90_hand_05.txt WA 12 ms 1284 KB
90_hand_06.txt TLE 3155 ms 1284 KB
90_hand_07.txt TLE 3155 ms 1284 KB
90_hand_08.txt WA 17 ms 1284 KB
90_hand_09.txt WA 17 ms 1284 KB