Submission #61379139


Source Code Expand

Copy
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
array<int, 2> st, en;
vector<vector<char>> a(n, vector<char>(m));
for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
cin >> a[i][j];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;

    array<int, 2> st, en;
    vector<vector<char>> a(n, vector<char>(m));
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
        cin >> a[i][j];
        if (a[i][j] == 'S') {
            st = {i, j};
        }
        if (a[i][j] == 'G') {
            en = {i, j};
        }
    }

    auto check = [&](int x, int y) -> bool {
        return 0 <= x and x < n and 0 <= y and y < m and a[x][y] != '#';
    };

    queue<array<int, 4>> q;
    vector dis(n, vector(m, vector(2, -1)));
    q.push({st[0], st[1], -1, 0});
    while (not q.empty()) {
        auto [x, y, z, d] = q.front();
        if (en[0] == x and en[1] == y) {
            cout << d << endl;
            return;
        }
        q.pop();
        if (z != 0) {
            if (check(x - 1, y) and dis[x - 1][y][0] == -1) {
                dis[x - 1][y][0] = d + 1;
                q.push({x - 1, y, 0, d + 1});
            }
            if (check(x + 1, y) and dis[x + 1][y][0] == -1) {
                dis[x + 1][y][0] = d + 1;
                q.push({x + 1, y, 0, d + 1});
            }
        }
        if (z != 1) {
            if (check(x, y - 1) and dis[x][y - 1][1] == -1) {
                dis[x][y - 1][1] = d + 1;
                q.push({x, y - 1, 1, d + 1});
            }
            if (check(x, y + 1) and dis[x][y + 1][1] == -1) {
                dis[x][y + 1][1] = d + 1;
                q.push({x, y + 1, 1, d + 1});
            }
        }
    }
    cout << -1 << endl;
}

signed main() {

#ifndef CDuongg
    if (fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}

Submission Info

Submission Time
Task D - Snaky Walk
User bimatbatmi
Language C++ 23 (gcc 12.2)
Score 400
Code Size 2589 Byte
Status AC
Exec Time 138 ms
Memory 58888 KB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:36:11: warning: ‘st.std::array<int, 2>::_M_elems[1]’ may be used uninitialized [-Wmaybe-uninitialized]
   36 |     q.push({st[0], st[1], -1, 0});
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:19: note: ‘st.std::array<int, 2>::_M_elems[1]’ was declared here
   18 |     array<int, 2> st, en;
      |                   ^~
Main.cpp:39:24: warning: ‘en.std::array<int, 2>::_M_elems[1]’ may be used uninitialized [-Wmaybe-uninitialized]
   39 |         if (en[0] == x and en[1] == y) {
Main.cpp:18:23: note: ‘en.std::array<int, 2>::_M_elems[1]’ was declared here
   18 |     array<int, 2> st, en;
      |                       ^~
Main.cpp:36:11: warning: ‘st.std::array<int, 2>::_M_elems[0]’ may be used uninitialized [-Wmaybe-uninitialized]
   36 |     q.push({st[0], st[1], -1, 0});
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:19: note: ‘st.std::array<int, 2>::_M_elems[0]’ was declared here
   18 |     array<int, 2> st, en;
      |                   ^~
Main.cpp:39:24: warning: ‘en.std::array<int, 2>::_M_elems[0]’ may be used uninitialized [-Wmaybe-uninitialized]
   39 |         if (en[0] == x and en[1] == y) {
Main.cpp:18:23: note: ‘en.std::array<int, 2>::_M_elems[0]’ was declared here
   18 |     array<int, 2> st, en;
      |                       ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 57
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_random4_00.txt, 04_random4_01.txt, 04_random4_02.txt, 04_random4_03.txt, 05_handmade_00.txt, 05_handmade_01.txt, 05_handmade_02.txt, 05_handmade_03.txt, 05_handmade_04.txt, 05_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3512 KB
00_sample_01.txt AC 1 ms 3428 KB
00_sample_02.txt AC 1 ms 3544 KB
01_random_00.txt AC 19 ms 19920 KB
01_random_01.txt AC 2 ms 4448 KB
01_random_02.txt AC 43 ms 47004 KB
01_random_03.txt AC 12 ms 14724 KB
01_random_04.txt AC 31 ms 34596 KB
01_random_05.txt AC 2 ms 4428 KB
01_random_06.txt AC 1 ms 3516 KB
01_random_07.txt AC 1 ms 3540 KB
01_random_08.txt AC 55 ms 58744 KB
01_random_09.txt AC 96 ms 58656 KB
01_random_10.txt AC 93 ms 58656 KB
01_random_11.txt AC 68 ms 58656 KB
01_random_12.txt AC 72 ms 58748 KB
01_random_13.txt AC 96 ms 58760 KB
01_random_14.txt AC 66 ms 58740 KB
01_random_15.txt AC 55 ms 58728 KB
01_random_16.txt AC 55 ms 58812 KB
01_random_17.txt AC 55 ms 58728 KB
01_random_18.txt AC 105 ms 58888 KB
01_random_19.txt AC 67 ms 58704 KB
02_random2_00.txt AC 55 ms 58768 KB
02_random2_01.txt AC 54 ms 58740 KB
02_random2_02.txt AC 54 ms 58824 KB
02_random2_03.txt AC 55 ms 58788 KB
02_random2_04.txt AC 55 ms 58756 KB
02_random2_05.txt AC 56 ms 58768 KB
02_random2_06.txt AC 55 ms 58828 KB
02_random2_07.txt AC 55 ms 58724 KB
02_random2_08.txt AC 55 ms 58792 KB
02_random2_09.txt AC 56 ms 58792 KB
02_random2_10.txt AC 55 ms 58728 KB
02_random2_11.txt AC 55 ms 58660 KB
02_random2_12.txt AC 55 ms 58724 KB
02_random2_13.txt AC 55 ms 58756 KB
02_random2_14.txt AC 54 ms 58728 KB
02_random2_15.txt AC 55 ms 58656 KB
02_random2_16.txt AC 55 ms 58744 KB
02_random2_17.txt AC 55 ms 58724 KB
02_random2_18.txt AC 56 ms 58744 KB
02_random2_19.txt AC 55 ms 58796 KB
03_random3_00.txt AC 131 ms 58808 KB
03_random3_01.txt AC 82 ms 58720 KB
03_random3_02.txt AC 127 ms 58808 KB
03_random3_03.txt AC 127 ms 58724 KB
04_random4_00.txt AC 113 ms 58660 KB
04_random4_01.txt AC 112 ms 58776 KB
04_random4_02.txt AC 114 ms 58768 KB
04_random4_03.txt AC 113 ms 58832 KB
05_handmade_00.txt AC 68 ms 58744 KB
05_handmade_01.txt AC 86 ms 58700 KB
05_handmade_02.txt AC 1 ms 3516 KB
05_handmade_03.txt AC 1 ms 3512 KB
05_handmade_04.txt AC 1 ms 3676 KB
05_handmade_05.txt AC 138 ms 58828 KB


2025-03-05 (Wed)
03:40:25 +00:00