Submission #636201

#TimeUsernameProblemLanguageResultExecution timeMemory
636201nguyen31hoang08minh2003Bajka (COCI20_bajka)C++14
70 / 70
118 ms2348 KiB
/* \|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/ \\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||// /-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\ \--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/ /---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\ \---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/ /--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\ \-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/ //||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\ /|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\ \|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/\|\//\\//\\/|/ \\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||//\\||\//\\/||// /-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\/-\|||\/|||/-\ \--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/\--\||/\||/--/ /---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\/---\//\\/---\ \---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/\---/\\//\---/ /--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\/--/||\/||\--\ \-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/\-/|||/\|||\-/ //||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\//||/\\//\||\\ /|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\/|/\\//\\//\|\ */ #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 305 #define maxM 305 const int inf = 0X3F3F3F3F; int n, m, d[maxN][maxM]; string s, t; priority_queue<array<int, 3>, vector<array<int, 3> >, greater<array<int, 3> > > pq; void pushQueue(const int x, const int y, const int w) { if (mini(d[x][y], w)) { if (y >= m) { cout << d[x][y] << '\n'; exit(0); } pq.push({d[x][y], x, y}); } } int main() { #ifdef LOCAL freopen("input.INP", "r", stdin); // freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(d, inf, sizeof(d)); cin >> n >> m >> s >> t; fore(i, 0, n) { if (s[i] != t[0]) continue; pushQueue(i, 1, 0); } for (; !pq.empty();) { const auto [w, x, y] = pq.top(); pq.pop(); if (w != d[x][y]) continue; if (x > 0 && s[x - 1] == t[y]) pushQueue(x - 1, y + 1, w + 1); if (x + 1 < n && s[x + 1] == t[y]) pushQueue(x + 1, y + 1, w + 1); fore(i, 0, n) if (s[x] == s[i]) pushQueue(i, y, w + abs(x - i)); } cout << -1 << '\n'; return 0; }

Compilation message (stderr)

bajka.cpp: In function 'int main()':
bajka.cpp:81:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |         const auto [w, x, y] = pq.top();
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...