제출 #309473

#제출 시각아이디문제언어결과실행 시간메모리
309473Ruxandra985비스킷 담기 (IOI20_biscuits)C++14
100 / 100
84 ms1016 KiB
#include <bits/stdc++.h>
#include "biscuits.h"

using namespace std;

map <long long , long long> mp[61];
long long s[61];
long long x2;

long long rec (int bit , long long nr){
    long long sum = 0;
    if (bit < 0)
        return 1;

    nr = min(nr , s[bit] / x2);
    nr = min(nr , (1LL << (bit + 1)));

    if (mp[bit].find(nr) != mp[bit].end()){ /// exista deja
        return mp[bit][nr];
    }

    if ((1LL << bit) <= nr){ /// nr tine de s[i], de asta, asta ins ca poate fi bitul 1

        sum += rec(bit - 1 , nr - (1LL << bit));
    }

    /// altfel pui bitul 0 aici

    sum += rec (bit - 1 , nr);

    mp[bit][nr] = sum;
    return sum;


}

long long count_tastiness(long long x, vector<long long> a) {
    int i;

    x2 = x;

    for (i = 0 ; i <= 60 ; i++){
        mp[i].clear();
        s[i] = 0;
    }
    s[60] = 0;

    for (i = 0 ; i <= 60 ; i++){
        if (i < a.size())
            s[i] += a[i] * (1LL << i);
        if (i)
            s[i] += s[i - 1];
    }

    /// s[i] / x e un fel de maxim posibil sa ai pana la i

	return rec(60 , min( s[60] / x , (1LL << 60) ) );
}

컴파일 시 표준 에러 (stderr) 메시지

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:49:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         if (i < a.size())
      |             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...