Submission #1056856

# Submission time Handle Problem Language Result Execution time Memory
1056856 2024-08-13T11:51:39 Z Alihan_8 Escape Route 2 (JOI24_escape2) C++17
54 / 100
3000 ms 72348 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

const int inf = 1e15;

int T;

struct func{
	// messy function

	vector <int> m, b;
    vector <vector<ar<int,2>>> a;
	vector <vector<int>> id, up, w;
	vector <ar<int,2>> rev;
    
    int n;

	void modify(auto a_){
		a = a_, n = a.size();
		m.resize(n); id.resize(n);
		
		int ct = 0;

		for ( int i = 0; i + 1 < n; i++ ){
			m[i] = a[i].size();
			id[i].resize(m[i]);

			for ( auto &u: id[i] ) u = ct++;
		}
		
		rev.resize(ct);
		b.resize(ct);

		for ( int i = 0; i + 1 < n; i++ ){
			for ( int j = 0; j < m[i]; j++ ){
				rev[id[i][j]] = a[i][j];
				b[id[i][j]] = i;
			}
		}
		
		up.resize(ct);
		w.resize(ct);
		
		for ( int i = 0; i < ct; i++ ){
			up[i].resize(20, -1);
			w[i].resize(20);
		}

		for ( int i = 0; i + 2 < n; i++ ){
			for ( int j = 0; j < m[i]; j++ ){
				auto [l, r] = a[i][j];

				ar <int,3> opt = {inf, -1, -1};

				for ( int k = 0; k < m[i + 1]; k++ ){
					auto [x, y] = a[i + 1][k];

					ar <int,3> nxt;

					if ( x >= r ){
						nxt = {0, y, k};
					} else{
						nxt = {1, y, k};
					}

					chmin(opt, nxt);
				}

				up[id[i][j]][0] = id[i + 1][opt[2]];
				w[id[i][j]][0] = opt[0];
			}
		}

		for ( int j = 1; j < 20; j++ ){
			for ( int i = 0; i < ct; i++ ){
				if ( up[i][j - 1] == -1 ){
					up[i][j] = up[i][j - 1];
					w[i][j] = w[i][j - 1];
				} else{
					up[i][j] = up[up[i][j - 1]][j - 1];
					w[i][j] = w[i][j - 1] + w[up[i][j - 1]][j - 1];
				}
			}
		}
	}

    int get(int u, int r){
        int cnt = 0;

        for ( int i = 19; i >= 0; i-- ){
            if ( up[u][i] == -1 ){
                continue;
            }

            if ( b[up[u][i]] < r ){
                cnt += w[u][i];

                u = up[u][i];
            }
        }

        cnt = cnt * T + rev[u][1];

        return cnt;
    }
    
    int qry(int l, int r){
		int opt = inf;

        for ( int j = 0; j < m[l]; j++ ){
            auto [x, y] = a[l][j];

            chmin(opt, get(id[l][j], r) - x);
        }
        
        return opt;
	}
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n >> T;

    vector <vector<ar<int,2>>> a(n);

    for ( int i = 0; i + 1 < n; i++ ){
        int m; cin >> m;

        a[i].resize(m);

        for ( auto &[l, r]: a[i] ){
            cin >> l >> r;
        }
    }

	func lf; lf.modify(a);

    int q; cin >> q;

    while ( q-- ){
        int l, r; cin >> l >> r;

        --l, --r;

		cout << lf.qry(l, r) << ln;
    }

    cout << '\n';
}

Compilation message

Main.cpp:45:14: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   45 |  void modify(auto a_){
      |              ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 34 ms 4544 KB Output is correct
3 Correct 59 ms 6228 KB Output is correct
4 Correct 86 ms 8084 KB Output is correct
5 Correct 70 ms 6740 KB Output is correct
6 Correct 89 ms 8180 KB Output is correct
7 Correct 89 ms 8276 KB Output is correct
8 Correct 68 ms 6136 KB Output is correct
9 Correct 86 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 34 ms 4544 KB Output is correct
3 Correct 59 ms 6228 KB Output is correct
4 Correct 86 ms 8084 KB Output is correct
5 Correct 70 ms 6740 KB Output is correct
6 Correct 89 ms 8180 KB Output is correct
7 Correct 89 ms 8276 KB Output is correct
8 Correct 68 ms 6136 KB Output is correct
9 Correct 86 ms 8272 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 128 ms 7004 KB Output is correct
12 Correct 130 ms 7044 KB Output is correct
13 Correct 120 ms 6996 KB Output is correct
14 Correct 119 ms 6996 KB Output is correct
15 Correct 95 ms 7252 KB Output is correct
16 Correct 57 ms 4432 KB Output is correct
17 Correct 87 ms 7732 KB Output is correct
18 Correct 94 ms 7508 KB Output is correct
19 Correct 96 ms 7836 KB Output is correct
20 Correct 102 ms 7448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 34 ms 4544 KB Output is correct
3 Correct 59 ms 6228 KB Output is correct
4 Correct 86 ms 8084 KB Output is correct
5 Correct 70 ms 6740 KB Output is correct
6 Correct 89 ms 8180 KB Output is correct
7 Correct 89 ms 8276 KB Output is correct
8 Correct 68 ms 6136 KB Output is correct
9 Correct 86 ms 8272 KB Output is correct
10 Correct 243 ms 56332 KB Output is correct
11 Correct 455 ms 72348 KB Output is correct
12 Correct 427 ms 72236 KB Output is correct
13 Correct 339 ms 70108 KB Output is correct
14 Correct 418 ms 72236 KB Output is correct
15 Correct 465 ms 72348 KB Output is correct
16 Correct 259 ms 56344 KB Output is correct
17 Correct 405 ms 72236 KB Output is correct
18 Correct 177 ms 60244 KB Output is correct
19 Correct 140 ms 60244 KB Output is correct
20 Correct 157 ms 60244 KB Output is correct
21 Correct 152 ms 60408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 34 ms 4544 KB Output is correct
3 Correct 59 ms 6228 KB Output is correct
4 Correct 86 ms 8084 KB Output is correct
5 Correct 70 ms 6740 KB Output is correct
6 Correct 89 ms 8180 KB Output is correct
7 Correct 89 ms 8276 KB Output is correct
8 Correct 68 ms 6136 KB Output is correct
9 Correct 86 ms 8272 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 128 ms 7004 KB Output is correct
12 Correct 130 ms 7044 KB Output is correct
13 Correct 120 ms 6996 KB Output is correct
14 Correct 119 ms 6996 KB Output is correct
15 Correct 95 ms 7252 KB Output is correct
16 Correct 57 ms 4432 KB Output is correct
17 Correct 87 ms 7732 KB Output is correct
18 Correct 94 ms 7508 KB Output is correct
19 Correct 96 ms 7836 KB Output is correct
20 Correct 102 ms 7448 KB Output is correct
21 Correct 243 ms 56332 KB Output is correct
22 Correct 455 ms 72348 KB Output is correct
23 Correct 427 ms 72236 KB Output is correct
24 Correct 339 ms 70108 KB Output is correct
25 Correct 418 ms 72236 KB Output is correct
26 Correct 465 ms 72348 KB Output is correct
27 Correct 259 ms 56344 KB Output is correct
28 Correct 405 ms 72236 KB Output is correct
29 Correct 177 ms 60244 KB Output is correct
30 Correct 140 ms 60244 KB Output is correct
31 Correct 157 ms 60244 KB Output is correct
32 Correct 152 ms 60408 KB Output is correct
33 Correct 630 ms 59260 KB Output is correct
34 Correct 579 ms 59008 KB Output is correct
35 Correct 492 ms 54404 KB Output is correct
36 Correct 476 ms 54396 KB Output is correct
37 Correct 332 ms 56212 KB Output is correct
38 Correct 243 ms 52368 KB Output is correct
39 Correct 355 ms 66928 KB Output is correct
40 Correct 284 ms 43588 KB Output is correct
41 Correct 245 ms 50492 KB Output is correct
42 Correct 394 ms 66720 KB Output is correct
43 Correct 294 ms 59472 KB Output is correct
44 Correct 367 ms 61484 KB Output is correct
45 Correct 165 ms 55416 KB Output is correct
46 Correct 161 ms 50832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2915 ms 46004 KB Output is correct
4 Correct 2952 ms 45840 KB Output is correct
5 Execution timed out 3065 ms 45940 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 34 ms 4544 KB Output is correct
3 Correct 59 ms 6228 KB Output is correct
4 Correct 86 ms 8084 KB Output is correct
5 Correct 70 ms 6740 KB Output is correct
6 Correct 89 ms 8180 KB Output is correct
7 Correct 89 ms 8276 KB Output is correct
8 Correct 68 ms 6136 KB Output is correct
9 Correct 86 ms 8272 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 128 ms 7004 KB Output is correct
12 Correct 130 ms 7044 KB Output is correct
13 Correct 120 ms 6996 KB Output is correct
14 Correct 119 ms 6996 KB Output is correct
15 Correct 95 ms 7252 KB Output is correct
16 Correct 57 ms 4432 KB Output is correct
17 Correct 87 ms 7732 KB Output is correct
18 Correct 94 ms 7508 KB Output is correct
19 Correct 96 ms 7836 KB Output is correct
20 Correct 102 ms 7448 KB Output is correct
21 Correct 243 ms 56332 KB Output is correct
22 Correct 455 ms 72348 KB Output is correct
23 Correct 427 ms 72236 KB Output is correct
24 Correct 339 ms 70108 KB Output is correct
25 Correct 418 ms 72236 KB Output is correct
26 Correct 465 ms 72348 KB Output is correct
27 Correct 259 ms 56344 KB Output is correct
28 Correct 405 ms 72236 KB Output is correct
29 Correct 177 ms 60244 KB Output is correct
30 Correct 140 ms 60244 KB Output is correct
31 Correct 157 ms 60244 KB Output is correct
32 Correct 152 ms 60408 KB Output is correct
33 Correct 630 ms 59260 KB Output is correct
34 Correct 579 ms 59008 KB Output is correct
35 Correct 492 ms 54404 KB Output is correct
36 Correct 476 ms 54396 KB Output is correct
37 Correct 332 ms 56212 KB Output is correct
38 Correct 243 ms 52368 KB Output is correct
39 Correct 355 ms 66928 KB Output is correct
40 Correct 284 ms 43588 KB Output is correct
41 Correct 245 ms 50492 KB Output is correct
42 Correct 394 ms 66720 KB Output is correct
43 Correct 294 ms 59472 KB Output is correct
44 Correct 367 ms 61484 KB Output is correct
45 Correct 165 ms 55416 KB Output is correct
46 Correct 161 ms 50832 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 2915 ms 46004 KB Output is correct
50 Correct 2952 ms 45840 KB Output is correct
51 Execution timed out 3065 ms 45940 KB Time limit exceeded
52 Halted 0 ms 0 KB -