Submission #863991

# Submission time Handle Problem Language Result Execution time Memory
863991 2023-10-21T16:17:46 Z FIFI_cpp Fountain (eJOI20_fountain) C++17
30 / 100
5 ms 604 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <iomanip>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
struct DATA
{
    int d;
    int c;
    int next;
};
vector<DATA> reservoir;
int n,q;

int recur(int node,int quantity)
{
    if (quantity <= reservoir[node].c)
        return node + 1;
    if (reservoir[node].next == -1)
        return 0;
    return recur(reservoir[node].next,quantity - reservoir[node].c);
}

int main() {
    fast
    cin >> n >> q;
    stack<pair<int,int>> sz;
    sz.push({1000000,0});
    for (int i = 0;i < n;i++)
    {
        DATA inter;
        int d,c;
        cin >> d >> c;
        inter.d = d;
        inter.c = c;
        inter.next = -1;
        reservoir.push_back(inter);
        while (inter.d > sz.top().first)
        {
            reservoir[sz.top().second].next = i;
            sz.pop();
        }
        sz.push({inter.d,i});
    }
    for (int i = 0;i < q;i++)
    {
        int r,v;
        cin >> r >> v;
        cout << recur(r - 1,v) << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Runtime error 1 ms 604 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -