# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
485074 | 2021-11-06T03:23:37 Z | nhanbin03 | Watermelon (INOI20_watermelon) | C++14 | 2000 ms | 1844 KB |
#include <bits/stdc++.h> #define task "INOI20_watermelon" #define X first #define Y second #define left ___left #define right ___right using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 0 + 10; int main() { // cin.tie(0)->sync_with_stdio(0); // cout.tie(0); if (fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".ans","w",stdout); } int n, k; cin >> n >> k; vector<int> a(n), v(n); for (int i = 0; i < n; i++) { cin >> a[i]; v[i] = i; } vector<vector<int>> lst; do { vector<int> ans(n); for (int i = 0; i < n; i++) { ans[v[i]] = i; } vector<int> left(n + 2), right(n + 2); for (int i = 0; i <= n; i++) { left[i + 1] = i; right[i] = i + 1; } vector<int> cmp(n, -1); int cnt = 0; while (++cnt) { bool changed = 0; for (int i = right[0]; i <= n; i = right[i]) { // cout << i << endl; if (ans[i - 1] < ans[right[i] - 1]) { right[left[i]] = right[i]; left[right[i]] = left[i]; changed = 1; cmp[i - 1] = cnt; } } if (changed == 0) break; } bool ok = 1; for (int i = 0; i < n; i++) { if (cmp[i] != a[i]) ok = 0; } if (ok) lst.push_back(v); // cout << endl; // for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; // for (int i = 0; i < n; i++) cout << cmp[i] << " "; cout << endl; } while (next_permutation(v.begin(), v.end())); sort(lst.begin(), lst.end()); if (k > lst.size()) { cout << -1; return 0; } vector<int> ans(n); for (int i = 0; i < n; i++) { ans[lst[k - 1][i]] = i + 1; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 204 KB | Output is correct |
2 | Correct | 78 ms | 296 KB | Output is correct |
3 | Incorrect | 809 ms | 272 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 204 KB | Output is correct |
2 | Correct | 78 ms | 296 KB | Output is correct |
3 | Incorrect | 809 ms | 272 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2084 ms | 1844 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2084 ms | 1844 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 204 KB | Output is correct |
2 | Correct | 78 ms | 296 KB | Output is correct |
3 | Incorrect | 809 ms | 272 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |