답안 #863990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863990 2023-10-21T16:17:03 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 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 344 KB Output is correct
6 Correct 4 ms 464 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 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 344 KB Output is correct
6 Correct 4 ms 464 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 -