답안 #780029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780029 2023-07-12T05:49:56 Z 이동현(#10007) Sparklers (JOI17_sparklers) C++17
0 / 100
2000 ms 16636 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

const int NS = (int)1e5 + 4;
int n, k, t;
int a[NS];
int mn[(1 << 20) + 4], mx[(1 << 20) + 4];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k >> t;
    --k;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int low = 0, high = (int)1e9, mid;
    while(low < high){
        mid = low + high >> 1;
        mn[1 << k] = a[k] - t * mid;
        mx[1 << k] = a[k] + t * mid;

        for(int i = 0; i < (1 << n); ++i){
            if(i == (1 << k)) continue;
            mn[i] = (int)1e18, mx[i] = -(int)1e18;
            int cnt = __builtin_popcount(i) - 1;
            for(int j = 0; j < n; ++j){
                if(!(i & (1 << j))) continue;

                int l = mn[i ^ (1 << j)], r = mx[i ^ (1 << j)];
                r = min(r, a[j] + cnt * t * mid);
                l = max(l, a[j] - cnt * t * mid);
                // if(mid == 8) cout << i << ' ' << j << ' ' << l << ' ' << r << endl;
                if(l <= r){
                    mx[i] = max(mx[i], r + t * mid);
                    mn[i] = min(mn[i], l - t * mid);
                }
            }
        }

        if(mn[(1 << n) - 1] != (int)1e18){
            high = mid;
        }
        else{
            low = mid + 1;
        }
    }

    cout << low << '\n';


    
    return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:24:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         mid = low + high >> 1;
      |               ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2086 ms 16636 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2086 ms 16636 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2086 ms 16636 KB Time limit exceeded
5 Halted 0 ms 0 KB -