結果

問題 No.1530 Permutation and Popcount
ユーザー jutamajutama
提出日時 2021-06-04 22:22:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 5,478 bytes
コンパイル時間 4,074 ms
コンパイル使用メモリ 190,280 KB
実行使用メモリ 215,740 KB
最終ジャッジ日時 2023-08-16 08:41:27
合計ジャッジ時間 12,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 99 ms
67,740 KB
testcase_12 AC 275 ms
189,880 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 118 ms
80,112 KB
testcase_15 AC 20 ms
15,308 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 163 ms
112,808 KB
testcase_18 AC 76 ms
51,640 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 140 ms
95,852 KB
testcase_22 AC 173 ms
119,396 KB
testcase_23 AC 138 ms
93,484 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 106 ms
72,468 KB
testcase_26 AC 8 ms
7,248 KB
testcase_27 AC 281 ms
195,948 KB
testcase_28 AC 179 ms
124,244 KB
testcase_29 AC 14 ms
10,716 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 310 ms
215,604 KB
testcase_32 AC 315 ms
215,724 KB
testcase_33 AC 308 ms
215,632 KB
testcase_34 AC 308 ms
215,688 KB
testcase_35 AC 309 ms
215,740 KB
testcase_36 AC 309 ms
215,624 KB
testcase_37 AC 307 ms
215,740 KB
testcase_38 AC 307 ms
215,592 KB
testcase_39 AC 305 ms
211,628 KB
testcase_40 AC 304 ms
211,708 KB
testcase_41 AC 302 ms
211,720 KB
testcase_42 AC 305 ms
214,256 KB
testcase_43 AC 191 ms
131,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<ld, ld> pid;
typedef std::pair<ll, std::string> pls;
typedef std::vector<bool> vb;
typedef std::vector<vb> vvb;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vvvi> vvvvi;
typedef std::vector<ll> vl;
typedef std::vector<vl> vvl;
typedef std::vector<vvl> vvvl;
typedef std::vector<vvvl> vvvvl;
typedef std::vector<ld> vd;
typedef std::vector<vd> vvd;
typedef std::vector<std::string> vs;
#define rep(i,n) for(auto i=0; i<n; ++i)
#define repm(i,s,n) for(auto i=s; i<n; ++i)
#define repd(i,n) for(auto i=n-1; i>=0; --i)
#define repdm(i,e,n) for(auto i=n-1; i>=e; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template <class T> inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; }

template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;}
template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;}
inline void _n() { std::cout << std::endl; }
template <class T> inline void _(const T a) { std::cout << a; }
template <class T> inline void _l(const T a) { _(a); _n(); }
template <class T> inline void _s(const T a) { _(a); _(' '); }
template <class T> inline void _v(const std::vector<T> v) { for(auto a : v) _(a); }
template <class T> inline void _vl(const std::vector<T> v) { for(auto a : v) _l(a); }
template <class T> inline void _vs(const std::vector<T> v) { for(auto a : v) _s(a); _n(); }
template <class T> inline void _vvl(const std::vector<std::vector<T>> v) { for(auto a : v) { _v(a); _n(); } }
template <class T> inline void _vvs(const std::vector<std::vector<T>> v) { for(auto a : v) { _vs(a); } }
inline void ynl(const bool b) {_l(b ? "yes" : "no");}
inline void yns(const bool b) {_l(b ? "Yes" : "No");}
inline void ynu(const bool b) {_l(b ? "YES" : "NO");}

constexpr int INF = numeric_limits<int>::max() >> 1;
constexpr long long INF_LL = numeric_limits<long long>::max() >> 1LL;
const long long MOD1 = 1000000007;
const long long MOD9 = 998244353;
using mint1 = atcoder::modint1000000007;
using mint9 = atcoder::modint998244353;

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

void input() {
    
    
}


void solve() {
    
   
    int N, M; cin >> N >> M;
    
    // repm(i, 1, 100) repm(j, 1, i*i+1) { N = i; M = j;
        
    
    int pct_all = 0;
    vvi pct_mat(N, vi(N));
    rep(i, N) rep(j, N) {
        int tmp = (i+1) * (j+1);
        int pct = (int)bitset<32>(tmp).count();
        pct_mat[i][j] = 1 - (pct % 2);
        pct_all += pct_mat[i][j];
    }
    
    // _vvs(pct_mat);
    // _l(pct_all);
    
    vi cnt(N);
    rep(i, N) rep(j, N) {
        cnt[i] += 2 * pct_mat[i][j];
    }
    // _vs(cnt);
    
    int fy = pct_all - M;
    // _l(fy);
    
    vvi dp(N+1, vi(N*N + 1));
    vvi prev(N+1, vi(N*N + 1));
    dp[0][0] = 1;
    rep(i, N) {
        rep(j, N*N + 1) {
            dp[i+1][j] |= dp[i][j];
            prev[i+1][j] = prev[i][j];
            
            if(j >= cnt[i]) {
                int flg = dp[i+1][j] == 0;
                dp[i+1][j] |= dp[i][j - cnt[i]];
                if(flg && dp[i+1][j]) {
                    prev[i+1][j] = i+1;
                }
            }
        }
    }
    
    // _l(prev[N][fy]);
    
    //_vvs(dp);
    
    //_vvs(prev);
    
    if(fy >= 0 && dp[N][fy]) {
        
        int tmp_c = N;
        int tmp_s = fy;
        vi ans_y;
        while(tmp_s > 0) {
            ans_y.push_back(prev[tmp_c][tmp_s]);
            tmp_c = prev[tmp_c][tmp_s];
            tmp_s -= cnt[tmp_c-1];
        }
        sort(all(ans_y));
        
        vi ans_x;
        rep(i, N) {
            if(find(all(ans_y), i+1) == ans_y.end()) {
                ans_x.push_back(i+1);
            }
        }
        
        int tx = 0;
        rep(i, ans_x.size()) {
            rep(j, ans_x.size()) {
                tx += pct_mat[ans_x[i]-1][ans_x[j]-1];
            }
        }
        
        int ty = 0;
        rep(i, ans_y.size()) {
            rep(j, ans_y.size()) {
                ty += pct_mat[ans_y[i]-1][ans_y[j]-1];
            }
        }
        
        
        if(tx - ty == M) {
            _s(ans_x.size()); _l(ans_y.size());
            _vs(ans_x);
            _vs(ans_y);
        } else {
            _l(-1);
        }
        
        
        
    } else {
        _l(-1);
    }
    
   //  }
    
    
}

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

int main() {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    
    input();
    solve();
    
    return 0;
}
0