The meaning of problems
Given a number n
Description has from 0 to 9999 ... (n number 9) 10 ^ n digits
If all the numbers is less than n bits, all leading zeros are filled with, in order to ensure that each number is the number of bits n
Each number is then defined by a plurality of blocks
The same number of adjacent blocks constituting a
For example to 00,027,734,000
There are three blocks of length 1 (2,3,4)
A length of block 2 (77)
2 blocks of length 3 (000,000)
Ask, 10 ^ n n-bit number, the sum of the lengths of blocks of different total number of
Entry
A number n
1 <= n <= 2e5
Export
n digits, separated by a space
The i-th block i denotes the length of the number
The answer to the modulo 998 244 353
Problem-solving ideas
I do not know there is no direct Gangster launch formula
Here we are talking about the recursive method
Assume now that n is 1, i.e., only the number of 0 to 9 of these 10
So if for each count plus one, so that becomes 2 digits 1 digits
Can be obtained, the length of the block 2 is applied only by the length of a next block as saying a number obtained
Therefore, 2 bits, the length is 10 kinds of blocks is 2, 00,11,22 ... 99
And a length of a number of blocks, that is, the number of all bits of the remaining
I.e. all digit bits and 2 (each number 2) * 100 (species) = 200
Blocks of length 2 occupies the 2 (bit) * 10 (species) = 20
Therefore, the length of the block 1 are 200--20 = 180 kinds
Similarly, the number of bits from 2 to 3 digits Recursive
3 is the block length only by the length of a next block plus 2 to give the same numerals
Therefore, the number of types of block length 3 to 10
2 is a block length only by the length of a next block of the same number plus 1 to give
note:
Block is not a block of the same length from the holding state transition from
Because if you want to transfer from the block of the same length from, then transfer the extra numbers can not be added in the next block .
However, they do not add the next block, you can obtain digital transferred from the other state, resulting in duplication
For example, 12223 is 222 blocks of length 3
To keep the block length, the extra numbers can not be added at about 222
To later add 1 as an example, it will become 122,231
However, this number can add 2 12231 transferred from the block 22
It will cause duplicate statistics, it can only block to a longer length transfer
Therefore, the number of types of block length 2 180
There are three digit 3 * 1000 = 3000
So the length of the number block type 1 is 3000--180 * 2--10 * 3 = 2610 kinds of
And so on until the required push to n digits of
1 can be found in all the bits and the number of bits 10,2 digit number for all and for all the bits and 200, 3-digit number is 3000 ......
The number of all the bits and i is i * (10 ^ i)
Median length i is the number of blocks of a recursive formula is
i * (10 ^ i) - 2 (the number of blocks of length 2) --3 (the number of blocks of length 3) - ... - n (n is the number of blocks of length)
Code
The length of each block number stored together with an array ans, use type long long
Double-digit circumstances can just get to break out
ans[1]=10;
ans[2]=180;
Then the cycle starts from 3 to n array requirements ans
But if you really have to go step by step to count the number of bits above recursive formula * and the number of words
Time complexity will be O (n ^ 2) level, for the range of time out 1e5
So for ways to think about (crazy looking for strange knowledge of high school)
According to the above-mentioned, each of two or more blocks are low adding a block number transferred from one and the same
So there is a total plus figure is the sum of a number of state cases
Length is the number of the current state of the block 1 may be formed on ** (bit length of the number of all the numbers of i) - (number of bits of length of all the numbers of i-1) - (i-1 when the length of the sum of the number of all blocks) to give **
Plus a sum of the variables memory array ans prefix and can be realized O (n) solution of
For the i * (10 ^ i), all of 10 ^ i may be pretreated presence array easy call
It can also be directly combined with rapid power
The following is a way to keep the array, the array name e10
So now ans [i] is the transition equation i * e10 [i] - (i-1) * e10 [i-1] - sum
And because the data is too large needs modulo
Assuming e10 [i] is very small, e10 [i-1] and the sum is large, then in order to ensure can become positive after modulo
So again plus i-mod
The last expression is
ans[i]=(i*e10[i]-(i-1)*e10[i-1]-sum+i*mod)%mod;
For the prefix and the sum
In followed by a
sum=(sum+ans[i])%mod;
To
Finally ans array in reverse order output
The complete code
(78ms / 2000ms)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll ans[200050],e10[200050];
int main(){
int n,i;
scanf("%d",&n);
e10[0]=1;
for(i=1;i<=n;i++)
e10[i]=e10[i-1]*10%mod;
ll sum=190;
ans[1]=10;
ans[2]=180;
for(i=3;i<=n;i++)
{
ans[i]=(i*e10[i]-(i-1)*e10[i-1]-sum+i*mod)%mod;
sum=(sum+ans[i])%mod;
}
for(i=n;i;i--)
printf("%d ",ans[i]);
return 0;
}