답안 #999286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999286 2024-06-15T09:07:46 Z AdamGS Sparklers (JOI17_sparklers) C++17
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e9+7;
const int LIM=1e5+7;
ll T[LIM], n, k, t;
vector<ll>A, B;
vector<pair<ll,ll>>calc(vector<pair<ll,ll>>T) {
  ll m=T.size()-1;
  vector<pair<ll,ll>>P;
  for(int i=(int)T.size()-1; i>=0; --i) {
    pair<ll,ll>x={max(0ll, T[i].st), T[i].nd-T[i].st};
    while(P.size()>0 && x.nd<0) {
      pair<ll,ll>y={max(x.st, P.back().st-x.nd), x.nd+P.back().nd};
      P.pop_back();
      x=y;
    }
    P.pb(x);
  }
  reverse(all(P));
  return P;
}
bool check(ll x) {
  vector<pair<ll,ll>>X, Y;
  for(auto i : A) X.pb({i, 2*x*t});
  for(auto i : B) Y.pb({i, 2*x*t});
  vector<pair<ll,ll>>P=calc(X), Q=calc(Y);
  ll l1=0, l2=0, akt=2*x*t;
  while(l1<P.size() && l2<Q.size()) {
    if(P[l1].st>akt && Q[l2].st>akt) return false;
    if(P[l1].st<=akt && P[l1].nd>=0) {
      akt+=P[l1].nd;
      ++l1;
    } else if(Q[l2].st<=akt && Q[l2].nd>=0) {
      akt+=Q[l2].nd;
      ++l2;
    } else break;
  }
  while(l1<P.size()) {
    if(P[l1].st>akt) return false;
    akt+=P[l1].nd;
    ++l1;
  }
  while(l2<Q.size()) {
    if(Q[l2].st>akt) return false;
    akt+=Q[l2].nd;
    ++l2;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> n >> k >> t;
  rep(i, n) cin >> T[i];
  rep(i, k-1) A.pb(T[i+1]-T[i]);
  for(int i=n-1; i>=k; --i) B.pb(T[i]-T[i-1]);
  reverse(all(A));
  reverse(all(B));
  ll po=0, ko=INF;
  while(po<ko) {
    ll sr=(po+ko)/2;
    if(check(sr)) ko=sr; else po=sr+1;
  }
  cout << po << '\n';
}

Compilation message

sparklers.cpp: In function 'std::vector<std::pair<long long int, long long int> > calc(std::vector<std::pair<long long int, long long int> >)':
sparklers.cpp:15:6: warning: unused variable 'm' [-Wunused-variable]
   15 |   ll m=T.size()-1;
      |      ^
sparklers.cpp: In function 'bool check(ll)':
sparklers.cpp:35:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   while(l1<P.size() && l2<Q.size()) {
      |         ~~^~~~~~~~~
sparklers.cpp:35:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   while(l1<P.size() && l2<Q.size()) {
      |                        ~~^~~~~~~~~
sparklers.cpp:45:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   while(l1<P.size()) {
      |         ~~^~~~~~~~~
sparklers.cpp:50:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   while(l2<Q.size()) {
      |         ~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -