Submission #154775

# Submission time Handle Problem Language Result Execution time Memory
154775 2019-09-24T15:06:36 Z jacynkaa Bali Sculptures (APIO15_sculpture) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <math.h>
#include <chrono>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10) //cin.tie(0); cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define what(x) cerr << #x << " is " << x << endl;
#define int long long

const int MAXN = 2e3 + 10;
const int MAXK = 44; //UWAGA

unsigned int E[MAXN][MAXN];
int n, a, b;
int tab[MAXN];
pii dist[MAXN];
int shortest[MAXN];
bitset<MAXN> wszystkie[MAXN];

void mini(pii A, pii &B)
{
    B.st = min(B.st, A.st + 1);
    B.nd = max(B.nd, A.nd + 1);
}

bool solveHeura(int q) //czy wynik zawiera sie na inkluzje w q
{
    fill(dist, dist + MAXN, mp(100000, -100000));
    dist[0] = {0, 0};

    rep(i, n) for (int k = i + 1; k <= n; k++)
    {
        if ((E[i][k] | q) == q)
            mini(dist[i], dist[k]);
    }
    //bitset<64> D(q);
    //cerr << D << " " << dist[n].st << " " << dist[n].nd << endl;
    return (dist[n].st <= b && dist[n].nd >= a);
}

bool solveShortest(int q)
{
    fill(shortest, shortest + MAXN, 1e9);
    shortest[0] = 0;
    rep(i, n) for (int k = i + 1; k <= n; k++)
    {
        if ((E[i][k] | q) == q)
            shortest[k] = min(shortest[k], shortest[i] + 1);
    }
    //cerr << shortest[n] << endl;
    return shortest[n] <= b;
}

bool solveBitset(int q)
{
    rep(i, n + 1) wszystkie[i].reset();
    wszystkie[0][0] = true;
    rep(i, n) for (int k = i + 1; k <= n; k++)
    {
        if ((E[i][k] | q) == q)
            wszystkie[k] = (wszystkie[k] | (wszystkie[i] << 1));
    }
    for (int i = a; i <= b; i++)
        if (wszystkie[n][i])
            return true;
    return false;
}

void Heura1(int &wynik)
{
    for (int k = MAXK; k >= 0; k--)
        if (!solveHeura(wynik + (1ll << k) - 1))
            wynik += (1ll << k);
}
void Heura2(int &wynik)
{
    wzorShortest(wynik);
}

void wzorShortest(int &wynik)
{
    for (int k = MAXK; k >= 0; k--)
        if (!solveShortest(wynik + (1ll << k) - 1))
            wynik += (1ll << k);
}

void wzorBitset(int &wynik)
{
    for (int k = MAXK; k >= 0; k--)
        if (!solveBitset(wynik + (1ll << k) - 1))
            wynik += (1ll << k);
}

void wzor(int &wynik)
{
    if (a == 1)
        wzorShortest(wynik);
    else
        wzorBitset(wynik);
}

void slow(int &wynik)
{
    int x = accumulate(tab, tab + n, 0) + 2;
    rep(i, x) if ((a == 1) ? solveShortest(i) : solveBitset(i))
    {
        wynik = i;
        return;
    }
}

void brut(int &wynik)
{
    wynik = 1e18;
    rep(S, (1ll << (n - 1)))
    {
        int xoor = 0;
        vector<int> X(1, -1);
        rep(j, n - 1) if (S & (1ll << j)) X.pb(j);

        if (X.size() >= a && X.size() <= b)
        {
            X.push_back(n - 1);
            rep(j, X.size() - 1)
            {
                int suum = 0;
                for (int l = X[j] + 1; l <= X[j + 1]; l++)
                    suum += tab[l];
                xoor = xoor | suum;
            }
            wynik = min(wynik, xoor);
        }
    }
}

void pre()
{
    cin >> n >> a >> b;
    rep(i, n) cin >> tab[i];

    rep(i, n)
    {
        int val = tab[i];
        for (int k = i + 1; k <= n; k++)
        {
            E[i][k] = val;
            val += tab[k];
        }
    }
}

main()
{
    _upgrade;
    pre();
    int wynik = 0;
    Heura2(wynik);
    cout << wynik << endl;
}

Compilation message

sculpture.cpp: In function 'bool solveHeura(long long int)':
sculpture.cpp:44:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if ((E[i][k] | q) == q)
             ~~~~~~~~~~~~~~^~~~
sculpture.cpp: In function 'bool solveShortest(long long int)':
sculpture.cpp:58:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if ((E[i][k] | q) == q)
             ~~~~~~~~~~~~~~^~~~
sculpture.cpp: In function 'bool solveBitset(long long int)':
sculpture.cpp:71:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if ((E[i][k] | q) == q)
             ~~~~~~~~~~~~~~^~~~
sculpture.cpp: In function 'void Heura2(long long int&)':
sculpture.cpp:88:5: error: 'wzorShortest' was not declared in this scope
     wzorShortest(wynik);
     ^~~~~~~~~~~~
sculpture.cpp:88:5: note: suggested alternative: 'solveShortest'
     wzorShortest(wynik);
     ^~~~~~~~~~~~
     solveShortest
sculpture.cpp: In function 'void brut(long long int&)':
sculpture.cpp:132:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (X.size() >= a && X.size() <= b)
             ~~~~~~~~~^~~~
sculpture.cpp:132:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (X.size() >= a && X.size() <= b)
                              ~~~~~~~~~^~~~
sculpture.cpp:15:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i = 0; i < (n); ++i)
                                     ^
sculpture.cpp:135:13: note: in expansion of macro 'rep'
             rep(j, X.size() - 1)
             ^~~
sculpture.cpp: At global scope:
sculpture.cpp:163:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^