Submission #1020049

# Submission time Handle Problem Language Result Execution time Memory
1020049 2024-07-11T13:14:55 Z 7again Tracks in the Snow (BOI13_tracks) C++17
0 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)

using namespace std ;

void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}

const int N = 2e5 , MOD = 1e9+7 ;
int xis[4]{1 , -1 , 0 , 0} , yis[4]{0 , 0 , 1 , -1} ;

int n , m ;
vector <int> v[N] ;

bool inside(int x , int y)
{
    return (x < n && x > -1 && y < m && y > -1) ;
}
void slv()
{
    cin >> n >> m ;

    char a[n][m] ;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++)
            cin >> a[i][j] ;

    int depth[n][m]{0} ;
    deque <pair <int , int>> q ;
    q.push_back({0 , 0}) ;
    depth[0][0] = 0 ;
    int mx = 1 ;

    while(!q.empty())
    {
        pair <int , int> t = q.front() ;
        q.pop_back() ;

        mx = max(mx , depth[t.f][t.s]) ;

        for(int i = 0 ; i < 4 ; i++)
        {
            int x = t.f + xis[i] , y = t.s = yis[i] ;
            if(inside(x , y) && depth[x][y] == 0)
            {
                if(a[x][y] == a[t.f][t.s])
                {
                    depth[x][y] = depth[t.f][t.s] ;
                    q.push_back({x , y}) ;
                }
                else
                {
                    depth[x][y] = depth[t.f][t.s] + 1 ;
                    q.push_front({x , y}) ;
                }
            }
        }
    }


    cout << mx ;
}
main()
{
    //FAST ;

    slv() ;
}

Compilation message

tracks.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main()
      | ^~~~
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:10:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:10:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1261 ms 1048576 KB Execution killed with signal 9
2 Runtime error 1230 ms 1048576 KB Execution killed with signal 9
3 Execution timed out 2062 ms 4952 KB Time limit exceeded
4 Runtime error 1247 ms 1048576 KB Execution killed with signal 9
5 Execution timed out 2048 ms 5980 KB Time limit exceeded
6 Runtime error 1248 ms 1048576 KB Execution killed with signal 9
7 Execution timed out 2049 ms 4952 KB Time limit exceeded
8 Runtime error 1246 ms 1048576 KB Execution killed with signal 9
9 Execution timed out 2041 ms 5208 KB Time limit exceeded
10 Execution timed out 2096 ms 5720 KB Time limit exceeded
11 Runtime error 1254 ms 1048576 KB Execution killed with signal 9
12 Runtime error 1273 ms 1048576 KB Execution killed with signal 9
13 Execution timed out 2052 ms 5724 KB Time limit exceeded
14 Execution timed out 2066 ms 5724 KB Time limit exceeded
15 Execution timed out 2025 ms 7516 KB Time limit exceeded
16 Runtime error 1226 ms 1048576 KB Execution killed with signal 9
17 Runtime error 1257 ms 1048576 KB Execution killed with signal 9
18 Runtime error 1229 ms 1048576 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 1226 ms 1048576 KB Execution killed with signal 9
2 Runtime error 1295 ms 1048576 KB Execution killed with signal 9
3 Execution timed out 2045 ms 161424 KB Time limit exceeded
4 Execution timed out 2011 ms 41552 KB Time limit exceeded
5 Runtime error 1532 ms 1048576 KB Execution killed with signal 9
6 Execution timed out 2079 ms 161420 KB Time limit exceeded
7 Execution timed out 2053 ms 5480 KB Time limit exceeded
8 Runtime error 1291 ms 1048576 KB Execution killed with signal 9
9 Execution timed out 2007 ms 5468 KB Time limit exceeded
10 Execution timed out 2081 ms 5212 KB Time limit exceeded
11 Runtime error 1267 ms 1048576 KB Execution killed with signal 9
12 Execution timed out 2043 ms 5212 KB Time limit exceeded
13 Runtime error 1189 ms 1048576 KB Execution killed with signal 9
14 Runtime error 1159 ms 1048576 KB Execution killed with signal 9
15 Runtime error 1177 ms 1048576 KB Execution killed with signal 9
16 Execution timed out 2059 ms 11344 KB Time limit exceeded
17 Execution timed out 2061 ms 44628 KB Time limit exceeded
18 Runtime error 1279 ms 1048576 KB Execution killed with signal 9
19 Execution timed out 2071 ms 41556 KB Time limit exceeded
20 Execution timed out 2031 ms 38736 KB Time limit exceeded
21 Runtime error 1363 ms 1048576 KB Execution killed with signal 9
22 Runtime error 1381 ms 1048576 KB Execution killed with signal 9
23 Execution timed out 2065 ms 80636 KB Time limit exceeded
24 Execution timed out 2059 ms 94032 KB Time limit exceeded
25 Execution timed out 2058 ms 161620 KB Time limit exceeded
26 Runtime error 1489 ms 1048576 KB Execution killed with signal 9
27 Runtime error 1523 ms 1048576 KB Execution killed with signal 9
28 Execution timed out 2054 ms 161544 KB Time limit exceeded
29 Runtime error 1545 ms 1048576 KB Execution killed with signal 9
30 Runtime error 1539 ms 1048576 KB Execution killed with signal 9
31 Execution timed out 2055 ms 105352 KB Time limit exceeded
32 Runtime error 1524 ms 1048576 KB Execution killed with signal 9