제출 #1335482

#제출 시각아이디문제언어결과실행 시간메모리
1335482nguyengiabach1201Bitwise (BOI06_bitwise)C++20
0 / 100
1 ms368 KiB
// https://oj.uz/problem/view/BOI06_bitwise

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define el '\n'
#define FNAME "bitwise"
#define ll long long
#define int long long
#define ld long double

const int MOD = 1e9 + 7;
const ll INF = 1e18 + 7;
const double EPS = 1e-9;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    if (fopen(FNAME ".in", "r"))
    {
        freopen(FNAME ".in", "r", stdin);
        freopen(FNAME ".out", "w", stdout);
    }

    return;
}

const int N = 1e2 + 5;
int n, p, k[N], a[N], b[N], mx[N], mn[N];
pair<int, int> rg[N];

void solve()
{
    cin >> n >> p;

    for (int i = 1; i <= p; ++i)
        cin >> k[i];

    for (int i = 1; i <= n; ++i)
        cin >> a[i] >> b[i];

    for (int i = 1; i <= p; ++i)
        rg[i] = {rg[i - 1].second + 1, rg[i - 1].second + k[i]};

    int ans = 0;

    for (int i = 32; i >= 0; --i)
    {
        bool ok = true;
        vector<pair<int, int>> chosen(p + 5);

        for (int j = 1; j <= p; ++j)
        {
            chosen[j] = {INF, -1};

            for (int k = rg[j].first; k <= rg[j].second; ++k)
            {
                int target = (a[k] | (1 << i)) & (~((1 << i) - 1));

                if (target <= b[k] && target < chosen[j].first)
                    chosen[j] = {target, k};
            }

            if (chosen[j].second == -1)
            {
                ok = false;
                break;
            }
        }

        for (int j = 1; j <= p; ++j)
            a[chosen[j].second] = chosen[j].first;

        if (ok)
            ans |= (1 << i);
    }

    cout << ans << el;
    return;
}

signed main()
{
    setup();

    int t = 1;
    bool multiTest = false;

    if (multiTest)
        cin >> t;

    while (t--)
        solve();

    return 0;
}

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

bitwise.cpp: In function 'void setup()':
bitwise.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(FNAME ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitwise.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(FNAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...