Submission #63732

# Submission time Handle Problem Language Result Execution time Memory
63732 2018-08-02T14:54:04 Z Bodo171 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1561 ms 119292 KB
#include <iostream>
#include <fstream>
#include <queue>
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)
{

    deque< pair<int,int> > q;
    q.push_back({L,C});
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
           d[i][j]=n*m+1;
    d[L][C]=0;
        while(!q.empty())
        {
             li=q.front().first;ci=q.front().second;q.pop_front();
              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-1]=='R'||s[lf][cf-1]=='F'))
                  {
                      dd=d[li][ci]+(s[li][ci-1]!=s[lf][cf-1]);
                      if(dd<d[lf][cf])
                      {
                          d[lf][cf]=dd;
                          if(dd==d[li][ci]) q.push_front({lf,cf});
                          else q.push_back({lf,cf});
                      }
                  }
              }
        }
}
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]);
    }
    dij(1,1);
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
          if(s[i][j-1]=='R'||s[i][j-1]=='F')
             mx=max(mx,d[i][j]);
    cout<<mx+1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 3704 KB Output is correct
2 Correct 3 ms 3704 KB Output is correct
3 Correct 1 ms 3704 KB Output is correct
4 Correct 17 ms 3704 KB Output is correct
5 Correct 8 ms 3704 KB Output is correct
6 Correct 3 ms 3704 KB Output is correct
7 Correct 4 ms 3704 KB Output is correct
8 Correct 4 ms 3704 KB Output is correct
9 Correct 4 ms 3704 KB Output is correct
10 Correct 6 ms 3704 KB Output is correct
11 Correct 6 ms 3704 KB Output is correct
12 Correct 13 ms 3704 KB Output is correct
13 Correct 8 ms 3704 KB Output is correct
14 Correct 7 ms 3704 KB Output is correct
15 Correct 26 ms 3920 KB Output is correct
16 Correct 34 ms 4052 KB Output is correct
17 Correct 21 ms 4052 KB Output is correct
18 Correct 20 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 16348 KB Output is correct
2 Correct 77 ms 16348 KB Output is correct
3 Correct 416 ms 81128 KB Output is correct
4 Correct 135 ms 81128 KB Output is correct
5 Correct 287 ms 81128 KB Output is correct
6 Correct 1386 ms 95032 KB Output is correct
7 Correct 20 ms 95032 KB Output is correct
8 Correct 15 ms 95032 KB Output is correct
9 Correct 5 ms 95032 KB Output is correct
10 Correct 3 ms 95032 KB Output is correct
11 Correct 18 ms 95032 KB Output is correct
12 Correct 5 ms 95032 KB Output is correct
13 Correct 92 ms 95032 KB Output is correct
14 Correct 51 ms 95032 KB Output is correct
15 Correct 35 ms 95032 KB Output is correct
16 Correct 40 ms 95032 KB Output is correct
17 Correct 186 ms 95032 KB Output is correct
18 Correct 165 ms 95032 KB Output is correct
19 Correct 121 ms 95032 KB Output is correct
20 Correct 107 ms 95032 KB Output is correct
21 Correct 288 ms 95032 KB Output is correct
22 Correct 265 ms 95032 KB Output is correct
23 Correct 411 ms 95032 KB Output is correct
24 Correct 209 ms 95032 KB Output is correct
25 Correct 742 ms 95032 KB Output is correct
26 Correct 686 ms 119292 KB Output is correct
27 Correct 1022 ms 119292 KB Output is correct
28 Correct 1561 ms 119292 KB Output is correct
29 Correct 1266 ms 119292 KB Output is correct
30 Correct 1256 ms 119292 KB Output is correct
31 Correct 1301 ms 119292 KB Output is correct
32 Correct 1051 ms 119292 KB Output is correct