답안 #780046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780046 2023-07-12T06:00:04 Z 이동현(#10007) Sparklers (JOI17_sparklers) C++17
0 / 100
9 ms 16088 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[1004][1004], mx[1004][1004];

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;
    for(int i = 0; i < 1004; ++i) for(int j = 0; j < 1004; ++j) mn[i][j] = (int)1e18, mx[i][j] = -(int)1e18;
    while(low < high){
        mid = low + high >> 1;
        mn[k][k] = a[k] - t * mid;
        mx[k][k] = a[k] + t * mid;

        int i = k, j = k;
        while(i != 0 || j != n - 1){
            if(i != 0 && (j == n - 1 || a[i] - a[i - 1] < a[j + 1] - a[j])) --i;
            else ++j;
            mn[i][j] = (int)1e18;
            mx[i][j] = -(int)1e18;

            int l = mn[i + 1][j], r = mx[i + 1][j];
            r = min(r, a[i] + (j - i) * t * mid);
            l = max(l, a[i] - (j - i) * t * mid);
            if(l <= r){
                mx[i][j] = max(mx[i][j], r + t * mid);
                mn[i][j] = min(mn[i][j], l - t * mid);
            }

            l = mn[i][j - 1], r = mx[i][j - 1];
            r = min(r, a[j] + (j - i) * t * mid);
            l = max(l, a[j] - (j - i) * t * mid);
            if(l <= r){
                mx[i][j] = max(mx[i][j], r + t * mid);
                mn[i][j] = min(mn[i][j], l - t * mid);
            }
        }

        if(mn[0][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:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         mid = low + high >> 1;
      |               ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 16084 KB Output is correct
2 Correct 7 ms 15984 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 9 ms 16088 KB Output is correct
6 Correct 7 ms 16084 KB Output is correct
7 Incorrect 6 ms 15984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 16084 KB Output is correct
2 Correct 7 ms 15984 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 9 ms 16088 KB Output is correct
6 Correct 7 ms 16084 KB Output is correct
7 Incorrect 6 ms 15984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 16084 KB Output is correct
2 Correct 7 ms 15984 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 9 ms 16088 KB Output is correct
6 Correct 7 ms 16084 KB Output is correct
7 Incorrect 6 ms 15984 KB Output isn't correct
8 Halted 0 ms 0 KB -