답안 #975056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975056 2024-05-04T11:02:40 Z LucaIlie 비스킷 담기 (IOI20_biscuits) C++17
9 / 100
1000 ms 710076 KB
#include "biscuits.h"
#include <bits/stdc++.h>

using namespace std;

const int k = 60;
long long x;
long long biscuits[k];
long long sum[k][k], mask[k][k];
int ind[k][k];
queue<pair<int, long long>> solutions;
vector<int> sol;

int p;
bool cmp( int p1, int p2 ) {
    //long long r1 = ((mask[p][p1] >> (p1 - p)) + sum[p][p1] - x) >> p2, r2 = ((mask[p][p2] >> (p2 - p)) + sum[p][p2] - x) >> p1;
    return ((__int128)mask[p][p1] << p) + (((__int128)sum[p][p1] - x) << p1) > ((__int128)mask[p][p2] << p) + (((__int128)sum[p][p2] - x) << p2);
}

long long count_tastiness( long long X, vector <long long> a ) {
    long long s;

    x = X;
    a.resize( k );

    s = 0;
    for ( int b = 0; b < k; b++ ) {
        a[b] += s;
        if ( a[b] > x ) {
            s = a[b] - x;
            a[b] = x + s % 2;
            s /= 2;
        } else
            s = 0;
        biscuits[b] = a[b];
    }

    for ( int i = 0; i < k; i++ ) {
        sum[i][i] = biscuits[i];
        for ( int j = i + 1; j < k; j++ ) {
            mask[i][j] = mask[i][j - 1] + (((long long)sum[i][j - 1] % 2) << (j - i - 1));
            sum[i][j] = sum[i][j - 1] / 2 + biscuits[j];
            //printf( "%d %d: %d %d\n", i, j, sum[i][j], mask[i][j] );
        }
    }
    for ( int b = 0; b < k; b++ ) {
        for ( int i = b; i < k; i++ )
            ind[b][i] = i;
        p = b;
        sort( ind[b] + b, ind[b] + k, cmp );
    }

    int ans = 0;
    solutions.push( { 0, 0 } );
    while ( !solutions.empty() ) {
        int b = solutions.front().first;
        long long s = solutions.front().second;
        solutions.pop();

        ans++;
        s >>= 1;
        for ( int j = b; j < k; j++ ) {
            int i = ind[b][j];
            long long cs = ((s + mask[b][i]) >> (i - b)) + sum[b][i];
            //  printf( "%d %d %d\n", b, i, cs );
            if ( cs >= x )
                solutions.push( { i + 1, cs - x } );
            else
                break;
        }
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 600 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 7 ms 604 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 4 ms 400 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Execution timed out 1101 ms 332540 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 710076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1100 ms 1192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 600 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 7 ms 604 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 4 ms 400 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Execution timed out 1101 ms 332540 KB Time limit exceeded
17 Halted 0 ms 0 KB -