# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
468451 | 2021-08-28T11:34:29 Z | gavgav | Fountain (eJOI20_fountain) | C++17 | 108 ms | 5948 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; scanf("%d%d", &height, &queries); int diameters[height], next_grater[height + 1], capacities[height + 1]; capacities[height - 1] = 0; fill(next_grater, next_grater + height + 1, -1); stack <int> meowmeow; for (int i = 0; i < height; i++){ scanf("%d%hd", &diameters[i], &capacities[i]); while (!meowmeow.empty() && diameters[i] > diameters[meowmeow.top()]){ next_grater[meowmeow.top()] = i; meowmeow.pop(); } meowmeow.push(i); } while (!meowmeow.empty()){ next_grater[meowmeow.top()] = height; meowmeow.pop(); } /* * Creating of any possible water path. */ int indexes[height], last = 0; fill(indexes, indexes + height, -1); vector <int> lengths; vector <vector <int>> ways; for (int i = 0; i < height;){ ways.push_back(vector <int> {}); lengths.push_back(-1); for (int j = i; j + 1;){ ways[last].push_back(j); lengths[last]++; indexes[j] = last; if (j + 1 == next_grater[j]){ i++; } j = next_grater[j]; } i++; while (i < height && indexes[i] != - 1){ i++; } last++; } /* * Creating postfix sums array. */ for (int i = height; 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 | Runtime error | 1 ms | 332 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 95 ms | 5852 KB | Output is correct |
2 | Incorrect | 108 ms | 5948 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 332 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |