蒟蒻RE求助
查看原帖
蒟蒻RE求助
544279
wh__楼主2024/9/11 21:22

思路应该没问题,莫名其妙RE了。。。

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define eb(x) emplace_back(x)
using namespace std;
const int SIZE=5010;
int n,k;
int b[SIZE];
int tot,ans[SIZE];
int read()
{
    int x=1,res=0;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')x=-1;ch=getchar();}
    while(isdigit(ch)){res=(res<<3)+(res<<1)+(ch^48);ch=getchar();}
    return x*res;
}
signed main()
{
    // freopen("xx.in","r",stdin);
    // freopen("xx.out","w",stdout);
    n=read(),k=read();
    for(int i=1;i<=n;i++) b[i]=k;
    if(n&1) for(int i=1;i<=k;i++) ans[++tot]=(n+1)/2,b[(n+1)/2]--;
    if(n/2)
    {
        ans[++tot]=n/2;
        b[n/2]--;
        for(int i=n;i;i--)
        {
            while(b[i]>0)
            {
                ans[++tot]=i;
                b[i]--;
            }
        }
        // printf("%d\n",n/2);
    }
    for(int i=1;i<=n*k;i++) printf("%d ",ans[i]);
    return 0;
}
/*
1122
1212
1221
2112
2121
2211

*/
2024/9/11 21:22
加载中...