답안 #914760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914760 2024-01-22T16:10:38 Z vjudge1 Bajka (COCI20_bajka) C++17
20 / 70
35 ms 708 KB
#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag,
// __gnu_pbds::tree_order_statistics_node_update > ordered_set;

//#include "debugging.h"

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define endl '\n'
#define fr(i, x) for (int i = 0; i < x; i++)
#define fr1(i, x) for (int i = 1; i <= x; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define sqr(x) ((x) * (x))
#define cube(x) ((x) * (x) * (x))
#define dbg(v) cerr << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
#define show(v) cerr << v << " ";
#define INT(n) \
    int n;     \
    cin >> n;
const int INF = 1e6;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    string scary, fav;
    cin >> n >> m;
    vvi dist(n + 1, vi(m + 1, INF));
    cin >> scary >> fav;
    fr(i, n) if (scary[i] == fav[0]) dist[i][0] = 0;
    fr1(i, m - 1) {
        fr(j, n) {
            if (scary[j] == fav[i]) {
                fr(k, n) {
                    if (j != k)
                        dist[j][i] = min(dist[j][i], dist[k][i - 1] + abs(j - k));
                }
            }
        }
        fr(j, n) {
            fr(k, n) {
                if (scary[j] == scary[k]) {
                    dist[j][i] = min(dist[j][i], dist[k][i] + abs(j - k));
                }
            }
        }
    }
    int best = INF;
    fr(i, n) best = min(best, dist[i][m - 1]);
    if (best == INF)
        cout << "-1\n";
    else
        cout << best << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 708 KB Output isn't correct
2 Halted 0 ms 0 KB -