Submission #821389

# Submission time Handle Problem Language Result Execution time Memory
821389 2023-08-11T09:46:39 Z danikoynov Watermelon (INOI20_watermelon) C++14
7 / 100
276 ms 460 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 11;
int p[maxn], used[maxn], b[maxn], n, k;
vector < vector < int > > pw;
void check()
{
    stack < int > st;
    for (int i = 1; i <= n; i ++)
    {
        int cnt = 0;
        while(!st.empty() && p[st.top()] < p[i])
        {
            cnt ++;
            if (b[st.top()] != cnt)
                return;
            st.pop();
        }
        st.push(i);
    }
    while(!st.empty())
    {
        if (b[st.top()] != -1)
            return;
        st.pop();
    }

    vector < int > cur;
    for (int i = 1; i <= n; i ++)
        cur.push_back(p[i]);

    pw.push_back(cur);
}

bool cmp(vector < int > l, vector < int > r)
{
    for (int i = 1; i <= n; i ++)
    {
        int p1 = 0;
        while(l[p1] != i)
            p1 ++;
        int p2 = 0;
        while(r[p2] != i)
            p2 ++;
        if (p1 == p2)
            continue;
        return p1 < p2;
    }
}
void perm(int pos)
{
    if (pos == n + 1)
        check();
    else
    {
        for (int i = 1; i <= n; i ++)
        {
            if (!used[i])
            {
                p[pos] = i;
                used[i] = 1;
                perm(pos + 1);
                used[i] = 0;
                p[pos] = 0;
            }
        }
    }
}

void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i ++)
        cin >> b[i];
    perm(1);
    if (pw.size() < k)
    {
        cout << -1 << endl;
    }
    else

    {
        sort(pw.begin(), pw.end(), cmp);
        for (int v : pw[k - 1])
            cout << v <<  " ";
        cout << endl;
    }
    /**for (vector < int > cur : pw)
    {
        for (int v : cur)
            cout << v << " ";
        cout << endl;
    }*/
}

int main()
{
    solve();
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:87:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |     if (pw.size() < k)
      |         ~~~~~~~~~~^~~
Main.cpp: In function 'bool cmp(std::vector<int>, std::vector<int>)':
Main.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 24 ms 320 KB Output is correct
3 Correct 230 ms 460 KB Output is correct
4 Correct 200 ms 212 KB Output is correct
5 Correct 210 ms 284 KB Output is correct
6 Correct 21 ms 256 KB Output is correct
7 Correct 200 ms 276 KB Output is correct
8 Correct 214 ms 276 KB Output is correct
9 Correct 22 ms 212 KB Output is correct
10 Correct 22 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 221 ms 300 KB Output is correct
13 Correct 227 ms 460 KB Output is correct
14 Correct 236 ms 436 KB Output is correct
15 Correct 224 ms 352 KB Output is correct
16 Correct 222 ms 276 KB Output is correct
17 Correct 251 ms 356 KB Output is correct
18 Correct 25 ms 212 KB Output is correct
19 Correct 200 ms 212 KB Output is correct
20 Correct 206 ms 276 KB Output is correct
21 Correct 210 ms 276 KB Output is correct
22 Correct 228 ms 276 KB Output is correct
23 Correct 202 ms 212 KB Output is correct
24 Correct 276 ms 284 KB Output is correct
25 Correct 216 ms 212 KB Output is correct
26 Correct 203 ms 276 KB Output is correct
27 Correct 259 ms 284 KB Output is correct
28 Correct 207 ms 280 KB Output is correct
29 Correct 224 ms 356 KB Output is correct
30 Correct 5 ms 312 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 3 ms 308 KB Output is correct
33 Correct 3 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 24 ms 320 KB Output is correct
3 Correct 230 ms 460 KB Output is correct
4 Correct 200 ms 212 KB Output is correct
5 Correct 210 ms 284 KB Output is correct
6 Correct 21 ms 256 KB Output is correct
7 Correct 200 ms 276 KB Output is correct
8 Correct 214 ms 276 KB Output is correct
9 Correct 22 ms 212 KB Output is correct
10 Correct 22 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 221 ms 300 KB Output is correct
13 Correct 227 ms 460 KB Output is correct
14 Correct 236 ms 436 KB Output is correct
15 Correct 224 ms 352 KB Output is correct
16 Correct 222 ms 276 KB Output is correct
17 Correct 251 ms 356 KB Output is correct
18 Correct 25 ms 212 KB Output is correct
19 Correct 200 ms 212 KB Output is correct
20 Correct 206 ms 276 KB Output is correct
21 Correct 210 ms 276 KB Output is correct
22 Correct 228 ms 276 KB Output is correct
23 Correct 202 ms 212 KB Output is correct
24 Correct 276 ms 284 KB Output is correct
25 Correct 216 ms 212 KB Output is correct
26 Correct 203 ms 276 KB Output is correct
27 Correct 259 ms 284 KB Output is correct
28 Correct 207 ms 280 KB Output is correct
29 Correct 224 ms 356 KB Output is correct
30 Correct 5 ms 312 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 3 ms 308 KB Output is correct
33 Correct 3 ms 296 KB Output is correct
34 Runtime error 1 ms 340 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 24 ms 320 KB Output is correct
3 Correct 230 ms 460 KB Output is correct
4 Correct 200 ms 212 KB Output is correct
5 Correct 210 ms 284 KB Output is correct
6 Correct 21 ms 256 KB Output is correct
7 Correct 200 ms 276 KB Output is correct
8 Correct 214 ms 276 KB Output is correct
9 Correct 22 ms 212 KB Output is correct
10 Correct 22 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 221 ms 300 KB Output is correct
13 Correct 227 ms 460 KB Output is correct
14 Correct 236 ms 436 KB Output is correct
15 Correct 224 ms 352 KB Output is correct
16 Correct 222 ms 276 KB Output is correct
17 Correct 251 ms 356 KB Output is correct
18 Correct 25 ms 212 KB Output is correct
19 Correct 200 ms 212 KB Output is correct
20 Correct 206 ms 276 KB Output is correct
21 Correct 210 ms 276 KB Output is correct
22 Correct 228 ms 276 KB Output is correct
23 Correct 202 ms 212 KB Output is correct
24 Correct 276 ms 284 KB Output is correct
25 Correct 216 ms 212 KB Output is correct
26 Correct 203 ms 276 KB Output is correct
27 Correct 259 ms 284 KB Output is correct
28 Correct 207 ms 280 KB Output is correct
29 Correct 224 ms 356 KB Output is correct
30 Correct 5 ms 312 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 3 ms 308 KB Output is correct
33 Correct 3 ms 296 KB Output is correct
34 Runtime error 1 ms 340 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -