Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void dbg_out() { cerr << endl; }
- template<typename Head, typename... Tail>
- void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
- #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
- #define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
- #define rng_seed(x) mt19937 rng(x)
- #define all(x) (x).begin(), (x).end()
- #define sz(x) (int) (x).size()
- // #define int long long
- const int MXN = 1e5 + 5, INF = 1e9 + 5;
- void solve() {
- string S, T;
- cin >> S >> T;
- int N = sz(S), M = sz(T);
- if (N != M) {
- cout << "NO";
- return;
- }
- if (S == T) {
- cout << "YES";
- return;
- }
- if (S.front() != T.front() && S.back() != T.back()) {
- cout << "NO";
- return;
- }
- // if (S.front() == T.front()) {
- // reverse(all(S));
- // reverse(all(T));
- // }
- int mn = INF, mx = -INF;
- int last = -1;
- for (int i = 0; i < N - 1; i++) {
- if (S[i] == T[i]) continue;
- if (S[i] != T[i] && last != -1 && last < i - 1) {
- cout << "NO";
- return;
- }
- if (S[i] != T[i]) last = i;
- if (S[i] > T[i]) {
- S[i] = (char) ('a' - 1);
- }
- // dbg(i, moves);
- mn = min(mn, (S[i] - 'a') - (T[i] - 'a'));
- mx = max(mn, (S[i] - 'a') - (T[i] - 'a'));
- // dbg(i, mn, mx);
- }
- cout << (mx == mn ? "YES" : "NO");
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int TC = 1;
- // cin >> TC;
- while (TC--) solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment