답안 #799966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799966 2023-08-01T08:56:17 Z Khizri 사탕 분배 (IOI21_candies) C++17
0 / 100
64 ms 18012 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2005;
int n,q;
vector<ll>pre[mxn];
vector<int> distribute_candies(vector<int> c, vector<int> x, vector<int> y, vector<int> vq) {
    n = c.size();
    q=x.size();
    for(int i=0;i<q;i++){
        int l=x[i],r=y[i],val=vq[i];
        for(int j=l;j<=r;j++){
            pre[j].pb(vq[i]);
        }
    }
    vector<int>ans;
    for(int id=0;id<n;id++){
        int lim=c[id];
        for(int i=1;i<pre[id].size();i++){
            pre[id][i]+=pre[id][i-1];
        }
        ll mx=-INF,mn=INF,idx=-1,idx2=-1;
        for(int i=0;i<pre[id].size();i++){
            if(pre[id][i]>=mx){
                mx=pre[id][i];
                idx=i;
            }
            if(pre[id][i]<=mn){
                mn=pre[id][i];
                idx2=i;
            }
        }
        if(idx2>idx&&mx-mn>lim){
            ans.pb(min(1ll*lim,pre[id].back()-pre[id][idx2]));
        }
        else{
            ans.pb(max(0ll,pre[id].back()-(pre[id][idx]-lim)));
        }
    }
    return ans;
}
/*
g++ candies.cpp grader.cpp ; .\a.exe
3 
10 15 13
2
0 2 20
0 1 -11
*/

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:22:27: warning: unused variable 'val' [-Wunused-variable]
   22 |         int l=x[i],r=y[i],val=vq[i];
      |                           ^~~
candies.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i=1;i<pre[id].size();i++){
      |                     ~^~~~~~~~~~~~~~~
candies.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i=0;i<pre[id].size();i++){
      |                     ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 64 ms 18012 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -