답안 #643436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643436 2022-09-22T03:27:56 Z cologne Broken Device 2 (JOI22_device2) C++17
92 / 100
76 ms 2980 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

namespace
{
    const int MAX = 150;
    bool inited = false;
    vector<long long> D(MAX + 1);
    void init()
    {
        if (inited)
            return;
        inited = true;
        D[0] = 1, D[1] = 0, D[2] = 1;
        for (int i = 3; i < MAX; i++)
            D[i] = D[i - 2] + D[i - 3];
    }
}

int Declare()
{
    init();
    return MAX;
}

pair<vector<int>, vector<int>> Asolve(int sz, long long A)
{
    vector<int> U, V;
    for (int i = 0; i < sz; i++)
        V.push_back(i & 1);

    int lst = 0;

    for (int i = 0; i < 2; i++)
        U.push_back(A >= D[sz - 2] ? 1 : 0);
    if (A >= D[sz - 2])
        A -= D[sz - 2], lst = 1;
    sz -= 2;

    while (sz)
    {
        if (lst == 1)
        {
            if (sz == 4 || sz == 2 || A >= D[sz - 3])
            {
                for (int i = 0; i < 2; i++)
                    U.push_back(1);
                A -= D[sz - 3];
                sz -= 2;
            }
            else
            {
                lst = 0;
                for (int i = 0; i < 3; i++)
                    U.push_back(0);
                sz -= 3;
            }
        }
        else
        {
            if (sz == 3 || A >= D[sz - 2])
            {
                lst = 1;
                for (int i = 0; i < 3; i++)
                    U.push_back(1);
                A -= D[sz - 2];
                sz -= 3;
            }
            else
            {
                for (int i = 0; i < 2; i++)
                    U.push_back(0);
                sz -= 2;
            }
        }
    }
    return {U, V};
}

pair<vector<int>, vector<int>> Anna(long long A)
{
    --A;
    for (int i = 2; i <= MAX; i++)
    {
        if (A >= 2 * D[i - 2])
            A -= 2 * D[i - 2];
        else
            return Asolve(i, A);
    }
    assert(false);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;

namespace
{
    const int MAX = 150;
    bool inited = false;
    vector<long long> D(MAX + 1);
    void init()
    {
        if (inited)
            return;
        inited = true;
        D[0] = 1, D[1] = 0, D[2] = 1;
        for (int i = 3; i < MAX; i++)
            D[i] = D[i - 2] + D[i - 3];
    }
}

long long bsolve(vector<int> u)
{
    int N = u.size() / 2, rem = N, prv = -1;
    long long ret = 0;

    int state = 1, ulimit = 3, ucount = 2;
    long long uplus = D[rem - 2];
    int dlimit = -3, dcount = 2;
    for (int v : u)
    {
        state += v * 4 - 2;
        if (state == ulimit)
        {
            ret += uplus;
            rem -= ucount;
            ulimit = state + 4;
            ucount = 2;
            uplus = rem >= 3 ? D[rem - 3] : 0;
            dlimit = state - 4;
            dcount = 3;
        }
        else if (state == dlimit)
        {
            rem -= dcount;
            ulimit = state + 4;
            ucount = 3;
            uplus = rem >= 2 ? D[rem - 2] : 0;
            dlimit = state - 4;
            dcount = 2;
        }
    }

    return ret;
}

long long Bruno(vector<int> u)
{
    init();
    long long ans = 1;
    for (int i = 2; i < (int)u.size() / 2; i++)
        ans += 2 * D[i - 2];
    return ans + bsolve(u);
}

Compilation message

Bruno.cpp: In function 'long long int bsolve(std::vector<int>)':
Bruno.cpp:23:36: warning: unused variable 'prv' [-Wunused-variable]
   23 |     int N = u.size() / 2, rem = N, prv = -1;
      |                                    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 612 KB Output is correct
2 Correct 13 ms 936 KB Output is correct
3 Correct 16 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 612 KB Output is correct
2 Correct 13 ms 936 KB Output is correct
3 Correct 16 ms 992 KB Output is correct
4 Correct 30 ms 1252 KB Output is correct
5 Correct 27 ms 1328 KB Output is correct
6 Correct 26 ms 1328 KB Output is correct
7 Correct 37 ms 1352 KB Output is correct
8 Correct 26 ms 1340 KB Output is correct
9 Correct 25 ms 1488 KB Output is correct
10 Correct 26 ms 1336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 612 KB Output is correct
2 Correct 13 ms 936 KB Output is correct
3 Correct 16 ms 992 KB Output is correct
4 Correct 30 ms 1252 KB Output is correct
5 Correct 27 ms 1328 KB Output is correct
6 Correct 26 ms 1328 KB Output is correct
7 Correct 37 ms 1352 KB Output is correct
8 Correct 26 ms 1340 KB Output is correct
9 Correct 25 ms 1488 KB Output is correct
10 Correct 26 ms 1336 KB Output is correct
11 Correct 28 ms 1448 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 34 ms 1552 KB Output is correct
14 Correct 27 ms 1484 KB Output is correct
15 Correct 35 ms 1500 KB Output is correct
16 Correct 26 ms 1488 KB Output is correct
17 Correct 26 ms 1500 KB Output is correct
18 Correct 27 ms 1484 KB Output is correct
19 Correct 27 ms 1472 KB Output is correct
20 Correct 28 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 612 KB Output is correct
2 Correct 13 ms 936 KB Output is correct
3 Correct 16 ms 992 KB Output is correct
4 Correct 30 ms 1252 KB Output is correct
5 Correct 27 ms 1328 KB Output is correct
6 Correct 26 ms 1328 KB Output is correct
7 Correct 37 ms 1352 KB Output is correct
8 Correct 26 ms 1340 KB Output is correct
9 Correct 25 ms 1488 KB Output is correct
10 Correct 26 ms 1336 KB Output is correct
11 Correct 28 ms 1448 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 34 ms 1552 KB Output is correct
14 Correct 27 ms 1484 KB Output is correct
15 Correct 35 ms 1500 KB Output is correct
16 Correct 26 ms 1488 KB Output is correct
17 Correct 26 ms 1500 KB Output is correct
18 Correct 27 ms 1484 KB Output is correct
19 Correct 27 ms 1472 KB Output is correct
20 Correct 28 ms 1404 KB Output is correct
21 Correct 32 ms 1456 KB Output is correct
22 Correct 34 ms 1672 KB Output is correct
23 Correct 31 ms 1636 KB Output is correct
24 Correct 31 ms 1744 KB Output is correct
25 Correct 31 ms 1640 KB Output is correct
26 Correct 30 ms 1720 KB Output is correct
27 Correct 31 ms 1668 KB Output is correct
28 Correct 28 ms 1564 KB Output is correct
29 Correct 27 ms 1516 KB Output is correct
30 Correct 27 ms 1600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 612 KB Output is correct
2 Correct 13 ms 936 KB Output is correct
3 Correct 16 ms 992 KB Output is correct
4 Correct 30 ms 1252 KB Output is correct
5 Correct 27 ms 1328 KB Output is correct
6 Correct 26 ms 1328 KB Output is correct
7 Correct 37 ms 1352 KB Output is correct
8 Correct 26 ms 1340 KB Output is correct
9 Correct 25 ms 1488 KB Output is correct
10 Correct 26 ms 1336 KB Output is correct
11 Correct 28 ms 1448 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 34 ms 1552 KB Output is correct
14 Correct 27 ms 1484 KB Output is correct
15 Correct 35 ms 1500 KB Output is correct
16 Correct 26 ms 1488 KB Output is correct
17 Correct 26 ms 1500 KB Output is correct
18 Correct 27 ms 1484 KB Output is correct
19 Correct 27 ms 1472 KB Output is correct
20 Correct 28 ms 1404 KB Output is correct
21 Correct 32 ms 1456 KB Output is correct
22 Correct 34 ms 1672 KB Output is correct
23 Correct 31 ms 1636 KB Output is correct
24 Correct 31 ms 1744 KB Output is correct
25 Correct 31 ms 1640 KB Output is correct
26 Correct 30 ms 1720 KB Output is correct
27 Correct 31 ms 1668 KB Output is correct
28 Correct 28 ms 1564 KB Output is correct
29 Correct 27 ms 1516 KB Output is correct
30 Correct 27 ms 1600 KB Output is correct
31 Correct 39 ms 2056 KB Output is correct
32 Correct 39 ms 2028 KB Output is correct
33 Correct 42 ms 2012 KB Output is correct
34 Correct 40 ms 2108 KB Output is correct
35 Correct 39 ms 2136 KB Output is correct
36 Correct 39 ms 1980 KB Output is correct
37 Correct 36 ms 2156 KB Output is correct
38 Correct 40 ms 1888 KB Output is correct
39 Correct 44 ms 1948 KB Output is correct
40 Correct 37 ms 1968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 60 ms 2884 KB Output is partially correct
2 Partially correct 61 ms 2896 KB Output is partially correct
3 Partially correct 70 ms 2904 KB Output is partially correct
4 Partially correct 76 ms 2836 KB Output is partially correct
5 Partially correct 59 ms 2960 KB Output is partially correct
6 Partially correct 59 ms 2944 KB Output is partially correct
7 Partially correct 61 ms 2980 KB Output is partially correct
8 Partially correct 65 ms 2920 KB Output is partially correct
9 Partially correct 60 ms 2928 KB Output is partially correct
10 Partially correct 59 ms 2880 KB Output is partially correct
11 Partially correct 62 ms 2928 KB Output is partially correct
12 Partially correct 60 ms 2840 KB Output is partially correct
13 Partially correct 60 ms 2948 KB Output is partially correct
14 Partially correct 65 ms 2960 KB Output is partially correct
15 Partially correct 62 ms 2812 KB Output is partially correct
16 Partially correct 55 ms 2720 KB Output is partially correct
17 Partially correct 56 ms 2652 KB Output is partially correct
18 Partially correct 59 ms 2756 KB Output is partially correct
19 Partially correct 52 ms 2752 KB Output is partially correct
20 Partially correct 55 ms 2684 KB Output is partially correct