Submission #843182

# Submission time Handle Problem Language Result Execution time Memory
843182 2023-09-03T18:48:31 Z Youssif_Elkadi Tracks in the Snow (BOI13_tracks) C++17
13.125 / 100
466 ms 66652 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define F first
#define S second
const int N = 4000;
int n, m, ans = 1;
char c[N][N];
bool fc[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
vector<pair<int, int>> f, r;
bool vis[N][N];
 
void dfs(int i, int j)
{
    for (int ii = 0; ii < 4; ii++)
    {
        int nx = i + dx[ii], ny = j + dy[ii];
        if (nx < 0 || ny < 0 || nx >= n || ny >= m)
            continue;
 
        if (c[nx][ny] == c[0][0])
        {
            if (!fc[nx][ny] && !vis[nx][ny]){
                
				fc[nx][ny]=1,vis[nx][ny]=1;
              dfs(nx, ny);
            	
            }
          else return;
        }
        else if (!vis[nx][ny])
        {
            if (c[nx][ny] == 'F')
                f.pb({nx, ny});
            else if (c[nx][ny] == 'R')
                r.pb({nx, ny});
            vis[nx][ny] = true;
        }
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> c[i][j];
        }
    }
    dfs(0, 0);
  fc[0][0] = true;
    vis[0][0] = true;
    char cur = 'R';
    if (c[0][0] == cur)
        cur = 'F';
    while (!f.empty() || !r.empty())
    {
        if (cur == 'R')
        {
            if (!r.empty())
                ans++;
            while (!r.empty())
            {
                int x = r.back().F, y = r.back().S;
                r.pop_back();
                for (int i = 0; i < 4; i++)
                {
                    int nx = x + dx[i], ny = y + dy[i];
                    if (nx < 0 || ny < 0 || nx >= n || ny >= m)
                        continue;
                    if (vis[nx][ny])
                        continue;
                    vis[nx][ny] = true;
                    if (c[nx][ny] == 'R')
                        r.pb({nx, ny});
                    else if (c[nx][ny] == 'F')
                        f.pb({nx, ny});
                }
            }
        }
        else
        {
            if (!f.empty())
            {
                ans++;
            }
            while (!f.empty())
            {
                int x = f.back().F, y = f.back().S;
                f.pop_back();
                for (int i = 0; i < 4; i++)
                {
                    int nx = x + dx[i], ny = y + dy[i];
                    if (nx < 0 || ny < 0 || nx >= n || ny >= m)
                        continue;
                    if (vis[nx][ny])
                        continue;
                    vis[nx][ny] = true;
                    if (c[nx][ny] == 'R')
                        r.pb({nx, ny});
                    else if (c[nx][ny] == 'F')
                        f.pb({nx, ny});
                }
            }
        }
        if (cur == 'F')
            cur = 'R';
        else
            cur = 'F';
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8536 KB Output isn't correct
2 Incorrect 1 ms 4440 KB Output isn't correct
3 Incorrect 1 ms 4696 KB Output isn't correct
4 Incorrect 6 ms 8920 KB Output isn't correct
5 Incorrect 3 ms 5464 KB Output isn't correct
6 Incorrect 1 ms 4456 KB Output isn't correct
7 Incorrect 1 ms 4700 KB Output isn't correct
8 Incorrect 1 ms 4696 KB Output isn't correct
9 Incorrect 1 ms 4952 KB Output isn't correct
10 Incorrect 3 ms 5552 KB Output isn't correct
11 Incorrect 3 ms 5468 KB Output isn't correct
12 Incorrect 4 ms 5720 KB Output isn't correct
13 Incorrect 3 ms 5464 KB Output isn't correct
14 Incorrect 2 ms 5464 KB Output isn't correct
15 Incorrect 8 ms 8536 KB Output isn't correct
16 Incorrect 9 ms 8536 KB Output isn't correct
17 Incorrect 7 ms 8280 KB Output isn't correct
18 Incorrect 6 ms 8916 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 46680 KB Output isn't correct
2 Incorrect 38 ms 13656 KB Output isn't correct
3 Correct 227 ms 48072 KB Output is correct
4 Incorrect 54 ms 17868 KB Output isn't correct
5 Incorrect 84 ms 37592 KB Output isn't correct
6 Incorrect 454 ms 62868 KB Output isn't correct
7 Correct 14 ms 47704 KB Output is correct
8 Incorrect 13 ms 46680 KB Output isn't correct
9 Incorrect 2 ms 4696 KB Output isn't correct
10 Correct 1 ms 4952 KB Output is correct
11 Incorrect 14 ms 47448 KB Output isn't correct
12 Incorrect 1 ms 4952 KB Output isn't correct
13 Incorrect 33 ms 13532 KB Output isn't correct
14 Incorrect 20 ms 10072 KB Output isn't correct
15 Incorrect 12 ms 15448 KB Output isn't correct
16 Incorrect 6 ms 4440 KB Output isn't correct
17 Incorrect 86 ms 20696 KB Output isn't correct
18 Incorrect 38 ms 25424 KB Output isn't correct
19 Incorrect 55 ms 18116 KB Output isn't correct
20 Incorrect 56 ms 23632 KB Output isn't correct
21 Correct 137 ms 40276 KB Output is correct
22 Incorrect 88 ms 37456 KB Output isn't correct
23 Incorrect 65 ms 12624 KB Output isn't correct
24 Correct 144 ms 40784 KB Output is correct
25 Incorrect 140 ms 47952 KB Output isn't correct
26 Correct 418 ms 43720 KB Output is correct
27 Incorrect 407 ms 66652 KB Output isn't correct
28 Incorrect 466 ms 61104 KB Output isn't correct
29 Incorrect 448 ms 49440 KB Output isn't correct
30 Incorrect 426 ms 57592 KB Output isn't correct
31 Incorrect 331 ms 30544 KB Output isn't correct
32 Incorrect 361 ms 49064 KB Output isn't correct