結果
| 問題 |
No.1530 Permutation and Popcount
|
| コンテスト | |
| ユーザー |
penguinman
|
| 提出日時 | 2021-06-03 06:42:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 2,207 bytes |
| コンパイル時間 | 9,201 ms |
| コンパイル使用メモリ | 328,440 KB |
| 最終ジャッジ日時 | 2025-01-21 21:18:46 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 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());
registerValidation();
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