| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1292955 | binminh01 | Watermelon (INOI20_watermelon) | C++20 | 2093 ms | 1608 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn = 1e5 + 5;
ll n, a[mn], k, b[mn], s[mn];
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; ++i) a[i] = i, cin >> s[i];
do {
for(int i = n; i >= 1; --i){
b[i] = -1;
ll pot = 1;
for(int j = i + 1; j <= n; ++j){
if(a[j] > a[i] && (b[j] == -1 || pot <= b[j])){
b[i] = pot;
break;
}
if(b[j] == -1) break;
pot = max(pot, b[j] + 1);
}
}
ll c = 1;
for(int i = 1; i <= n; ++i){
c &= (b[i] == s[i]);
}
k -= c;
// for(int i = 1)
if(k == 0){
for(int i = 1; i <= n; ++i) cout << a[i] << " ";
return;
}
} while (next_permutation(a + 1, a + n + 1));
cout << -1;
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if(fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
int testCase = 1;
//cin >> testCase;
while(testCase--) solve();
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
