답안 #673783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673783 2022-12-22T03:12:00 Z abysmal Sprinkler (JOI22_sprinkler) C++14
3 / 100
4000 ms 24904 KB
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>

using namespace std;

const int64_t INF = (int64_t) 1e18 + 777;
const int64_t mINF = 2500 + 5;
const int64_t MOD = 1e9 + 9;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};

struct Solution
{
    int n;
    int64_t l;
    vector<int> h;
    vector<vector<int> > adj;
    Solution() {}

    void solve()
    {
        cin >> n >> l;

        adj.resize(n);
        for(int i = 0; i < n - 1; i++)
        {
            int u;
            int v;
            cin >> u >> v;
            u--; v--;

            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        h.resize(n);
        for(int i = 0; i < n; i++)
        {
            cin >> h[i];
        }

        int q;
        cin >> q;
        for(int i = 0; i < q; i++)
        {
            int t;
            cin >> t;

            if(t == 1)
            {
                int u;
                int d;
                int64_t w;
                cin >> u >> d >> w;
                u--;

                DFS(u, d, w);
            }
            else
            {
                int u;
                cin >> u;
                u--;

                cout << h[u] << "\n";
            }
        }
    }

    void DFS(int u, int d, int w, int p = -1)
    {
        int64_t tmp = (1LL * h[u] * w) % l;
        h[u] = tmp;
        if(d == 0) return;

        for(int i = 0; i < (int) adj[u].size(); i++)
        {
            int v = adj[u][i];
            if(v == p) continue;

            DFS(v, d - 1, w, u);
        }
    }

    int modsub(int t1, int t2)
    {
        int res = t1 - t2;
        if(res < 0) res += MOD;

        return res;
    }

    int modadd(int t1, int t2)
    {
        int res = t1 + t2;
        if(res >= MOD) res -= MOD;

        return res;
    }

    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return (res % MOD);
    }

    bool BIT(int& mask, int& j)
    {
        return (mask & MASK(j));
    }

    int MASK(int j)
    {
        return (1 << j);
    }
};

void __startup()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}

int main()
{
    __startup();
    int t = 1;
//    cin >> t;

    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 4 ms 412 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 7 ms 380 KB Output is correct
8 Correct 6 ms 412 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 226 ms 23924 KB Output is correct
3 Correct 301 ms 24396 KB Output is correct
4 Correct 229 ms 23920 KB Output is correct
5 Correct 252 ms 24136 KB Output is correct
6 Correct 221 ms 23756 KB Output is correct
7 Correct 227 ms 24396 KB Output is correct
8 Correct 221 ms 24904 KB Output is correct
9 Correct 202 ms 23492 KB Output is correct
10 Correct 287 ms 24144 KB Output is correct
11 Correct 197 ms 23812 KB Output is correct
12 Correct 284 ms 24424 KB Output is correct
13 Execution timed out 4022 ms 17352 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 226 ms 23924 KB Output is correct
3 Correct 301 ms 24396 KB Output is correct
4 Correct 229 ms 23920 KB Output is correct
5 Correct 252 ms 24136 KB Output is correct
6 Correct 221 ms 23756 KB Output is correct
7 Correct 227 ms 24396 KB Output is correct
8 Correct 221 ms 24904 KB Output is correct
9 Correct 202 ms 23492 KB Output is correct
10 Correct 287 ms 24144 KB Output is correct
11 Correct 197 ms 23812 KB Output is correct
12 Correct 284 ms 24424 KB Output is correct
13 Execution timed out 4022 ms 17352 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 637 ms 20940 KB Output is correct
3 Correct 3975 ms 21592 KB Output is correct
4 Correct 1186 ms 21068 KB Output is correct
5 Execution timed out 4057 ms 19520 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 709 ms 23460 KB Output is correct
3 Correct 3876 ms 21984 KB Output is correct
4 Correct 1342 ms 22636 KB Output is correct
5 Execution timed out 4051 ms 21152 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 4 ms 412 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 7 ms 380 KB Output is correct
8 Correct 6 ms 412 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 226 ms 23924 KB Output is correct
31 Correct 301 ms 24396 KB Output is correct
32 Correct 229 ms 23920 KB Output is correct
33 Correct 252 ms 24136 KB Output is correct
34 Correct 221 ms 23756 KB Output is correct
35 Correct 227 ms 24396 KB Output is correct
36 Correct 221 ms 24904 KB Output is correct
37 Correct 202 ms 23492 KB Output is correct
38 Correct 287 ms 24144 KB Output is correct
39 Correct 197 ms 23812 KB Output is correct
40 Correct 284 ms 24424 KB Output is correct
41 Execution timed out 4022 ms 17352 KB Time limit exceeded
42 Halted 0 ms 0 KB -