답안 #933431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933431 2024-02-25T16:09:31 Z LucaIlie Toll (BOI17_toll) C++17
7 / 100
357 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_K = 5;
const int MAX_N = 5e4;
const int INF = 1e9;
int k;

struct matrix {
    int n;
    vector<vector<int>> mat;

    void init( int _n ) {
        n = _n;
        mat.resize( n );
        for ( int i = 0; i < n; i++ ) {
            mat[i].resize( n );
            for ( int j = 0; j < n; j++ )
                mat[i][j] = INF;
        }
    }

    matrix operator + ( matrix b ) {
        matrix a = *this;
        matrix c;
        c.init( n );

        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                for ( int k = 0; k < n; k++ )
                    c.mat[i][j] = min( c.mat[i][j], a.mat[i][k] + b.mat[k][j] );
            }
        }

        return c;
    }
};


matrix buckets[MAX_N];

struct SEG_TREE {
    int n;
    vector<matrix> segTree;

    void init( int v, int l, int r ) {
        if ( l == r ) {
            segTree[v] = buckets[l];
            return;
        }
        int mid = (l + r) / 2;
        init( v * 2 + 1, l, mid );
        init( v * 2 + 2, mid + 1, r );
        segTree[v] = segTree[v * 2 + 1] + segTree[v * 2 + 2];
    }

    void init( int _n ) {
        n = _n;
        segTree.resize( 4 * n );
        init( 0, 0, n - 1 );
    }

    matrix query( int v, int l, int r, int lq, int rq ) {
        if ( lq <= l && r <= rq )
            return segTree[v];

        int mid = (l + r) / 2;
        if ( mid < lq )
            return query( v * 2 + 2, mid + 1, r, lq, rq );
        if ( mid + 1 > rq )
            return query( v * 2 + 1, l, mid, lq, rq );
        return query( v * 2 + 1, l, mid, lq, rq ) + query( v * 2 + 2, mid + 1, r, lq, rq );
    }

    matrix query( int l, int r ) {
        return query( 0, 0, n - 1, l, r );
    }
} toll;

int main() {
    int k, n, m, o;

    cin >> k >> n >> m >> o;


    int b = 0;
    for ( int i = 0; i < n; i += k ) {
        buckets[i / k].init( k );
        b++;
    }
    for ( int i = 0; i < m; i++ ) {
        int a, b, c;
        cin >> a >> b >> c;
        buckets[a / k].mat[a % k][b % k] = c;
    }
    toll.init( b );

    while ( o-- ) {
        int l, r;

        cin >> l >> r;
        int ans = toll.query( l / k, r / k - 1 ).mat[l % k][r % k];
        if ( ans == INF || l / k >= r / k )
            cout << "-1\n";
        else
            cout << ans << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 17488 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 4 ms 2140 KB Output is correct
6 Correct 5 ms 2136 KB Output is correct
7 Correct 5 ms 2140 KB Output is correct
8 Correct 87 ms 18552 KB Output is correct
9 Correct 83 ms 18516 KB Output is correct
10 Correct 58 ms 17744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 14584 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Runtime error 357 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Runtime error 290 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Runtime error 290 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 17488 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 4 ms 2140 KB Output is correct
6 Correct 5 ms 2136 KB Output is correct
7 Correct 5 ms 2140 KB Output is correct
8 Correct 87 ms 18552 KB Output is correct
9 Correct 83 ms 18516 KB Output is correct
10 Correct 58 ms 17744 KB Output is correct
11 Correct 125 ms 14584 KB Output is correct
12 Correct 1 ms 1880 KB Output is correct
13 Runtime error 357 ms 524288 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -