1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <set> #include <vector> using namespace std;
const int INF = ~0u>>1; typedef pair <int,int> P; #define MID(x,y) ((x+y)>>1) #define iabs(x) ((x)>0?(x):-(x)) #define REP(i,a,b) for(int i=(a);i<(b);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define mp make_pair #define print() cout<<"--------"<<endl #define maxn 5010
struct node{ int id,ans,val; }num[maxn];
bool cmp(node a,node b){ return a.val < b.val; }
int val[10010]; bool vis[66]; int ans[maxn]; int main(){ int n,k; scanf("%d%d", &n, &k); for (int i = 0; i < k; i++){ scanf("%d", &num[i].val); num[i].id = i; } int len = 0; int now = 0; sort(num,num + k,cmp);
for (int i = 1; i <= 10000; i ++){ val[i] = val[i /10] + i % 10; } memset(vis,1,sizeof(vis));
for (int i = 1; i <= n; i ++){ if (vis[i % 63]){ len ++; while (num[now].val == len){ ans[num[now++].id] = i; } }
vis[i % 63] = 1;
int next = i + val[i / 10000] + val[i % 10000]; vis[next % 63] = 0;
} cout << len << endl; for (int i = 0; i < now; i++){ if (i) printf(" "); printf("%d", ans[i]); } cout << endl; return 0; }
|