# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
468636 | 2021-08-29T07:03:26 Z | gavgav | Fountain (eJOI20_fountain) | C++17 | 106 ms | 3072 KB |
#include <iostream> #include <vector> #include <stack> using namespace std; int main(){ /* * 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 height, queries, ways_number = 0; scanf("%d%d", &height, &queries); int diameters[height], next_grater[height + 1], capacities[height + 1]; capacities[height] = 0; next_grater[height] = -1; vector <int> starts; stack <int> meowmeow; for (int i = 0; i < height; i++){ scanf("%d%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{ ways_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 indexes[height]; vector <int> lengths (ways_number, -1); vector <vector <int>> ways (ways_number); for (int i = 0; i < ways_number; i++){ for (int j = starts[i]; j != -1; j = next_grater[j]) { ways[i].push_back(j); lengths[i]++; indexes[j] = i; } } /* * Creating postfix sums array. */ for (int i = height - 1; i > -1; i--){ if (next_grater[i] != -1){ 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 = 0, right = lengths[indexes[level]]; while (left - right < 1){ middle = (left + right) / 2; if (volume > capacities[level] - capacities[ways[indexes[level]][middle]]){ answer = ways[indexes[level]][middle] + 1; left = middle + 1; } else { right = middle - 1; } } printf("%d\n", answer % (height + 1)); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 332 KB | Output is correct |
5 | Incorrect | 2 ms | 332 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 98 ms | 3072 KB | Output is correct |
2 | Incorrect | 106 ms | 3068 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 332 KB | Output is correct |
5 | Incorrect | 2 ms | 332 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |