Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:16777216")
- #include <cctype>
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <algorithm>
- #include <vector>
- #include <math.h>
- #include <time.h>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <map>
- #include <list>
- #include <set>
- #include <string>
- #include <iomanip>
- #include <iterator>
- #include <unordered_map>
- #include <unordered_set>
- #define forn(i, n) for (i64 i = 0; i < n; ++i)
- #define revn(i, n) for (i64 i = n-1; i>=0; --i)
- #define cyc(i, s, n) for (i64 i = s; i <= n; ++i)
- #define pb push_back
- #define mp(a,b) make_pair(a,b)
- #define all(x) x.begin(), x.end()
- #define F first
- #define S second
- #define eps 1e-7
- #define inf (1000*1000*1000+9)
- #define debug(x) cout << x << endl;
- using namespace std;
- typedef unsigned long long u64;
- typedef long long i64;
- typedef long double ld;
- typedef vector < i64 > vi64;
- typedef vector < u64 > vu64;
- typedef pair < i64, i64 > pi64;
- typedef vector < vi64 > graph;
- typedef int huint;
- /////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////
- inline i64 nextInt() {
- int s = 1, x = 0, c = getc(stdin);
- while (c <= 32)
- c = getc(stdin);
- if (c == '-')
- s = -1, c = getc(stdin);
- while ('0' <= c && c <= '9')
- x = x * 10 + c - '0', c = getc(stdin);
- return x * s;
- }
- inline void printInt(i64 x) {
- if (x < 0)
- putc('-', stdout), x = -x;
- char s[20];
- i64 n = 0;
- while (x || !n)
- s[n++] = '0' + x % 10, x /= 10;
- while (n--)
- putc(s[n], stdout);
- }
- inline void NextString( char *s ) {
- int c = getc(stdin);
- while (c <= 32)
- c = getc(stdin);
- while (c > 32)
- *s++ = c, c = getc(stdin);
- *s = 0;
- }
- inline void writeWord( char *s ) {
- while (*s)
- putchar(*s++);
- }
- /////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////
- vi64 p;
- void sieve() {
- i64 n = 10000;
- vector<char> pr(n+1,true);
- cyc(i, 2, n) {
- if (pr[i])
- for (i64 j = i*i; j<=n; j+=i)
- pr[j]=false;
- }
- cyc(i, 2, n)
- if (pr[i])
- p.pb(i);
- }
- string alph = "qwertyuiopasdfghjklzxcvbnm", ralph;
- string s;
- set<char> u;
- vector<bool> can;
- i64 Z = 0, A = 0, n;
- bool fix(i64 &k) {
- if (!k) {
- cout << s;
- return false;
- }
- i64 bestZ=0, bestA=0;
- forn(i, n)
- if (u.count(alph[i]))
- ++bestA;
- else break;
- forn(i, n)
- if (u.count(ralph[i]))
- ++bestZ;
- else break;
- if (!Z && !A) {
- cout << -1;
- return false;
- } else if (!Z || !A) {
- char f;
- if (bestZ>bestA)
- f=alph[bestA];
- else f=ralph[bestZ];
- bool flag = false;
- forn(i, n) {
- if (can[i]) {
- s[i]=f;
- u.insert(f);
- can[i]=false;
- flag = true;
- break;
- }
- }
- if (flag) {
- --k;
- return true;
- } else {
- cout << -1;
- return false;
- }
- }
- if (bestZ>bestA) {
- bool flag = false;
- forn(i, n) {
- if (can[i] && s[i]=='a') {
- u.insert(alph[bestA]);
- s[i]=alph[bestA];
- can[i]=false;
- flag = true;
- break;
- }
- }
- if (!flag) {
- cout << -1;
- return false;
- } else {
- --k;
- --A;
- return true;
- }
- }
- if (bestA>=bestZ) {
- bool flag = false;
- forn(i, n) {
- if (can[i] && s[i]=='z') {
- u.insert(ralph[bestZ]);
- s[i]=ralph[bestZ];
- can[i]=false;
- flag = true;
- break;
- }
- }
- if (!flag) {
- cout << -1;
- return false;
- } else {
- --k;
- --Z;
- return true;
- }
- }
- return true;
- }
- int main() {
- sort(all(alph));
- ralph = alph;
- reverse(all(ralph));
- cin >> s;
- n = s.size();
- i64 k = nextInt();
- can.resize(n,false);
- forn(i, n) {
- if (s[i]=='?') {
- if (i&1) {
- s[i]='a';
- ++A;
- } else {
- s[i]='z';
- ++Z;
- }
- can[i]=true;
- } else {
- u.insert(s[i]);
- }
- }
- k-=u.size();
- k = (k<0)?0:k;
- while (fix(k)){}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement