제출 #477993

#제출 시각아이디문제언어결과실행 시간메모리
477993manh2004Bajka (COCI20_bajka)C++14
20 / 70
1093 ms1264 KiB
/// HDM #include <bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back #define ld long double #define time cout << "\nTime: " << clock()/(double) 1000 << "s " #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define inp freopen(duckman".inp", "r", stdin); #define out freopen(duckman".out", "w", stdout); const ll oo = 4557430888798830399; #define duckman "Bajka" const ll nmax = 1e6 + 5, mod = 1000000007; using namespace std; int n, m; string a, b; vector<int> idx[400]; void Read() { cin >> n >> m; cin >> a >> b; for (int i = 0; i < n; ++i) { idx[a[i]].pb(i); } } int ans = INT_MAX; int dp[500][500]; void Try(int cnt, int i, int cost) { if (cnt >= m) { ans = min(ans, cost); return; } if (dp[cnt][i] < cost) { return; } dp[cnt][i] = cost; if (i - 1 >= 0) { if (a[i - 1] == b[cnt]) { Try(cnt + 1, i - 1, cost + 1); } } if (i + 1 < n) { if (a[i + 1] == b[cnt]) { Try(cnt + 1, i + 1, cost + 1); } } for (auto& j : idx[a[i]]) { if (j != i) { Try(cnt, j, cost + abs(j - i)); } } } void Solve() { memset(dp, 0x3f, sizeof(dp)); for (auto& i : idx[b[0]]) { Try(1, i, 0); } cout << (ans == INT_MAX ? -1 : ans); } int main() { fast; Read(); Solve(); } /* */

컴파일 시 표준 에러 (stderr) 메시지

bajka.cpp: In function 'void Read()':
bajka.cpp:26:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   26 |         idx[a[i]].pb(i);
      |                 ^
bajka.cpp: In function 'void Try(int, int, int)':
bajka.cpp:51:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   51 |     for (auto& j : idx[a[i]]) {
      |                            ^
bajka.cpp: In function 'void Solve()':
bajka.cpp:60:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |     for (auto& i : idx[b[0]]) {
      |                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...