제출 #1233125

#제출 시각아이디문제언어결과실행 시간메모리
1233125fermatBali Sculptures (APIO15_sculpture)C++20
100 / 100
112 ms11108 KiB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2005;

int n, a, b, ar[N], cnt;

bool dp[N][N], u[N];

long long ans, sum, pref[N], Dp[N];

vector < vector <int> > g;
queue <int> q;

main()
{
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)
        scanf("%d", &ar[i]), pref[i] = pref[i - 1] + ar[i];

    if (n > 100)
    {
        for (int k = 40; k >= 0; k--)
        {
            g.clear();
            g.resize(n + 1);

            for (int i = 1; i <= n; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if ( ( ans | ( ( (pref[i] - pref[j]) >> k) << k) ) == ans )
                        g[j].push_back(i);
                }
            }
            long long cur = (1LL << k);

            memset(Dp, 0, sizeof(Dp) );

            Dp[0] = 1;
            q.push(0);

            while (!q.empty())
            {
                int v = q.front();
                q.pop();
                for (auto to : g[v])
                {
                    if ( !Dp[to] )
                    {
                        Dp[to] = Dp[v] + 1;
                        q.push(to);
                    }
                }
            }
            bool fl = 0;

            if (Dp[n] == 0 || Dp[n] - 1 > b)
                ans += cur;
        }
        cout << ans << endl;
    }
    else
    {
        for (int k = 40; k >= 0; k--)
        {
            long long cur = (1LL << k);

            memset(dp, 0, sizeof(dp) );

            dp[0][0] = 1;

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int l = 1; l <= j; l++)
                    {
                        if ( ( ans | ( ( (pref[j] - pref[l - 1]) >> k) << k) ) == ans  )
                            dp[i][j] |= dp[i - 1][l - 1];
                    }
                }
            }
            bool fl = 0;

            for (int i = a; i <= b; i++)
                fl |= dp[i][n];

            if (!fl)
                ans += cur;
        }
        cout << ans << endl;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

sculpture.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main()
      | ^~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d", &ar[i]), pref[i] = pref[i - 1] + ar[i];
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...