Submission #1058893

#TimeUsernameProblemLanguageResultExecution timeMemory
1058893BoasCopy and Paste 3 (JOI22_copypaste3)C++17
0 / 100
3115 ms676976 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T1, typename T2> using indexed_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using indexed_set = indexed_map<T, null_type>; #define loop(x, i) for (int i = 0; i < (x); i++) #define loop1(x, i) for (int i = 1; i <= (x); i++) #define rev(x, i) for (int i = (int)(x) - 1; i >= 0; i--) #define itloop(x) for (auto it = begin(x); x != end(x); it++) #define itrev(x) for (auto it = rbegin(x); x != rend(x); it++) #define int long long #define INF ((int)(2e18 + 1)) #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) #define existsIn(x, l) (count(ALL(l), x) > 0) #define removeIn(x, l) l.erase(find(ALL(l), x)) #define pb push_back #define sz(x) (int)(x).size() #define F first #define S second #define var const auto & #define foreach(l) for (var e : l) typedef int8_t in8; typedef int16_t in16; typedef int32_t in32; typedef int64_t in64; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vii> vvii; typedef vector<viii> vviii; typedef set<int> si; typedef set<ii> sii; typedef set<iii> siii; typedef vector<si> vsi; typedef vector<sii> vsii; typedef vector<vsi> vvsi; typedef vector<string> vstr; typedef vector<vector<string>> vvstr; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vi::iterator viit; typedef si::iterator siit; typedef tuple<int, int, int, int> iiii; int n, a, b, c; string s; map<iiii, int> dp; map<iiii, bool> seen; vi ixs; int calc(int lX = 0, int sX = 0, int lY = 0, int sY = 0) { if (sX == n) return 0; if (sX > n) return INF; if (dp.count({lX, sX, lY, sY})) return dp[{lX, sX, lY, sY}]; if (seen[{lX, sX, lY, sY}]) return INF; seen[{lX, sX, lY, sY}] = 1; int res = INF; if (sX == 0) { for (int i : ixs) { int optA = a + calc(i, 1, lY, sY); res = min(res, optA); if (a >= res) break; } } else { int optA = a + calc(lX, sX + 1, lY, sY); res = min(res, optA); } if (sX && b < res) { int optB = b + calc(0, 0, lX, sX); res = min(res, optB); } if (sY && c < res && lX + sX + sY <= n) { bool val = 1; // check of goede teskt /*loop(sY, i) { if (s[lX + sX + i] != s[lY + i]) { val = 0; break; } }*/ if (val) { int optC = c + calc(lX, sX + sY, lY, sY); res = min(res, optC); } } return dp[{lX, sX, lY, sY}] = res; } void solve() { dp.clear(); ixs.clear(); cin >> n >> s >> a >> b >> c; si chars; loop(n, i) { if (!chars.count(s[i])) { chars.insert(s[i]); ixs.pb(i); } } cout << calc() << endl; } signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...