Submission #768764

# Submission time Handle Problem Language Result Execution time Memory
768764 2023-06-28T14:50:47 Z danikoynov Festivals in JOI Kingdom 2 (JOI23_festival2) C++14
5 / 100
9000 ms 340 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 = 20;
int n, mod, used[maxn], p[maxn], visit[maxn];
int l[maxn], r[maxn], ans;
void check()
{
    int d = 1;
    for (int i = 1; i <= 2 * n; i += 2)
    {
        l[d] = p[i];
        r[d] = p[i + 1];
        d ++;
    }

    for (int i = 1; i <= n; i ++)
    {
        if (l[i] > r[i])
            return;
        if (i != 1 && l[i] < l[i - 1])
            return;
        visit[i] = 0;
    }
    int to = 0, cur = 0;
    for (int i = 1; i <= n; i ++)
    {
        if (to < l[i])

        {
            cur ++;
            visit[i] = 1;
            to = r[i];
        }
    }


    /**cout << "---------" << endl;
    for (int i = 1; i <= n; i ++)
        cout << l[i] << " " << r[i] << endl;*/

    int best = 0;
    to = 0;
    while(true)
    {
        int mx = -1;
        for (int i = 1; i <= n; i ++)
        {
            if (l[i] > to)
            {
                if (mx == -1 || r[i] < r[mx])
                    mx = i;
            }
        }
        if (mx == -1)
            break;
        to = r[mx];
        best ++;
    }
    if (best > cur)
        ans ++;
}
void perm(int pos)
{
    if (pos == 2 * n + 1)
        check();
    else
    {
        for (int i = 1; i <= 2 * n; i ++)
        {
            if (used[i] == 0)
            {
                used[i] = 1;
                p[pos] = i;
                perm(pos + 1);
                p[pos] = 0;
                used[i] = 0;
            }
        }
    }
}
void solve()
{
    cin >> n >> mod;
    perm(1);
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 108 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 108 ms 292 KB Output is correct
8 Execution timed out 9025 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 108 ms 292 KB Output is correct
8 Execution timed out 9025 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 108 ms 292 KB Output is correct
8 Execution timed out 9025 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 108 ms 292 KB Output is correct
8 Execution timed out 9025 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 108 ms 292 KB Output is correct
8 Execution timed out 9025 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -