답안 #800153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800153 2023-08-01T10:58:31 Z SlavaKemDev 급행열차 20/19 (ROI19_express) C++17
0 / 100
328 ms 48884 KB
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <random>
#include <cassert>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pair<ll, ll>>;
using vii = vector<int>;

#define fill(a) for (ll i = 0; i < (a).size(); i++) cin >> (a)[i]
#define mp make_pair
#define mt make_tuple
#define bs(a, b) binary_search((a).begin(), (a).end(), (b))

ld EPS = 1e-9;
ld phi = (1 + sqrt(5)) / 2;

ll MOD = 1e9 + 7;
ll INF = 1e18;
ll P = 239;
ll B = 550;

struct Edge {
    ll to, w;
};

vector<vector<Edge>> g;
vector<bitset<10001>> c;
vector<ll> order;
vector<bool> used;

void dfs(ll v) {
    used[v] = true;
    for (Edge edge : g[v])
        if (!used[edge.to])
            dfs(edge.to);
    order.push_back(v);
}

ll p;

vector<ll> merge(vector<ll> a, vector<ll> b, ll w) {
    for (ll &v : b) v += w;
    ll n = (ll)a.size(), m = (ll)b.size();
    ll i = 0, j = 0;
    vector<ll> p1(n + m);
    while (i < n || j < m) {
        if (j == m || (i < n && a[i] < b[j]))
            p1[i + j] = a[i], i++;
        else
            p1[i + j] = b[j], j++;
    }

    if (n + m < 2) return p1;
    vector<ll> p2;

    p2.push_back(p1[0]);
    p2.push_back(p1[1]);

    for (i = 2; i < n + m; i++)
        if (p1[i] * (p - 1) > p2[p2.size() - 2] * p) p2.push_back(p1[i]);

    return p2;
}

int main() {
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);

    clock_t timer = clock();
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(64);
    cout << fixed;
#endif

    ll t;
    cin >> t;

    while (t--) {
        ll n, m, q;
        cin >> n >> m >> q >> p;

        g.assign(n, {});
        used.assign(n, false);
        order.clear();

        for (ll i = 0; i < m; i++) {
            ll u, v, w;
            cin >> u >> v >> w;
            u--; v--;
            g[u].push_back({v, w});
        }

        dfs(0);
        reverse(order.begin(), order.end());

        vector<vector<ll>> cn(n);
        cn[0].push_back(0);


        for (ll v : order) {
            for (Edge edge : g[v])
                cn[edge.to] = merge(cn[edge.to], cn[v], edge.w);
        }

        while (q--) {
            ll f, r;
            cin >> f >> r;
            f--;

            bool ok = false;
            for (ll i : cn[f]) ok |= r <= i && i <= r * p / (p - 1);

            cout << ok;
        }

        cout  << "\n";
    }

#ifdef LOCAL
    cout << endl << "Execution time: " << (ld)(clock() - timer) / CLOCKS_PER_SEC;
#endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Incorrect 4 ms 468 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 328 ms 48884 KB Output is correct
3 Correct 190 ms 20800 KB Output is correct
4 Incorrect 175 ms 16060 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 328 ms 48884 KB Output is correct
3 Correct 190 ms 20800 KB Output is correct
4 Incorrect 175 ms 16060 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 2004 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 2004 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -