답안 #938605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938605 2024-03-05T11:03:50 Z vjudge1 Intercastellar (JOI22_ho_t1) C++17
100 / 100
68 ms 6996 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    vector<int> sums(n);
    for (int i = 0; i < n; i++)
    {
        int temp = v[i];
        int cnt = 0;
        while (temp%2==0)
        {
            temp/=2;
            cnt++;
        }
        sums[i] = cnt;
    }
    vector<int> pref_sum(n,0);
    pref_sum[0] = (1<<sums[0]);
    for (int i = 1; i < n; i++)
        pref_sum[i] = pref_sum[i-1]+(1<<sums[i]);
    int q;
    cin >> q;
    while(q--)
    {
        int x;
        cin >> x;
        int l = 0, r = n-1;
        while (r-l>1)
        {
            int mid = l+r>>1;
            if (pref_sum[mid] <= x)
                l = mid;
            else
                r = mid;
        }
        
        if (pref_sum[l] >= x)
         cout << v[l]/(1<<(sums[l])) << '\n';
        else
        cout << v[r]/(1<<(sums[r])) << '\n';
    
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |             int mid = l+r>>1;
      |                       ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 32 ms 1748 KB Output is correct
5 Correct 47 ms 5444 KB Output is correct
6 Correct 27 ms 4444 KB Output is correct
7 Correct 49 ms 5436 KB Output is correct
8 Correct 46 ms 5544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 32 ms 1748 KB Output is correct
5 Correct 47 ms 5444 KB Output is correct
6 Correct 27 ms 4444 KB Output is correct
7 Correct 49 ms 5436 KB Output is correct
8 Correct 46 ms 5544 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 26 ms 2408 KB Output is correct
24 Correct 30 ms 4444 KB Output is correct
25 Correct 59 ms 6996 KB Output is correct
26 Correct 38 ms 3924 KB Output is correct
27 Correct 34 ms 4260 KB Output is correct
28 Correct 68 ms 6100 KB Output is correct
29 Correct 63 ms 5608 KB Output is correct
30 Correct 36 ms 1596 KB Output is correct
31 Correct 66 ms 6052 KB Output is correct