답안 #924498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924498 2024-02-09T05:56:11 Z Faisal_Saqib Toll (BOI17_toll) C++17
7 / 100
3000 ms 10156 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
// #define int long long
const int N=5e4+2;
vector<pair<int,int>> ma[N],query[N];
vector<int> block[N];
int index[N];
bool vis[N];
int ans[N];
int Dist_next[6][N];
int Dist_this[6][N];
signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int k,n,m,q;
    cin>>k>>n>>m>>q;
    for(int j=0;j<m;j++)
    {
        int a,b,t;
        cin>>a>>b>>t;
        ma[a].push_back({b,t});
    }
    for(int lp=0;lp<q;lp++)
    {
        int x,y;
        cin>>x>>y;
        query[x].push_back({y,lp});
    }
    for(int i=0;i<n;i++)
    {
        index[i]=block[i/k].size();
        block[(i/k)].push_back(i);
    }
    for(int ind=0;ind<k;ind++)
        for(int l=0;l<n;l++)
            Dist_next[ind][l]=Dist_this[ind][l]=1e9;
    for(int i=n-1;i>=0;i--)
    {
        if(!vis[(i/k)])
        {
            vis[(i/k)]=1;
	        // cout<<"Block: ";
	        int st=block[i/k][0];
            for(int& vertex:block[i/k])
            {
            	// cout<<vertex<<' ';
                Dist_this[index[vertex]][vertex]=0;
                for(auto& [adj,wei]:ma[vertex]) // O(k)
                {
                    Dist_this[index[vertex]][adj]=wei;
                    for(int to=st;to<n;to++)
                    {
                        Dist_this[index[vertex]][to]=min(Dist_this[index[vertex]][to],Dist_next[index[adj]][to]+wei);
                    }
                }
                for(auto& [y,inp]:query[vertex])
                {
                    if(y==vertex)
                    {
                        ans[inp]=0;
                    }
                    else if(y<(i+1))
                    {
                        ans[inp]=-1;
                    }
                    else
                    {
                        ans[inp]=((Dist_this[index[vertex]][y]==1e9)?-1:Dist_this[index[vertex]][y]);
                    }
                }
            }
            for(int ind=0;ind<k;ind++)
            {
                for(int l=st;l<n;l++)
                {
                    Dist_next[ind][l]=Dist_this[ind][l];
                    Dist_this[ind][l]=1e9;
                }
            }
        }
    }
    for(int lp=0;lp<q;lp++)
        cout<<ans[lp]<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2896 ms 10152 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 2887 ms 10156 KB Output is correct
9 Correct 2768 ms 10072 KB Output is correct
10 Correct 523 ms 8600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3044 ms 9156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 4 ms 6492 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 6 ms 6504 KB Output is correct
10 Correct 2850 ms 9880 KB Output is correct
11 Execution timed out 3046 ms 9040 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 4 ms 6492 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 6 ms 6504 KB Output is correct
10 Correct 2850 ms 9880 KB Output is correct
11 Execution timed out 3046 ms 9040 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2896 ms 10152 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 2887 ms 10156 KB Output is correct
9 Correct 2768 ms 10072 KB Output is correct
10 Correct 523 ms 8600 KB Output is correct
11 Execution timed out 3044 ms 9156 KB Time limit exceeded
12 Halted 0 ms 0 KB -