E. Median String
time limit per test
2 seconds
memory limit per test
256 megabytes
You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than tt.
Let's consider list of all strings consisting of exactly kk lowercase Latin letters, lexicographically not less than ss and not greater than tt (including ss and tt) in lexicographical order. For example, for k=2k=2, s=s="az" and t=t="bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].
Your task is to print the median (the middle element) of this list. For the example above this will be "bc".
It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.
Input
The first line of the input contains one integer kk (1≤k≤2⋅1051≤k≤2⋅105) — the length of strings.
The second line of the input contains one string ss consisting of exactly kk lowercase Latin letters.
The third line of the input contains one string tt consisting of exactly kk lowercase Latin letters.
It is guaranteed that ss is lexicographically less than tt.
It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.
Output
Print one string consisting exactly of kk lowercase Latin letters — the median (the middle element) of list of strings of length kklexicographically not less than ss and not greater than tt.
Examples
input
2 az bf
output
bc
input
5 afogk asdji
output
alvuw
input
6 nijfvj tvqhwp
output
qoztvz
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
const ll mod = 1000000007;
const int N = 1e6;
int n,m,k; int ans=0;
int a[1000006], b[1000006];
string s1,s2;
int main() {
cin>>n;
cin>>s1>>s2;
string s;
int c=0;
for(int i=n-1;i>=0;i--){
int d;
d = (s1[i]-'a' +s2[i] - 'a')+c;
c = d/26 , s+=('a' + d%26 );
}
c=c*26;
for(int i=n-1;i>=0;i--){
int d;
d= c + s[i] -'a';
c = d%2*26;
s[i] = (d/2 + 'a');
}
for(int i=n-1;i>=0;i--){
cout<<s[i];
}
return 0;
}