답안 #549046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549046 2022-04-15T03:05:34 Z cig32 사탕 분배 (IOI21_candies) C++17
3 / 100
5000 ms 2097152 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 lb = 0, rb = k - 1;
    while(lb < rb) {
      int mid = (lb + rb + 1) >> 1;
      if(smax[mid] - smin[mid] >= c[i]) lb = mid;
      else rb = mid - 1;
    } 
    if(smax[lb] - smin[lb] >= c[i]) {
      if(smax[lb] == ps[lb]) {
        s[i] = ps[k-1] - smin[lb];
      }
      else {
        s[i] = ps[k-1] - (smax[lb] - c[i]);
      }
    }
    else {
      s[i] = ps[k-1];
    }
  }
  return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 21 ms 13960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5197 ms 1578864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 3035 ms 1108540 KB Output is correct
3 Correct 4103 ms 1299872 KB Output is correct
4 Execution timed out 5155 ms 1999756 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 428 KB Output is correct
3 Execution timed out 5013 ms 2097152 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 21 ms 13960 KB Output is correct
6 Execution timed out 5197 ms 1578864 KB Time limit exceeded
7 Halted 0 ms 0 KB -