답안 #741415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741415 2023-05-14T04:36:44 Z Trigbluy Modern Machine (JOI23_ho_t5) C++14
15 / 100
3000 ms 2028 KB
#include <bits/stdc++.h>

using namespace std;

vector <int> lits, buttons;

int main ()
{
    int n, m, q;
    cin >> n >> m;

    char a;
    cin >> a;
    lits.push_back(a == 'R');

    for (int i = 1; i < n; i++)
    {
        char a;
        cin >> a;
        lits.push_back(lits[i-1] + (a == 'R'));
    }

    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        buttons.push_back(a - 1);
    }

    cin >> q;

    while (q--)
    {
        int l,r;
        cin >> l >> r;
        
        int md = 0, me = 0, pa = 0;

        for (int b = l - 1; b < r; b++)
        {
            int pos = buttons[b];
            int a,v;

            if (me + md < n)
            {
                if (0 <= pos && pos < me)
                {
                    a = md + ((n - md - me) - (lits[n - md - 1] - ((me > 0)? lits[me - 1] : 0)));
                    v = pos;
                }
                else if (me <= pos && pos < n - md)
                {
                    a = md + ((n - md - pos - 1) - (lits[n - md - 1] - lits[pos]));
                    v = me + ((pos > 0? lits[pos - 1] : 0) - ((me > 0)? lits[me - 1] : 0));
                }
                else
                {
                    a = n - 1 - pos;
                    v = me + (lits[n - md - 1] - ((me > 0)? lits[me - 1] : 0));
                }

                if (v>=a)
                {
                    int av;
                    for (av  = pos - 1; a > 0 && av >= 0; av--)
                        if ((((lits[av] - (av > 0? lits[av - 1] : 0)) == 1) && !(av >= n - md)) || (av < me))
                            a--;
                    av++;
                    
                    md = ((n - av) > md)? n - av : md;

                    if (me + md >= n)
                    {
                        pa = n - md;
                    }
                }
                else
                {
                    int va;
                    for (va = pos + 1; v >= 0 && va < n; va++)
                        if (((lits [va] - lits[va - 1] == 0 && !(va < me))) || (va >= n - md))
                            v--;

                    me = (va > me)? va : me;

                    if (me + md >= n)
                    {
                        pa = me;
                    }
                }
            }
            else
            {
                if (pos >= pa)
                {
                    a = n - pos - 1;
                    v = pa;

                    if (a > v)
                        pa = pos + 1 + v + 1;
                    else
                        pa = pa - a;
                }
                else
                {
                    a = n - pa;
                    v = pos;

                    if (a > v)
                        pa = pa + v + 1;
                    else
                        pa = pos - a;
                }
            }
            //cout << me << '-' << md << '-' << pa << '\n';
        }

        if (me + md < n)
            cout << me + lits[n - md - 1] - (me>0? lits[me - 1] : 0) << '\n';
        else
            cout << pa << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 13 ms 420 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 5 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 13 ms 420 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 5 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Execution timed out 3016 ms 2028 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3048 ms 1316 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3048 ms 1316 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3048 ms 1316 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 13 ms 420 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 5 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Execution timed out 3016 ms 2028 KB Time limit exceeded
19 Halted 0 ms 0 KB -