# [bzoj3325] [Scoi2013]密码【malachar】【贪心】

【题目链接】
https://www.lydsy.com/JudgeOnline/problem.php?id=3325
【题解】
由于一定有解，所以每个位置只要计算一次，所以考虑用马拉车来解决。可以通过马拉车的思路，如果之前算到这里，那么就不再算下去。同时再开一个数组记录每个数不能填的数，显然复杂度是 O(N) O ( N ) $O(N)$
【代码】

/* - - - - - - - - - - - - - - -
User :      VanishD
problem :   [bzoj3325]
Points :    malachar
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define    ll      long long
# define    inf     0x3f3f3f3f
# define    N       200010
using namespace std;
int tmp = 0, fh = 1; char ch = getchar();
while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
return tmp * fh;
}
int p[N], s[N], tag[N][31], n;
int main(){
//  freopen("bzoj3325.in", "r", stdin);
//  freopen("bzoj3325.out", "w", stdout);
for (int i = 1; i <= n; i++)
p[i * 2 - 1] = read();
for (int i = 1; i < n; i++)
s[0] = 28, s[1] = 1;
int r = 0;
for (int i = 1; i <= n * 2; i++){
if (s[i] == 0){
for (int j = 1; j <= 27; j++)
if (tag[i][j] == false){
s[i] = j;
break;
}
}
int now = i + p[i];
for (int j = r + 1; j <= now; j++)
s[j] = s[i - (j - i)];
tag[now + 1][s[i - (now  + 1 - i)]] = true;
r = max(r, now);
}
for (int i = 1; i <= n; i++)
printf("%c", s[i * 2 - 1] + 'a' - 1);
printf("\n");
return 0;
}


11-30 35
03-25 26
01-18 254
03-27 135
04-02 1089
02-09 1054
03-09 29
10-17 1837
12-05 1236
11-03 1892
02-01 1925
11-27 3222
08-05 1759
02-17 392