답안 #674201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674201 2022-12-23T13:15:45 Z abysmal Intercastellar (JOI22_ho_t1) C++14
100 / 100
83 ms 9940 KB
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>

using namespace std;

const int64_t INF = (int64_t) 1e18 + 777;
const int64_t mINF = (int64_t) 1e15;
const int64_t MOD = 1e9 + 7;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up

bool mod_cmp(int a, int b)
{
    return a > b;
}

struct Solution
{
    Solution() {}

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

        vector<int> a(n);
        vector<int64_t> c(n, 1);

        for(int i = 0; i < n; i++)
        {
            cin >> a[i];

            while(a[i] % 2 == 0)
            {
                a[i] /= 2;

                c[i] = min(c[i] * 2, mINF);
            }
        }

        vector<int64_t> prefix(n, 0);
        for(int i = 0; i < n; i++)
        {
            if(i != 0) prefix[i] = prefix[i - 1];
            prefix[i] = min(prefix[i] + c[i], mINF);
        }

        int q;
        cin >> q;
        for(int i = 0; i < q; i++)
        {
            int64_t x;
            cin >> x;

            int l = 0;
            int r = n - 1;
            int id = -1;

            while(l <= r)
            {
                int mid = l + (r - l) / 2;

                if(prefix[mid] >= x)
                {
                    id = mid;
                    r = mid - 1;
                }
                else l = mid + 1;
            }

            if(id == -1) cout << id << "\n";
            else cout << a[id] << "\n";
        }
    }

    int modsub(int t1, int t2)
    {
        int res = t1 - t2;
        if(res < 0) res += MOD;

        return res;
    }

    int modadd(int t1, int t2)
    {
        int res = t1 + t2;
        if(res >= MOD) res -= MOD;

        return res;
    }

    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return (res % MOD);
    }

    bool BIT(int& mask, int& j)
    {
        return (mask & MASK(j));
    }

    int MASK(int j)
    {
        return (1 << j);
    }
};

void __startup()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}

int main()
{
    __startup();
    int t = 1;
//    cin >> t;

    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 21 ms 4752 KB Output is correct
4 Correct 34 ms 2524 KB Output is correct
5 Correct 55 ms 6232 KB Output is correct
6 Correct 28 ms 4708 KB Output is correct
7 Correct 51 ms 6252 KB Output is correct
8 Correct 50 ms 6424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 21 ms 4752 KB Output is correct
4 Correct 34 ms 2524 KB Output is correct
5 Correct 55 ms 6232 KB Output is correct
6 Correct 28 ms 4708 KB Output is correct
7 Correct 51 ms 6252 KB Output is correct
8 Correct 50 ms 6424 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 29 ms 3092 KB Output is correct
24 Correct 35 ms 5792 KB Output is correct
25 Correct 65 ms 9548 KB Output is correct
26 Correct 48 ms 6040 KB Output is correct
27 Correct 45 ms 6080 KB Output is correct
28 Correct 79 ms 9940 KB Output is correct
29 Correct 83 ms 9488 KB Output is correct
30 Correct 40 ms 3756 KB Output is correct
31 Correct 80 ms 9940 KB Output is correct