답안 #486770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486770 2021-11-12T18:17:11 Z davi_bart Patkice II (COCI21_patkice2) C++14
15 / 110
2000 ms 140204 KB
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char v[2010][2010];
bool vis[2010][2010];
int dd[2010][2010];
int N, M;
void solve(pair<int, int> start) {
    priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > q;
    q.push({0, start});
    while (!q.empty()) {
        auto [d, pos] = q.top();
        q.pop();
        if (pos.fi < 0 || pos.fi >= N || pos.se < 0 || pos.se >= M || vis[pos.fi][pos.se]) continue;
        vis[pos.fi][pos.se] = 1;
        dd[pos.fi][pos.se] = d;
        if (v[pos.fi][pos.se] == 'x') return;

        q.push({d + (v[pos.fi][pos.se] != '^'), {pos.fi - 1, pos.se}});
        q.push({d + (v[pos.fi][pos.se] != 'v'), {pos.fi + 1, pos.se}});
        q.push({d + (v[pos.fi][pos.se] != '<'), {pos.fi, pos.se - 1}});
        q.push({d + (v[pos.fi][pos.se] != '>'), {pos.fi, pos.se + 1}});
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    pair<int, int> start, fine;
    for (int i = 0; i < N; i++) {
        string a;
        cin >> a;
        for (int j = 0; j < M; j++) {
            v[i][j] = a[j];
            if (a[j] == 'o') start = {i, j};
            if (a[j] == 'x') fine = {i, j};
        }
    }
    solve(start);
    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < M; j++) {
    //         dd[i][j]--;
    //         cout << dd[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dd[fine.fi][fine.se] - 1 << '\n';
}

Compilation message

Main.cpp: In function 'void solve(std::pair<long long int, long long int>)':
Main.cpp:19:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |         auto [d, pos] = q.top();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 332 KB Partially correct
2 Partially correct 0 ms 332 KB Partially correct
3 Partially correct 1 ms 460 KB Partially correct
4 Partially correct 1 ms 460 KB Partially correct
5 Partially correct 0 ms 332 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 332 KB Partially correct
2 Partially correct 0 ms 332 KB Partially correct
3 Partially correct 1 ms 460 KB Partially correct
4 Partially correct 1 ms 460 KB Partially correct
5 Partially correct 0 ms 332 KB Partially correct
6 Partially correct 170 ms 7428 KB Partially correct
7 Partially correct 157 ms 24568 KB Partially correct
8 Partially correct 592 ms 17264 KB Partially correct
9 Partially correct 1281 ms 74160 KB Partially correct
10 Partially correct 1692 ms 36896 KB Partially correct
11 Execution timed out 2089 ms 140204 KB Time limit exceeded