Submission #63729

# Submission time Handle Problem Language Result Execution time Memory
63729 2018-08-02T14:44:51 Z Bodo171 Tracks in the Snow (BOI13_tracks) C++14
91.25 / 100
2000 ms 205184 KB
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=4005;
int d[nmax][nmax];
pair<int,int> q[2][nmax*nmax];
string s[nmax];
int p[2],u[2];
bool E[nmax][nmax];
int use,mx,i,j,dd,n,m,li,ci,lf,cf,di;
int d1[]={-1,0,1,0};
int d2[]={0,-1,0,1};
void dij(int L,int C)
{
    p[0]=p[1]=1;
    u[0]=u[1]=0;
    q[0][++u[0]]={L,C};use=0;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
           d[i][j]=n*m+1;
    d[L][C]=0;
    for(i=0;i<=n*m;i++)
    {
        if(p[use]>u[use])
            return;
        mx=max(mx,i);
        for(p[use]=1;p[use]<=u[use];p[use]++)
        {
             li=q[use][p[use]].first;ci=q[use][p[use]].second;
             if(i==d[li][ci])
              for(di=0;di<4;di++)
              {
                  lf=li+d1[di];cf=ci+d2[di];
                  if(lf>=1&&cf>=1&&lf<=n&&cf<=m&&(s[lf][cf]=='R'||s[lf][cf]=='F'))
                  {
                      dd=d[li][ci]+(s[li][ci]!=s[lf][cf]);
                      if(dd<d[lf][cf])
                      {
                          d[lf][cf]=dd;
                          q[(dd&1)][++u[(dd&1)]]={lf,cf};
                      }
                  }
              }
        }
        p[use]=1;u[use]=0;
        use=1-use;
    }
}
int main()
{
   // freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;getline(cin,s[0]);
    for(i=1;i<=n;i++)
    {
        getline(cin,s[i]);
        s[i]=" "+s[i];
    }
    dij(1,1);
    cout<<mx+1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4088 KB Output is correct
2 Correct 3 ms 4088 KB Output is correct
3 Correct 4 ms 4088 KB Output is correct
4 Correct 16 ms 4768 KB Output is correct
5 Correct 6 ms 4768 KB Output is correct
6 Correct 3 ms 4768 KB Output is correct
7 Correct 3 ms 4768 KB Output is correct
8 Correct 4 ms 4768 KB Output is correct
9 Correct 4 ms 4768 KB Output is correct
10 Correct 7 ms 4768 KB Output is correct
11 Correct 7 ms 4768 KB Output is correct
12 Correct 17 ms 4768 KB Output is correct
13 Correct 7 ms 4768 KB Output is correct
14 Correct 7 ms 4768 KB Output is correct
15 Correct 30 ms 5156 KB Output is correct
16 Correct 33 ms 5320 KB Output is correct
17 Correct 20 ms 5320 KB Output is correct
18 Correct 17 ms 5640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 17544 KB Output is correct
2 Correct 91 ms 17544 KB Output is correct
3 Correct 367 ms 82024 KB Output is correct
4 Correct 108 ms 82024 KB Output is correct
5 Correct 283 ms 82024 KB Output is correct
6 Execution timed out 2041 ms 165192 KB Time limit exceeded
7 Correct 18 ms 165192 KB Output is correct
8 Correct 17 ms 165192 KB Output is correct
9 Correct 7 ms 165192 KB Output is correct
10 Correct 3 ms 165192 KB Output is correct
11 Correct 21 ms 165192 KB Output is correct
12 Correct 3 ms 165192 KB Output is correct
13 Correct 92 ms 165192 KB Output is correct
14 Correct 49 ms 165192 KB Output is correct
15 Correct 30 ms 165192 KB Output is correct
16 Correct 41 ms 165192 KB Output is correct
17 Correct 223 ms 165192 KB Output is correct
18 Correct 125 ms 165192 KB Output is correct
19 Correct 111 ms 165192 KB Output is correct
20 Correct 93 ms 165192 KB Output is correct
21 Correct 289 ms 165192 KB Output is correct
22 Correct 252 ms 165192 KB Output is correct
23 Correct 489 ms 165192 KB Output is correct
24 Correct 224 ms 165192 KB Output is correct
25 Correct 657 ms 165192 KB Output is correct
26 Correct 1241 ms 166492 KB Output is correct
27 Correct 1922 ms 205184 KB Output is correct
28 Execution timed out 2029 ms 205184 KB Time limit exceeded
29 Execution timed out 2052 ms 205184 KB Time limit exceeded
30 Execution timed out 2069 ms 205184 KB Time limit exceeded
31 Correct 1629 ms 205184 KB Output is correct
32 Correct 1324 ms 205184 KB Output is correct