답안 #485890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485890 2021-11-09T15:53:32 Z gavgav Fountain (eJOI20_fountain) C++17
100 / 100
107 ms 7368 KB
#include <stdio.h>
#define MAX_N 100000
#define MAX_M 200000
#define MAX_D 1000000000
#define MAX_S 100000000000000
struct reservoir {
    long long diameters, capacity;
};
struct query {
    int level, volume, rasp;
};
int stiva[MAX_N + 1], next[MAX_M + 1], liste[MAX_N + 1];
long long sumaNec[MAX_N + 1];
struct reservoir reservoirs[MAX_N + 1];
struct query q[MAX_M + 1];
int main() {
    int height, queries_number, top, st, dr, mij, i, j;
    long long sumaV;
    scanf( "%d%d", &height, &queries_number);
    reservoirs[0].diameters = MAX_D + 1;
    reservoirs[0].capacity = 0;
    for ( i = 1; i <= height; i++ )
        scanf( "%d%d", &reservoirs[i].diameters, &reservoirs[i].capacity);
    for ( i = 1; i <= queries_number; i++ ) {
        scanf( "%d%d", &q[i].level, &q[i].volume);
        next[i] = liste[q[i].level];
        liste[q[i].level] = i;
    }
    stiva[0] = 0;
    sumaNec[0] = -MAX_S - 1;
    top = 0;
    sumaV = 0;
    for ( i = height; i >= 1; i-- ) {
        while ( reservoirs[i].diameters >= reservoirs[stiva[top]].diameters ) {
            sumaV -= reservoirs[stiva[top]].capacity;
            top--;
        }
        top++;
        stiva[top] = i;
        sumaNec[top] = sumaV;
        sumaV += reservoirs[i].capacity;

        j = liste[i];
        while ( j != 0 ) {
            st = top + 1;
            dr = 0;
            while ( st - dr > 1 ) {
                mij = (st + dr) / 2;
                if ( sumaV - sumaNec[mij] >= q[j].volume)
                    dr = mij;
                else
                    st = mij;
            }
            q[j].rasp = stiva[dr];

            j = next[j];
        }
    }
    for ( i = 1; i <= queries_number; i++ )
        printf( "%d\n", q[i].rasp );
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:23:18: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   23 |         scanf( "%d%d", &reservoirs[i].diameters, &reservoirs[i].capacity);
      |                 ~^     ~~~~~~~~~~~~~~~~~~~~~~~~
      |                  |     |
      |                  int*  long long int*
      |                 %lld
fountain.cpp:23:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   23 |         scanf( "%d%d", &reservoirs[i].diameters, &reservoirs[i].capacity);
      |                   ~^                             ~~~~~~~~~~~~~~~~~~~~~~~
      |                    |                             |
      |                    int*                          long long int*
      |                   %lld
fountain.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf( "%d%d", &height, &queries_number);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf( "%d%d", &reservoirs[i].diameters, &reservoirs[i].capacity);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf( "%d%d", &q[i].level, &q[i].volume);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 5572 KB Output is correct
2 Correct 78 ms 5784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 72 ms 5572 KB Output is correct
9 Correct 78 ms 5784 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 47 ms 3436 KB Output is correct
12 Correct 107 ms 7368 KB Output is correct
13 Correct 98 ms 6724 KB Output is correct
14 Correct 77 ms 6432 KB Output is correct
15 Correct 71 ms 6464 KB Output is correct