답안 #395442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395442 2021-04-28T11:09:08 Z PanTkd Bitwise (BOI06_bitwise) C++14
100 / 100
2 ms 320 KB
//
//  main.cpp
//
//  Created by Panagiotis Chadjicostas on
//  Copyright © Panagiotis Hadjicostas. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define fo(i,a,b) for(int i = a; i<=b; i++)
#define f(i,b) for(int i=0;i<b;i++)
#define F first
#define S second
#define sz size
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
  
///////////////////////////////////////////////////////////////////////

struct po{
    ll s,e;
};

ll sc[1000];
ll l[1000];
void solve(){
    ll n,p;cin>>n>>p;
    

    for(ll i=1;i<=p;i++){
        cin>>l[i];l[i]+=l[i-1];
    }
    po v[n+1];
    for(ll i=1;i<=n;i++){
        cin>>v[i].s>>v[i].e;
    }

    ll sol=0;
    for(ll i=30;i>=0;i--){
        bool ok=1;
        ll put=(1<<i);

        for(ll b=1;b<=p&&ok;b++){
            
            sc[b]=0;
            ok=false;
            for(ll j=l[b-1]+1;j<=l[b];j++){
                if(v[j].e>=put&&(v[j].s>=put||!sc[b])){
                    ok=true;
                    sc[b]=j;
                }
            }
        }
        if(ok){
            sol += put;
            for (ll b = 1; b <= p; b++)
                v[sc[b]].s = max(v[sc[b]].s, put);
        }
        for(ll j=1;j<=n;j++){
            if(v[j].s>=put){
                v[j].s-=put;
                v[j].e-=put;
            }
            else if (v[j].e>=put){
                v[j].e=put-1;
            }
        }
    }
    cout<<sol<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;//cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 208 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct