結果
問題 | No.1311 Reverse Permutation Index |
ユーザー |
![]() |
提出日時 | 2020-12-08 01:38:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 1,001 bytes |
コンパイル時間 | 756 ms |
コンパイル使用メモリ | 93,348 KB |
最終ジャッジ日時 | 2025-01-16 19:26:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cstring>#include <cstdlib>#include <cmath>using namespace std;using ll = long long;int main() {ll k;cin >> k;int n;cin >> n;vector<int> p(n), q(n);for (int i = n; --i >= 0;) {int b = n - i;p[i] = k % b; k /= b;}vector<int> o(n, 0);for (int i = 0; i < n; i++) {int t = p[i];for (int j = 0; j < n; j++) {if (o[j] == 0 && t-- == 0) {o[p[i] = j] = 1;break;}}}for (int i = 0; i < n; i++) {q[p[i]] = i;}o.assign(n, 0);for (int i = 0; i < n; i++) {int t = 0;for (int j = q[i]; --j >= 0;) {t += o[j] == 0;}o[q[i]] = 1;q[i] = t;}for (int i = 0; i < n; i++) {int b = n - i;k *= b;k += q[i];}cout << k << endl;return 0;}