Submission #83013

# Submission time Handle Problem Language Result Execution time Memory
83013 2018-11-03T21:32:21 Z Bodo171 Soccer (JOI17_soccer) C++14
100 / 100
378 ms 23252 KB
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
const int nmax=505;
const long long lim=1LL*1e18;
int d1[]={-1,0,1,0};
int d2[]={0,-1,0,1};
struct node
{
    long long dd;
    int l,c,st;
};
struct cmp
{
    bool operator()(node unu,node doi)
    {
        return unu.dd>doi.dd;
    }
};
priority_queue< node,vector<node>,cmp> pq;
long long d[nmax][nmax][5];
long long D[nmax][nmax];
bool ok[nmax][nmax];
int n,m,li,ci,si,l1,l2,c1,c2,dir,nr,i,x,y,j,s;
long long di,A,B,C,ans;
void prp(int lf,int cf,int sf,long long df)
{
    if(lf<=0||cf<=0||lf>n||cf>m) return;
    if(df<d[lf][cf][sf])
    {
        d[lf][cf][sf]=df;
        pq.push({df,lf,cf,sf});
    }
}
void dij()
{
    while(!pq.empty())
    {
        li=pq.top().l;ci=pq.top().c;si=pq.top().st;di=pq.top().dd;
        pq.pop();
        if(li==l2&&ci==c2)
        {
            ans=di;
            return;
        }
        if(si==4)
        {
            for(dir=0;dir<4;dir++)
            {
                prp(li,ci,dir,di+1LL*B);
                prp(li+d1[dir],ci+d2[dir],si,di+1LL*C);
            }
        }
        else
        {
            prp(li+d1[si],ci+d2[si],si,di+1LL*A);
            prp(li,ci,4,di+1LL*D[li][ci]*C);
        }
    }
}
queue< pair<int,int> > q;
void prcD()
{
    int lf,cf;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            if(ok[i][j])
           {
               D[i][j]=1;
               q.push({i,j});
           }
    while(!q.empty())
    {
        li=q.front().first;ci=q.front().second;
        q.pop();
        for(int i=0;i<4;i++)
        {
            lf=li+d1[i];cf=ci+d2[i];
            if(lf>0&&lf<=n&&cf>0&&cf<=m&&(!D[lf][cf]))
            {
                D[lf][cf]=D[li][ci]+1;
                q.push({lf,cf});
            }
        }
    }
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
          D[i][j]--;
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    cin>>A>>B>>C;
    cin>>nr;
    n++,m++;
    for(i=1;i<=nr;i++)
    {
        cin>>x>>y;x++,y++;
        if(i<nr)
            ok[x][y]=1;
        if(i==1)
        {
            l1=x;c1=y;
        }
        if(i==nr)
        {
            l2=x;c2=y;
        }
    }
    prcD();
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
           for(s=0;s<5;s++)
             d[i][j][s]=lim;
    d[l1][c1][4]=0;
    pq.push({0,l1,c1,4});
    dij();
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6768 KB Output is correct
2 Correct 2 ms 6768 KB Output is correct
3 Correct 96 ms 18684 KB Output is correct
4 Correct 49 ms 18684 KB Output is correct
5 Correct 50 ms 18684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 18684 KB Output is correct
2 Correct 36 ms 18684 KB Output is correct
3 Correct 128 ms 18684 KB Output is correct
4 Correct 301 ms 19124 KB Output is correct
5 Correct 150 ms 19176 KB Output is correct
6 Correct 183 ms 19176 KB Output is correct
7 Correct 127 ms 19332 KB Output is correct
8 Correct 140 ms 19376 KB Output is correct
9 Correct 30 ms 19376 KB Output is correct
10 Correct 21 ms 19376 KB Output is correct
11 Correct 217 ms 19444 KB Output is correct
12 Correct 234 ms 19444 KB Output is correct
13 Correct 142 ms 19444 KB Output is correct
14 Correct 96 ms 19444 KB Output is correct
15 Correct 22 ms 19444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6768 KB Output is correct
2 Correct 2 ms 6768 KB Output is correct
3 Correct 96 ms 18684 KB Output is correct
4 Correct 49 ms 18684 KB Output is correct
5 Correct 50 ms 18684 KB Output is correct
6 Correct 57 ms 18684 KB Output is correct
7 Correct 36 ms 18684 KB Output is correct
8 Correct 128 ms 18684 KB Output is correct
9 Correct 301 ms 19124 KB Output is correct
10 Correct 150 ms 19176 KB Output is correct
11 Correct 183 ms 19176 KB Output is correct
12 Correct 127 ms 19332 KB Output is correct
13 Correct 140 ms 19376 KB Output is correct
14 Correct 30 ms 19376 KB Output is correct
15 Correct 21 ms 19376 KB Output is correct
16 Correct 217 ms 19444 KB Output is correct
17 Correct 234 ms 19444 KB Output is correct
18 Correct 142 ms 19444 KB Output is correct
19 Correct 96 ms 19444 KB Output is correct
20 Correct 22 ms 19444 KB Output is correct
21 Correct 31 ms 19444 KB Output is correct
22 Correct 240 ms 19444 KB Output is correct
23 Correct 323 ms 19444 KB Output is correct
24 Correct 213 ms 19444 KB Output is correct
25 Correct 227 ms 19444 KB Output is correct
26 Correct 297 ms 19660 KB Output is correct
27 Correct 163 ms 19660 KB Output is correct
28 Correct 240 ms 19660 KB Output is correct
29 Correct 378 ms 19660 KB Output is correct
30 Correct 147 ms 19660 KB Output is correct
31 Correct 71 ms 19660 KB Output is correct
32 Correct 151 ms 23252 KB Output is correct
33 Correct 210 ms 23252 KB Output is correct
34 Correct 41 ms 23252 KB Output is correct
35 Correct 227 ms 23252 KB Output is correct