2020-牛客多校-6E-Easy Construction

 

 :构造一个长度为N序列P,使的序列 P 存在长度为 [ 1 , N ]的子序列的和 S mod N = K ,也就是构造出一个存在 N 个不同长度的子序列X,且X的和 S mod N = K

 :可以使用求和公式(1+n)* n / 2 判断是否满足存在 N 个数的和 S mod N = K ,

  S mod N != K ,-1

  S mod N = K

    N&1 = 1 :能够满足  N 个不同长度的子序列X,且X的和 S mod N = K 的K值只能是0 ,那么序列可以是【1 , N-1 , 2 , N-2 , 3 , N-3 ... N 】

    N&1 = 0 :能够满足  N 个不同长度的子序列X,且X的和 S mod N = K 的K值只能是N/2,那么序列可以是【N , N/2 , 1 , N-1 , 2 , N-2 ....】

#include <bits/stdc++.h>
using namespace std;
#define ll long long
using namespace std;
const int mod = 1e8;/// 998244353;
const int mxn = 15 +7;
ll _,m,n,t,k,ans;
int dp[mxn][1<<13] , a[mxn][mxn] , f[mxn] , sta[1<<13] ;
void solve()
{
    while(cin>>n>>m){
        ans = (1+n)*n/(2*1ll);
        if(ans%n==m){
            if(n&1){
                if(m==0){
                    cout<<n<<' ';
                    for(int i=1;i<=n/2;i++)
                        cout<<i<<" "<<n-i<<(i==n/2?'\n':' ');
                } else {
                    cout<<-1;
                }
            } else {
                if(m==n/2){
                    cout<<n<<' '<<n/2<<' ';
                    for(int i=1;i<n/2;i++)
                        cout<<i<<" "<<n-i<<(i==n/2-1?'\n':' ');
                } else {
                    cout<<-1;
                }
            }
        } else {
            cout<<-1;
        }
        cout<<endl;
    }
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
}
View Code

猜你喜欢

转载自www.cnblogs.com/Shallow-dream/p/13391070.html