183722025-10-21 14:08:49ubormaciCarlo könyveicpp17Accepted 100/10016ms7844 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <fstream>
using namespace std;

#pragma GCC optimize("O2")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

set lower bound/upper bound:
 	// . . . m1 . . . d . . . . m2
    auto m1_it = b.lower_bound(d);
    advance(m1_it, -1);
    m1 = *m1_it;
	m2 = *b.upper_bound(d);

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

constexpr auto lcm(auto x, auto... xs)
{
	return ((x = std::lcm(x, xs)), ...);
}

std::gcd(int a, int b)

*/

typedef long long ll;

void solve() {
	string a, b;
	cin >> a >> b;

	string oga = a;
	string ogb = b;

	string c = "";

	ll al = a.length();
	ll bl = b.length();

	//ll sm = min(al, bl);
	//ll bg = max(al, bl);

	//string pref = "";

	/*
	if(bl - al >= 2) {
		cout << a + "a";
		return;
	}
	if(bl - al == 1) {
		if(b[bg-1] > 'a') {
			cout << a + 'a';
		}else{
			cout << "-1";
		}
		return;
	}
	*/

	//cerr << "\nal=" << al;
	//cerr << "\nbl=" << bl;

	if(al > bl) {
		for(ll i = 0; i < al - bl; i++) {
			b += 'a' - 1;
		}
		bl = al;
	}
	if(bl > al) {
		for(ll i = 0; i < bl - al; i++) {
			a += 'a' - 1;
		}
		al = bl;
	}

	//cerr << "\na=" << a;
	//cerr << "\nb=" << b;

	ll ns = 0;
	while(a[ns] == b[ns] && ns < al) {
		//cerr << "\nns=" << ns;
		//cerr << "\na[ns=]" << a[ns];
		c += a[ns];
		ns++;
	}

	//cerr << "\nns=" << ns;

	if(ns == al) {
		cout << "-1";
		return;
	}

	if(b[ns] - a[ns] >= 2) {
		//cerr << "\nsinglediff";
		c += a[ns] + 1;
		cout << c;
		return;
	}
	
	string c1 = "-1", c2 = "-1";
	// c1 : first element is smaller
	// c2 : first element is larger

	c1 = c + a[ns];
	c2 = c + b[ns];

	if(a[ns] == 'a' - 1) {
		c1 = c;
	}

	for(ll i = ns + 1; i < al; i++) {
		//cerr << "\nc1=" << c1;
		if(a[i] == 'z') {
			c1 += 'z';
		}else{
			c1 += a[i] + 1;
			break;
		}
	}
	for(ll i = ns + 1; i < al; i++) {
		//cerr << "\nc2=" << c2;
		if(b[i] == 'a' - 1) {
			c2 = "-1";
			break;
		}else{
			break;
		}
	}

	//cerr << "\nc1=" << c1;
	//cerr << "\nc2=" << c2;

	if(c1 == oga || c1 == ogb) {
		c1 = "-1";
	}
	if(c2 == oga || c2 == ogb) {
		c2 = "-1";
	}

	if(c1 == "-1" && c2 == "-1") {
		cout << "-1";
		return;
	}else if(c2 == "-1") {
		//cerr << "\nc1";
		cout << c1;
		return;
	}else if(c2 == "-1") {
		//cerr << "\nc2";
		cout << c1;
		return;
	}
		
	if(c1.length() <= c2.length()) {
		//cerr << "\nc1";
		cout << c1;
	}else{
		//cerr << "\nc2";
		cout << c2;
	}

}

int main()
{
	std::ios_base::sync_with_stdio(false);

	solve();

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Accepted1ms316 KiB
subtask215/15
6Accepted8ms5052 KiB
7Accepted9ms5296 KiB
8Accepted8ms5340 KiB
9Accepted8ms5272 KiB
10Accepted8ms6000 KiB
subtask315/15
11Accepted8ms4544 KiB
12Accepted8ms4240 KiB
13Accepted8ms4180 KiB
14Accepted8ms4044 KiB
15Accepted7ms4220 KiB
subtask430/30
16Accepted1ms316 KiB
17Accepted1ms316 KiB
18Accepted1ms508 KiB
19Accepted1ms316 KiB
20Accepted1ms316 KiB
21Accepted1ms316 KiB
22Accepted1ms508 KiB
23Accepted1ms316 KiB
subtask540/40
24Accepted1ms316 KiB
25Accepted1ms532 KiB
26Accepted1ms316 KiB
27Accepted1ms316 KiB
28Accepted1ms500 KiB
29Accepted8ms5052 KiB
30Accepted9ms5296 KiB
31Accepted8ms5340 KiB
32Accepted8ms5272 KiB
33Accepted8ms6000 KiB
34Accepted8ms4544 KiB
35Accepted8ms4240 KiB
36Accepted8ms4180 KiB
37Accepted8ms4044 KiB
38Accepted7ms4220 KiB
39Accepted1ms316 KiB
40Accepted1ms316 KiB
41Accepted1ms508 KiB
42Accepted1ms316 KiB
43Accepted1ms316 KiB
44Accepted1ms316 KiB
45Accepted1ms508 KiB
46Accepted1ms316 KiB
47Accepted16ms7844 KiB
48Accepted14ms7692 KiB
49Accepted9ms5496 KiB
50Accepted8ms4976 KiB
51Accepted8ms4288 KiB
52Accepted8ms4016 KiB
53Accepted9ms6264 KiB
54Accepted10ms6068 KiB