# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
495645 | 2021-12-19T17:29:36 Z | Amer | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 3000 ms | 81256 KB |
#include <iostream> #include<map> #include<vector> #include<queue> #include<stack> using namespace std; class mem { public: int maxCombination = 0; int maxNumber = 0; int lastIndex = 0; }; struct CompareMem { bool operator()(mem const& a, mem const& b) { // return "true" if "p1" is ordered // before "p2", for example: return a.lastIndex < b.lastIndex; } }; const int maxN = 1000005; int arr[maxN]; map<int, priority_queue<mem, vector<mem>, CompareMem>> memorisation; int solve(int start, int finish, int mood) { bool possible = true; mem now; now.lastIndex = finish; now.maxNumber = arr[start - 1]; now.maxCombination = 0; for (int i = start; i < finish; i++) { stack<mem> temp; if (memorisation[i].size() != 0) { for (int j = 0; j < memorisation[i].size(); j++) { if (memorisation[i].top().lastIndex < finish) { if (memorisation[i].top().maxCombination > mood) { return false; } } else { break; } temp.push(memorisation[i].top()); memorisation[i].pop(); } while (!temp.empty()) { memorisation[i].push(temp.top()); temp.pop(); } } if (now.maxNumber > arr[i]) { if (arr[i] + now.maxNumber > mood) { possible = false; } if (arr[i] + now.maxNumber > now.maxCombination) { now.maxCombination = arr[i] + now.maxNumber; } } else { now.maxNumber = arr[i]; } } memorisation[start].push(now); return possible; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { int start, finish, mood; cin >> start >> finish >> mood; cout << solve(start, finish, mood)<<endl; } } /* 5 2 3 5 1 8 2 1 3 6 2 5 3 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 8 ms | 332 KB | Output is correct |
9 | Correct | 3 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 8 ms | 332 KB | Output is correct |
9 | Correct | 3 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 9 ms | 444 KB | Output is correct |
12 | Correct | 19 ms | 724 KB | Output is correct |
13 | Correct | 22 ms | 716 KB | Output is correct |
14 | Correct | 26 ms | 716 KB | Output is correct |
15 | Correct | 27 ms | 716 KB | Output is correct |
16 | Correct | 885 ms | 852 KB | Output is correct |
17 | Correct | 358 ms | 796 KB | Output is correct |
18 | Correct | 239 ms | 728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3081 ms | 81256 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3086 ms | 8552 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 8 ms | 332 KB | Output is correct |
9 | Correct | 3 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 9 ms | 444 KB | Output is correct |
12 | Correct | 19 ms | 724 KB | Output is correct |
13 | Correct | 22 ms | 716 KB | Output is correct |
14 | Correct | 26 ms | 716 KB | Output is correct |
15 | Correct | 27 ms | 716 KB | Output is correct |
16 | Correct | 885 ms | 852 KB | Output is correct |
17 | Correct | 358 ms | 796 KB | Output is correct |
18 | Correct | 239 ms | 728 KB | Output is correct |
19 | Execution timed out | 3093 ms | 16748 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 2 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 8 ms | 332 KB | Output is correct |
9 | Correct | 3 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 9 ms | 444 KB | Output is correct |
12 | Correct | 19 ms | 724 KB | Output is correct |
13 | Correct | 22 ms | 716 KB | Output is correct |
14 | Correct | 26 ms | 716 KB | Output is correct |
15 | Correct | 27 ms | 716 KB | Output is correct |
16 | Correct | 885 ms | 852 KB | Output is correct |
17 | Correct | 358 ms | 796 KB | Output is correct |
18 | Correct | 239 ms | 728 KB | Output is correct |
19 | Execution timed out | 3081 ms | 81256 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |