답안 #548912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548912 2022-04-14T16:54:51 Z cig32 사탕 분배 (IOI21_candies) C++17
3 / 100
5000 ms 2072604 KB
#include "candies.h"
#include "bits/stdc++.h"
using namespace std;

#include <cassert>
#include <cstdio>
#include <vector>


std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
  int n = c.size();
  std::vector<int> s(n);
  int q = l.size();
  vector<long long> list[n];
  for(int i=0; i<n; i++) {
    list[i].push_back(1e15);
    list[i].push_back(-1e15);
  }
  for(int i=0; i<q; i++) {
    for(int j=l[i]; j<=r[i]; j++) list[j].push_back(v[i]);
  }
  for(int i=0; i<n; i++) {
    int k = list[i].size();
    long long ps[k];
    ps[0] = list[i][0];
    for(int j=1; j<k; j++) ps[j] = ps[j-1] + list[i][j];
    long long smax[k], smin[k];
    smax[k-1] = ps[k-1];
    smin[k-1] = ps[k-1];
    for(int j=k-2; j>=0; j--) {
      smax[j] = max(smax[j+1], ps[j]);
      smin[j] = min(smin[j+1], ps[j]);
    }
    int idx = -1;
    long long optl, optr;
    long long lb = 0, rb = c[i];
    for(int j=0; j<k; j++) {
      bool crash = 0;
      if(ps[j] >= rb) {
        long long q = ps[j] - rb;
        rb += q;
        lb += q;
        crash = 1;
      }
      if(ps[j] <= lb) {
        long long q = lb - ps[j];
        rb -= q;
        lb -= q;
        crash = 1;
      }
      if(crash && smax[j] == ps[j] && smax[j] - smin[j] <= c[i]) {
        idx = j;
        optl = lb, optr = rb;
      }
      if(crash && smin[j] == ps[j] && smax[j] - smin[j] <= c[i]) {
        idx = j;
        optl = lb, optr = rb;
      }
    }
    if(idx == -1) {
      optl = 0, optr = c[i];
    }
    s[i] = ps[k-1] - optl;
  }
  return s;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:36:21: warning: variable 'optr' set but not used [-Wunused-but-set-variable]
   36 |     long long optl, optr;
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 3 ms 1080 KB Output is correct
5 Correct 32 ms 13924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5192 ms 1749236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 3359 ms 1109456 KB Output is correct
3 Correct 4303 ms 1300184 KB Output is correct
4 Execution timed out 5161 ms 1981496 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Execution timed out 5204 ms 2072604 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 3 ms 1080 KB Output is correct
5 Correct 32 ms 13924 KB Output is correct
6 Execution timed out 5192 ms 1749236 KB Time limit exceeded
7 Halted 0 ms 0 KB -