답안 #805732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
805732 2023-08-03T22:11:38 Z handlewastaken Linear Garden (IOI08_linear_garden) C++17
100 / 100
53 ms 3156 KB
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
    int n, m, i, s = 1, df = 0, odf;
    cin >> n >> m;
    char ch;
    bool a, b, c, x, y, z;
    a = b = c = true;
    vector<int> po(n / 2 + 1);
    po[0] = 1;
    for (i = 1; i <= n / 2; i++)
        po[i] = 2 * po[i - 1] % m;
    while (n--)
    {
        cin >> ch;
        odf = df;
        if (ch == 'P')
        {
            odf--;
            df++;
            x = a;
            y = b;
            z = c;
            if (odf < -2 || odf > 2)
                continue;
            if (odf < 0)
                z = false;
            if (odf > 0)
                x = false;
            if (odf == 2 || odf == -2)
                y = false;
            if (x || z)
            {
                if (df % 2 == 0)
                    s += po[n / 2];
                else
                    s += po[(n + 1) / 2];
                if (y)
                    s--;
            }
            if (y)
            {
                if (df % 2 == 0)
                    s += po[(n + 1) / 2];
                else
                    s += po[n / 2];
            }
            s %= m;
        }
        else
            df--;
        if (df < 0)
            c = false;
        if (df > 0)
            a = false;
        if (df == 2 || df == -2)
            b = false;
    }
    cout << s;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2260 KB Output is correct
2 Correct 51 ms 3156 KB Output is correct
3 Correct 53 ms 3120 KB Output is correct