Submission #16520821


Source Code Expand

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  string s;
  cin >> s;
  set<char> d;
  for (char c = 'a'; c <= 'z'; c++) d.insert(c);
  for (auto &i : s) d.erase(i);
  if (d.size()) {
    s += *d.begin();
    cout << s << '\n';
    return;
  }
  set<char> g;
  while (s.size()) {
    char c = s.back();
    s.pop_back();
    auto it = g.upper_bound(c);
    if (it != g.end()) {
      s += *it;
      cout << s << '\n';
      return;
    }
    g.insert(c);
  }
  cout << -1 << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

Submission Info

Submission Time
Task A - Diverse Word
User erke
Language C++ (GCC 9.2.1)
Score 300
Code Size 951 Byte
Status AC
Exec Time 8 ms
Memory 3620 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 23
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 8 ms 3516 KB
02.txt AC 2 ms 3616 KB
03.txt AC 3 ms 3456 KB
04.txt AC 2 ms 3584 KB
05.txt AC 2 ms 3616 KB
06.txt AC 2 ms 3568 KB
07.txt AC 4 ms 3572 KB
08.txt AC 3 ms 3512 KB
09.txt AC 2 ms 3556 KB
10.txt AC 4 ms 3620 KB
11.txt AC 2 ms 3612 KB
12.txt AC 3 ms 3588 KB
13.txt AC 2 ms 3620 KB
14.txt AC 2 ms 3460 KB
15.txt AC 3 ms 3512 KB
16.txt AC 4 ms 3512 KB
17.txt AC 3 ms 3452 KB
18.txt AC 2 ms 3608 KB
19.txt AC 2 ms 3576 KB
s1.txt AC 2 ms 3556 KB
s2.txt AC 2 ms 3452 KB
s3.txt AC 2 ms 3496 KB
s4.txt AC 3 ms 3616 KB