Submission #991861

# Submission time Handle Problem Language Result Execution time Memory
991861 2024-06-03T09:33:06 Z danikoynov Security Gate (JOI18_security_gate) C++14
12 / 100
5000 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 ll mod = 1000000007;

int n;
string s;

void solve()
{
    cin >> n >> s;
    s = "#" + s;
    int cnt = 0;
    for (int i = 1; i <= n; i ++)
    {
        if (s[i] == 'x')
            cnt ++;
    }

    int res = 0;
    for (int mask = 0; mask < (1 << cnt); mask ++)
    {
        int bit = 0;
        string t = s;
        for (int i = 1; i <= n; i ++)
        {
            if (t[i] == 'x')
            {
                //cout << "here " << mask << " " << bit << " " << (mask & (1 << bit)) << endl;
                if ((mask & (1 << bit)) > 0)
                    t[i] = '(';
                else
                    t[i] = ')';
                bit ++;
            }
        }


        bool done = false;
        for (int i = 1; i <= n; i ++)
            for (int j = i; j <= n; j ++)
            {
                int pf = 0;

                bool tf = true;
                for (int d = 1; d <= n; d ++)
                {
                    int c = -1;
                    if (t[d] == '(')
                        c = 1;
                    if (d >= i && d <= j)
                        c *= -1;
                    pf += c;
                    if (pf < 0)
                    {
                        tf = false;
                        break;
                    }
                }
                if (pf != 0)
                    tf = false;
                if (tf)
                {
                    ///cout << i << " : " << j << endl;
                    done = true;
                    break;
                }
            }
        int pf = 0;

        bool tf = true;
        for (int d = 1; d <= n; d ++)
        {
            int c = -1;
            if (t[d] == '(')
                c = 1;
            pf += c;
            if (pf < 0)
            {
                tf = false;
                break;
            }
        }
        if (pf != 0)
            tf = false;
        if (tf)
        {
            ///cout << i << " : " << j << endl;
            done = true;
        }
        if (done)
            res ++;

        ///cout << t << " " << done << endl;
    }
    cout << res << endl;
}

int main()
{
    speed();
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 6 ms 456 KB Output is correct
21 Correct 372 ms 348 KB Output is correct
22 Correct 1707 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 341 ms 428 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 29 ms 348 KB Output is correct
27 Correct 350 ms 432 KB Output is correct
28 Correct 23 ms 348 KB Output is correct
29 Correct 52 ms 432 KB Output is correct
30 Correct 27 ms 348 KB Output is correct
31 Correct 654 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 6 ms 456 KB Output is correct
21 Correct 372 ms 348 KB Output is correct
22 Correct 1707 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 341 ms 428 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 29 ms 348 KB Output is correct
27 Correct 350 ms 432 KB Output is correct
28 Correct 23 ms 348 KB Output is correct
29 Correct 52 ms 432 KB Output is correct
30 Correct 27 ms 348 KB Output is correct
31 Correct 654 ms 436 KB Output is correct
32 Correct 162 ms 348 KB Output is correct
33 Correct 47 ms 348 KB Output is correct
34 Execution timed out 5039 ms 348 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 6 ms 456 KB Output is correct
21 Correct 372 ms 348 KB Output is correct
22 Correct 1707 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 341 ms 428 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 29 ms 348 KB Output is correct
27 Correct 350 ms 432 KB Output is correct
28 Correct 23 ms 348 KB Output is correct
29 Correct 52 ms 432 KB Output is correct
30 Correct 27 ms 348 KB Output is correct
31 Correct 654 ms 436 KB Output is correct
32 Correct 162 ms 348 KB Output is correct
33 Correct 47 ms 348 KB Output is correct
34 Execution timed out 5039 ms 348 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 6 ms 456 KB Output is correct
21 Correct 372 ms 348 KB Output is correct
22 Correct 1707 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 341 ms 428 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 29 ms 348 KB Output is correct
27 Correct 350 ms 432 KB Output is correct
28 Correct 23 ms 348 KB Output is correct
29 Correct 52 ms 432 KB Output is correct
30 Correct 27 ms 348 KB Output is correct
31 Correct 654 ms 436 KB Output is correct
32 Correct 162 ms 348 KB Output is correct
33 Correct 47 ms 348 KB Output is correct
34 Execution timed out 5039 ms 348 KB Time limit exceeded
35 Halted 0 ms 0 KB -