Submission #469199

# Submission time Handle Problem Language Result Execution time Memory
469199 2021-08-31T06:10:00 Z gavgav Fountain (eJOI20_fountain) C++17
60 / 100
959 ms 524292 KB
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    /*
     * Get dates about fountain.
     * Creating array in witch every number denotes index of the nearest number witch greater than this reservoir.
     * Indexes in this array means number of reservoir.
     */
    int streams_number = 0, queries, height;
    scanf("%d%d", &height, &queries);
    long long diameters[height];
    int next_grater[height], capacities[height + 1];
    capacities[height] = 0;
    vector <int> starts;
    stack <int> meowmeow;
    for (int i = 0; i < height; i++){
        scanf("%lld%d", &diameters[i], &capacities[i]);
        if (!meowmeow.empty() && diameters[i] > diameters[meowmeow.top()]){
            do{
                next_grater[meowmeow.top()] = i;
                meowmeow.pop();
            }while (!meowmeow.empty() && diameters[i] > diameters[meowmeow.top()]);
        }
        else{
            streams_number++;
            starts.push_back(i);
        }
        meowmeow.push(i);
    }
    while (!meowmeow.empty()){
        next_grater[meowmeow.top()] = height;
        meowmeow.pop();
    }
    /*
     * Creating of any possible water path.
     */
    int affiliation[height], indexes[height];
    int lengths[streams_number] {};
    vector <int> streams[streams_number];
    for (int i = 0; i < streams_number; i++){
        for (int j = starts[i], k = 0; j != height; j = next_grater[j], k++) {
            streams[i].push_back(j);
            lengths[i]++;
            indexes[j] = k;
            affiliation[j] = i;
        }
        streams[i].push_back(height);
    }
    /*
     * Creating postfix sums array.
     */
    for (int i = height - 1; i > -1; i--){
        capacities[i] += capacities[next_grater[i]];
    }
    /*
     * Get queries and by binary search print answer.
     */

    int volume, level, left, right, middle, answer;
    while (queries--){
        scanf("%d%d", &level, &volume);
        level--;
        left = indexes[level] + 1, right = lengths[affiliation[level]], answer = streams[affiliation[level]][indexes[level]] + 1;
        while (left - right < 1){
            middle = (left + right) / 2;
            if (volume > capacities[level] - capacities[streams[affiliation[level]][middle]]){
                answer = streams[affiliation[level]][middle] + 1;
                left = middle + 1;
            } else {
                right = middle - 1;
            }
        }
        printf("%d\n", answer % (height + 1));
    }
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d%d", &height, &queries);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lld%d", &diameters[i], &capacities[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         scanf("%d%d", &level, &volume);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 304 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 4720 KB Output is correct
2 Correct 112 ms 4568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 304 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 102 ms 4720 KB Output is correct
9 Correct 112 ms 4568 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 959 ms 483964 KB Output is correct
12 Correct 156 ms 4632 KB Output is correct
13 Runtime error 922 ms 524292 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -