답안 #1003154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003154 2024-06-20T06:56:40 Z ayankarimova 쌀 창고 (IOI11_ricehub) C++14
0 / 100
519 ms 15192 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const ll sz=5005;
ll a[sz], b[sz], s1[sz], s2[sz], s[sz];
map<ll, ll>mp;
int besthub(int r, int l, int x[], long long k)
{
    for(int i=0; i<r; i++){
        mp[x[i]]++;
        s[x[i]]++;
    }
    for(int i=1; i<=l+1; i++) s[i]+=s[i-1];
    ll sum=0;
    for(ll i=1; i<=l; i++){
        a[i]=a[i-1]+s1[i-1];
        s1[i]=mp[i]+s1[i-1];
    }
    //cout<<endl;
    sum=0;
    for(ll i=l; i>=1; i--){
        b[i]=b[i+1]+s2[i+1];
        s2[i]=mp[i]+s2[i+1];
        //cout<<b[i]<<' ';
    }
    ll ans=0;
    for(int i=1; i<=l; i++){
        for(int j=0; j<r; j++){
            for(int t=0; t<r; t++){
                ll num1=a[i]-a[x[j]]-s1[x[j]-1];
                ll num2=b[i]-b[x[t]]-s2[x[t]+1];
                num1=abs(num1); num2=abs(num2);/*
                if(i==11){
                    cout<<j<<' '<<t<<' '<<num1<<' '<<num2<<' '<<s[x[t]]-s[x[j]-1]<<endl;
                }
*/
                if(num1+num2<=k) ans=max(ans, s[x[t]]-s[x[j]-1]);
            }
        }
    }
    return ans;
}
/*
{} []
5 20 6

1 2 10 12 14 3
*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:16:8: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   16 |     ll sum=0;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 360 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 519 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 15192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -