「CF509B」Painting Pebbles
题解
得出mn=min{ai}
每堆前mn+1个染色为1
然后2-k给每一堆染色1个
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 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #include<cmath> #define mod 30031 #define inf 1000000000 #define rad 100000000 #define pa pair<int,int> #define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,k,mn=inf; int a[105],c[105][105]; int now[105]; void color(int num,int id) { for(int i=1;i<=n;i++) { int t=num; for(;now[i]<a[i]&&t;now[i]++,t--) c[i][now[i]+1]=id; } } int main() { n=read();k=read(); for(int i=1;i<=n;i++) { a[i]=read(); mn=min(mn,a[i]); } color(mn+1,1); for(int i=2;i<=k;i++) color(1,i); for(int i=1;i<=n;i++) if(now[i]!=a[i]){puts("NO");return 0;} puts("YES"); for(int i=1;i<=n;i++) { for(int j=1;j<=a[i];j++) printf("%d ",c[i][j]); puts(""); } return 0; } |
Subscribe