QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#280426 | #7778. Turning Permutation | ucup-team1516# | WA | 2ms | 11680kb | C++20 | 3.8kb | 2023-12-09 16:01:39 | 2023-12-09 16:01:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
if(x > y) {
x = y;
return true;
} else return false;
}
template<class T> bool chmax(T& x, T y){
if(x < y) {
x = y;
return true;
} else return false;
}
// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )
#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)
// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)
// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)
// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)
// for_earh
#define fore(e, v) for (auto&& e : v)
// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
ll n, K;
int128 dp[60][60][60][60];
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n >> K;
dp[2][0][1][2] = 1, dp[2][1][0][1] = 1;
rep (i, 2, n + 1) { // i + 1を新たに追加
// imosパート
rep (j, i) rep (k, i) rep (x, 1, i + 1) {
dp[i][j + 1][k][x] += dp[i][j][k][x];
chmin(dp[i][j][k][x], (int128)(K + 1));
}
// i + 1を挿入
rep (j, i) rep (k, i) rep (x, 1, i + 1) {
int128 val = dp[i][j][k][x];
if (j < k) {
dp[i + 1][j + 1][j][x] += val;
dp[i + 1][i + 1][j][x] -= val;
} else if (j > k) {
dp[i + 1][1][j + 1][x] += val;
dp[i + 1][j + 1][j + 1][x] -= val;
dp[i + 1][0][j + 1][i + 1] += val;
dp[i + 1][1][j + 1][i + 1] -= val;
}
}
}
int128 sum = 0;
rep (j, n) rep (k, n) rep (x, 1, n + 1) sum += dp[n][j][k][x];
if (sum < K) {
cout << -1 << '\n';
return 0;
}
vector<int> ans;
vector<int> nums;
rep (i, 1, n + 1) nums.push_back(i);
rrep (i, 2, n + 1) {
rep (x, 1, i + 1) {
sum = 0;
rep (j, i) rep (k, i) sum += dp[i][j][k][x];
if (sum >= K) {
ans.push_back(nums[x - 1]);
nums.erase(nums.begin() + x - 1);
break;
} else {
K -= sum;
}
}
}
ans.push_back(nums[0]);
rep (i, n) cout << ans[i] << " \n"[i == n - 1];
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9576kb
input:
3 2
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9612kb
input:
3 5
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 11680kb
input:
4 6
output:
3 1 2 4
result:
ok 4 number(s): "3 1 2 4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 11624kb
input:
4 11
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 9660kb
input:
3 1
output:
1 2 3
result:
wrong answer 2nd numbers differ - expected: '3', found: '2'