結果
| 問題 | No.1530 Permutation and Popcount |
| コンテスト | |
| ユーザー |
penguinman
|
| 提出日時 | 2021-06-03 06:34:18 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.90.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,181 bytes |
| 記録 | |
| コンパイル時間 | 8,797 ms |
| コンパイル使用メモリ | 337,068 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-20 17:40:02 |
| 合計ジャッジ時間 | 13,622 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 41 |
ソースコード
#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();
}
penguinman