Submission #485075

# Submission time Handle Problem Language Result Execution time Memory
485075 2021-11-06T03:30:18 Z nhanbin03 Watermelon (INOI20_watermelon) C++14
7 / 100
2000 ms 1676 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 + 1);
        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

Main.cpp: In function 'int main()':
Main.cpp:68:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     if (k > lst.size()) {
      |         ~~^~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task ".ans","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 204 KB Output is correct
2 Correct 97 ms 288 KB Output is correct
3 Correct 833 ms 620 KB Output is correct
4 Correct 805 ms 272 KB Output is correct
5 Correct 818 ms 272 KB Output is correct
6 Correct 81 ms 204 KB Output is correct
7 Correct 802 ms 272 KB Output is correct
8 Correct 840 ms 268 KB Output is correct
9 Correct 83 ms 272 KB Output is correct
10 Correct 87 ms 284 KB Output is correct
11 Correct 12 ms 204 KB Output is correct
12 Correct 838 ms 384 KB Output is correct
13 Correct 826 ms 528 KB Output is correct
14 Correct 880 ms 452 KB Output is correct
15 Correct 921 ms 376 KB Output is correct
16 Correct 875 ms 452 KB Output is correct
17 Correct 832 ms 300 KB Output is correct
18 Correct 81 ms 296 KB Output is correct
19 Correct 836 ms 272 KB Output is correct
20 Correct 837 ms 272 KB Output is correct
21 Correct 819 ms 284 KB Output is correct
22 Correct 836 ms 268 KB Output is correct
23 Correct 823 ms 276 KB Output is correct
24 Correct 815 ms 272 KB Output is correct
25 Correct 854 ms 324 KB Output is correct
26 Correct 823 ms 276 KB Output is correct
27 Correct 840 ms 272 KB Output is correct
28 Correct 827 ms 268 KB Output is correct
29 Correct 825 ms 304 KB Output is correct
30 Correct 9 ms 296 KB Output is correct
31 Correct 9 ms 292 KB Output is correct
32 Correct 9 ms 204 KB Output is correct
33 Correct 9 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 204 KB Output is correct
2 Correct 97 ms 288 KB Output is correct
3 Correct 833 ms 620 KB Output is correct
4 Correct 805 ms 272 KB Output is correct
5 Correct 818 ms 272 KB Output is correct
6 Correct 81 ms 204 KB Output is correct
7 Correct 802 ms 272 KB Output is correct
8 Correct 840 ms 268 KB Output is correct
9 Correct 83 ms 272 KB Output is correct
10 Correct 87 ms 284 KB Output is correct
11 Correct 12 ms 204 KB Output is correct
12 Correct 838 ms 384 KB Output is correct
13 Correct 826 ms 528 KB Output is correct
14 Correct 880 ms 452 KB Output is correct
15 Correct 921 ms 376 KB Output is correct
16 Correct 875 ms 452 KB Output is correct
17 Correct 832 ms 300 KB Output is correct
18 Correct 81 ms 296 KB Output is correct
19 Correct 836 ms 272 KB Output is correct
20 Correct 837 ms 272 KB Output is correct
21 Correct 819 ms 284 KB Output is correct
22 Correct 836 ms 268 KB Output is correct
23 Correct 823 ms 276 KB Output is correct
24 Correct 815 ms 272 KB Output is correct
25 Correct 854 ms 324 KB Output is correct
26 Correct 823 ms 276 KB Output is correct
27 Correct 840 ms 272 KB Output is correct
28 Correct 827 ms 268 KB Output is correct
29 Correct 825 ms 304 KB Output is correct
30 Correct 9 ms 296 KB Output is correct
31 Correct 9 ms 292 KB Output is correct
32 Correct 9 ms 204 KB Output is correct
33 Correct 9 ms 204 KB Output is correct
34 Execution timed out 2083 ms 332 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 1676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 1676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 204 KB Output is correct
2 Correct 97 ms 288 KB Output is correct
3 Correct 833 ms 620 KB Output is correct
4 Correct 805 ms 272 KB Output is correct
5 Correct 818 ms 272 KB Output is correct
6 Correct 81 ms 204 KB Output is correct
7 Correct 802 ms 272 KB Output is correct
8 Correct 840 ms 268 KB Output is correct
9 Correct 83 ms 272 KB Output is correct
10 Correct 87 ms 284 KB Output is correct
11 Correct 12 ms 204 KB Output is correct
12 Correct 838 ms 384 KB Output is correct
13 Correct 826 ms 528 KB Output is correct
14 Correct 880 ms 452 KB Output is correct
15 Correct 921 ms 376 KB Output is correct
16 Correct 875 ms 452 KB Output is correct
17 Correct 832 ms 300 KB Output is correct
18 Correct 81 ms 296 KB Output is correct
19 Correct 836 ms 272 KB Output is correct
20 Correct 837 ms 272 KB Output is correct
21 Correct 819 ms 284 KB Output is correct
22 Correct 836 ms 268 KB Output is correct
23 Correct 823 ms 276 KB Output is correct
24 Correct 815 ms 272 KB Output is correct
25 Correct 854 ms 324 KB Output is correct
26 Correct 823 ms 276 KB Output is correct
27 Correct 840 ms 272 KB Output is correct
28 Correct 827 ms 268 KB Output is correct
29 Correct 825 ms 304 KB Output is correct
30 Correct 9 ms 296 KB Output is correct
31 Correct 9 ms 292 KB Output is correct
32 Correct 9 ms 204 KB Output is correct
33 Correct 9 ms 204 KB Output is correct
34 Execution timed out 2083 ms 332 KB Time limit exceeded
35 Halted 0 ms 0 KB -