結果

問題 No.1530 Permutation and Popcount
ユーザー penguinmanpenguinman
提出日時 2021-06-03 06:34:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,181 bytes
コンパイル時間 7,015 ms
コンパイル使用メモリ 338,484 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 22:34:28
合計ジャッジ時間 16,243 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include "testlib.h"
//using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, j, n) for(ll i = ll(j); i < ll(n); i++)
#define REP(i, j, n) for(ll i = ll(j); i <= ll(n); i++)
#define per(i, j, n) for(ll i = ll(j); ll(n) <= i; i--)
#define ALL(a) (a).begin(),(a).end()
#define revALL(a) (a).rbegin(),(a).rend()
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define ln "\n"
using std::endl;
using std::cin;
using std::cout;
using ll = long long;
using lint = __int128;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll, ll>;
using vs = vector<int>;
using vss = vector<vs>;
using pss = std::pair<int, int>;
using vl = vector<lint>;
using vll = vector<vl>;
using pll = std::pair<lint, lint>;

//main
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::random_device rnd;
    std::mt19937 mt(rnd());
    ll N,M;
    N = inf.readInt(1,300,"N");
    inf.readSpace();
    M = inf.readInt(0,N*N,"M");
    inf.readEoln();
    vi cnt(N+1);
    REP(i,1,N){
        REP(j,1,N){
            if(__builtin_popcount(i*j)%2 == 0) cnt[i]++;
        }
    }
    vector<vector<bool>> dp(N+1,vector<bool>(2*N*N+1));
    dp[0][N*N] = true;
    REP(i,1,N){
        REP(j,0,2*N*N){
            if(!dp[i-1][j]) continue;
            if(cnt[i] <= j) dp[i][j-cnt[i]] = true;
            if(j+cnt[i] <= 2*N*N) dp[i][j+cnt[i]] = true;
        }
    }
    M += N*N;
    if(dp[N][M]){
        vi P,Q;
        per(i,N,1){
            if(M+cnt[i]<=2*N*N && dp[i-1][M+cnt[i]]){
                Q.pb(i);
                M += cnt[i];
            }
            else{
                P.pb(i);
                M -= cnt[i];
            }
        }
        cout << P.size() << " " << Q.size() << ln;
        for(auto p:P) cout << p << ln;
        for(auto q:Q) cout << q << ln;
    }
    else{
        cout << -1 << ln;
    }
    inf.readEof();
}

0