Submission #598315

# Submission time Handle Problem Language Result Execution time Memory
598315 2022-07-18T03:08:57 Z nguyen31hoang08minh2003 Pohlepko (COCI16_pohlepko) C++14
80 / 80
14 ms 16368 KB
/*
=/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\=
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
=\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/=
\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/
\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
-//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\-
//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\
\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//
-\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\
=/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\=
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
=\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/=
\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/
\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
-//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\-
//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\//----\\
\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//\\----//
-\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//--\\--//-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\
=/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\==/\=
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
=\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/==\/=
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;

template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};

typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define maxN 2005
#define maxM 2005
const int inf = 0x3f3f3f3f;

const short directions[2][2] = {{0, 1}, {1, 0} };

int n, m;
string board[maxN];
short trace[maxN][maxM];

void input() {
    cin >> n >> m;
    fore(x, 0, n)
        cin >> board[x];
}

void solve() {
    vii q[2];
    string result;
    q[0].emplace_back(0, 0);
    memset(trace, -1, sizeof(trace));
    for (int c, flag = 0, u, v; !q[flag].empty(); flag ^= 1) {
        c = inf;
        for (const auto &[x, y] : q[flag])
            for (const auto &[dx, dy] : directions) {
                u = dx + x;
                v = dy + y;
                if (u >= n || v >= m)
                    continue;
                mini(c, board[u][v]);
            }
        for (const auto &[x, y] : q[flag])
            fort(d, 0, 1) {
                const auto &[dx, dy] = directions[d];
                u = dx + x;
                v = dy + y;
                if (u >= n || v >= m || c != board[u][v] || trace[u][v] >= 0)
                    continue;
                trace[u][v] = d;
                q[flag ^ 1].emplace_back(u, v);
            }
        q[flag].clear();
    }
    for (int x = n - 1, y = m - 1; x > 0 || y > 0;) {
        const int &d = trace[x][y];
        result += board[x][y];
        x -= directions[d][0];
        y -= directions[d][1];
    }
    result += board[0][0];
    reverse(all(result));
    cout << result << '\n';
}

int main() {
    #ifdef LOCAL
        freopen("input.INP", "r", stdin);
    #endif // LOCAL
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);
    input();
    solve();
    return 0;
}

Compilation message

pohlepko.cpp: In function 'void solve()':
pohlepko.cpp:78:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |         for (const auto &[x, y] : q[flag])
      |                          ^
pohlepko.cpp:79:30: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   79 |             for (const auto &[dx, dy] : directions) {
      |                              ^
pohlepko.cpp:86:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   86 |         for (const auto &[x, y] : q[flag])
      |                          ^
pohlepko.cpp:88:29: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |                 const auto &[dx, dy] = directions[d];
      |                             ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 3 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 4 ms 8276 KB Output is correct
6 Correct 4 ms 8660 KB Output is correct
7 Correct 7 ms 10828 KB Output is correct
8 Correct 12 ms 16368 KB Output is correct
9 Correct 4 ms 8204 KB Output is correct
10 Correct 4 ms 8344 KB Output is correct
11 Correct 3 ms 8476 KB Output is correct
12 Correct 4 ms 8916 KB Output is correct
13 Correct 4 ms 8580 KB Output is correct
14 Correct 13 ms 16312 KB Output is correct
15 Correct 3 ms 8276 KB Output is correct
16 Correct 14 ms 11468 KB Output is correct