Submission #61181062
Source Code Expand
// I AM A MUSLIM
#include "bits/stdc++.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define fast_io std::ios::sync_with_stdio(0);std::cin.tie(0)
#define lli long long int
#define flush fflush(stdout)
#define new_line printf("\n")
#define yn(a, b) printf("%s\n", (a) >= (b) ? "Yes":"No")
#define amodm(a, M) (((a)%M+M)%M)
// #define int lli
using pii = std::pair<int,int>;
const int MOD = 1000000007;
const int mxN = 500100;
// From YouKn0wWho's template
const int N = mxN;
const int MOD1 = 127657753, MOD2 = 987654319;
const int p1 = 137, p2 = 277;
int ip1, ip2;
std::pair<int, int> pw[N], ipw[N];
int power(long long n, long long k, const int mod) {
int ans = 1 % mod;
n %= mod;
if (n < 0) n += mod;
while (k) {
if (k & 1) ans = (long long) ans * n % mod;
n = (long long) n * n % mod;
k >>= 1;
}
return ans;
}
void prec() {
pw[0] = {1, 1};
for (int i = 1; i < N; i++) {
pw[i].first = 1LL * pw[i - 1].first * p1 % MOD1;
pw[i].second = 1LL * pw[i - 1].second * p2 % MOD2;
}
ip1 = power(p1, MOD1 - 2, MOD1);
ip2 = power(p2, MOD2 - 2, MOD2);
ipw[0] = {1, 1};
for (int i = 1; i < N; i++) {
ipw[i].first = 1LL * ipw[i - 1].first * ip1 % MOD1;
ipw[i].second = 1LL * ipw[i - 1].second * ip2 % MOD2;
}
}
struct Hashing {
int n;
std::string s; // 0 - indexed
std::vector<std::pair<int, int>> hs; // 1 - indexed
Hashing() {}
Hashing(std::string _s) {
n = _s.size();
s = _s;
hs.emplace_back(0, 0);
for (int i = 0; i < n; i++) {
std::pair<int, int> p;
p.first = (hs[i].first + 1LL * pw[i].first * s[i] % MOD1) % MOD1;
p.second = (hs[i].second + 1LL * pw[i].second * s[i] % MOD2) % MOD2;
hs.push_back(p);
}
}
std::pair<int, int> get_hash(int l, int r) { // 1 - indexed
assert(1 <= l && l <= r && r <= n);
std::pair<int, int> ans;
ans.first = (hs[r].first - hs[l - 1].first + MOD1) * 1LL * ipw[l - 1].first % MOD1;
ans.second = (hs[r].second - hs[l - 1].second + MOD2) * 1LL * ipw[l - 1].second % MOD2;
return ans;
}
std::pair<int, int> get_hash() {
return get_hash(1, n);
}
};
std::vector<std::unordered_map<int,int>> dp(mxN);
signed main() {
int testCases=1;
// scanf("%d",&testCases);
prec();
for (int TC = 1; TC <= testCases; TC++) {
int k; scanf("%d",&k);
std::string s, t;
std::cin >> s >> t;
int m = (int)s.size(), n = (int)t.size();
Hashing hs(s);
Hashing ht(t);
std::function<int(int,int,int)> fn1 = [&] (int i, int j, int L) {
if (i == 0) return j;
if (j == 0) return i;
if (dp[i].find(j) != dp[i].end()) return dp[i][j];
if (L == 10) {
if (hs.get_hash(1, i) == ht.get_hash(1, j)) return 0;
return 100;
}
if (s[i - 1] == t[j - 1])
return dp[i][j] = fn1(i - 1, j - 1, L);
return dp[i][j] = 1 + std::min({fn1(i, j - 1, L+1), // Insert
fn1(i - 1, j, L+1), // Remove
fn1(i - 1, j - 1, L+1) // Replace
});
};
std::function<int(int,int,int)> fn = [&] (int i, int j, int L) {
if (i == 0) return j;
if (j == 0) return i;
if (L == 10) {
return fn1(i, j, 0);
// return 0;
}
if (s[i - 1] == t[j - 1])
return fn(i - 1, j - 1, L);
return 1 + std::min({fn(i, j - 1, L+1), // Insert
fn(i - 1, j, L+1), // Remove
fn(i - 1, j - 1, L+1) // Replace
});
};
int ans = fn(m, n, 0);
yn((ans<=k),1);
}
return 0;
}
/*
*/
Submission Info
| Submission Time |
|
| Task |
F - Operate K |
| User |
MArhamAA1422 |
| Language |
C++ 20 (Clang 16.0.6) |
| Score |
0 |
| Code Size |
4196 Byte |
| Status |
WA |
| Exec Time |
2218 ms |
| Memory |
170740 KiB |
Compile Error
./Main.cpp:5:13: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC optimize("O3,unroll-loops")
^
./Main.cpp:6:13: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
^
./Main.cpp:18:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1000000007;
^
3 warnings generated.
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 525 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt, small_05.txt, small_06.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand_01.txt |
TLE |
2216 ms |
161612 KiB |
| hand_02.txt |
AC |
1642 ms |
149304 KiB |
| hand_03.txt |
TLE |
2131 ms |
141488 KiB |
| hand_04.txt |
TLE |
2217 ms |
170740 KiB |
| sample_01.txt |
AC |
23 ms |
37912 KiB |
| sample_02.txt |
AC |
23 ms |
38096 KiB |
| sample_03.txt |
AC |
23 ms |
37988 KiB |
| small_01.txt |
AC |
23 ms |
37988 KiB |
| small_02.txt |
AC |
24 ms |
38032 KiB |
| small_03.txt |
AC |
23 ms |
37980 KiB |
| small_04.txt |
AC |
23 ms |
37932 KiB |
| small_05.txt |
AC |
23 ms |
38064 KiB |
| small_06.txt |
AC |
23 ms |
37908 KiB |
| test_01.txt |
AC |
23 ms |
38036 KiB |
| test_02.txt |
AC |
22 ms |
37976 KiB |
| test_03.txt |
AC |
22 ms |
37912 KiB |
| test_04.txt |
AC |
23 ms |
37912 KiB |
| test_05.txt |
AC |
23 ms |
38100 KiB |
| test_06.txt |
AC |
74 ms |
87784 KiB |
| test_07.txt |
AC |
74 ms |
87836 KiB |
| test_08.txt |
AC |
76 ms |
87780 KiB |
| test_09.txt |
AC |
74 ms |
87892 KiB |
| test_10.txt |
AC |
76 ms |
87892 KiB |
| test_11.txt |
AC |
38 ms |
44620 KiB |
| test_12.txt |
AC |
37 ms |
44424 KiB |
| test_13.txt |
AC |
29 ms |
40884 KiB |
| test_14.txt |
AC |
29 ms |
41308 KiB |
| test_15.txt |
TLE |
2215 ms |
141988 KiB |
| test_16.txt |
TLE |
2215 ms |
143024 KiB |
| test_17.txt |
TLE |
2215 ms |
164208 KiB |
| test_18.txt |
AC |
164 ms |
90000 KiB |
| test_19.txt |
TLE |
2216 ms |
160592 KiB |
| test_20.txt |
AC |
152 ms |
89072 KiB |
| test_21.txt |
TLE |
2213 ms |
118244 KiB |
| test_22.txt |
TLE |
2216 ms |
161568 KiB |
| test_23.txt |
TLE |
2214 ms |
131720 KiB |
| test_24.txt |
TLE |
2215 ms |
146176 KiB |
| test_25.txt |
TLE |
2216 ms |
158932 KiB |
| test_26.txt |
TLE |
2101 ms |
114836 KiB |
| test_27.txt |
AC |
76 ms |
87748 KiB |
| test_28.txt |
AC |
75 ms |
87796 KiB |
| test_29.txt |
AC |
75 ms |
87804 KiB |
| test_30.txt |
AC |
74 ms |
87784 KiB |
| test_31.txt |
AC |
37 ms |
44400 KiB |
| test_32.txt |
AC |
37 ms |
44512 KiB |
| test_33.txt |
AC |
74 ms |
87904 KiB |
| test_34.txt |
AC |
40 ms |
47296 KiB |
| test_35.txt |
AC |
44 ms |
47744 KiB |
| test_36.txt |
TLE |
2215 ms |
152316 KiB |
| test_37.txt |
TLE |
2213 ms |
108468 KiB |
| test_38.txt |
TLE |
2214 ms |
138756 KiB |
| test_39.txt |
TLE |
2218 ms |
145716 KiB |
| test_40.txt |
TLE |
2215 ms |
151448 KiB |
| test_41.txt |
AC |
1717 ms |
160508 KiB |
| test_42.txt |
TLE |
2073 ms |
158540 KiB |
| test_43.txt |
TLE |
2215 ms |
146176 KiB |
| test_44.txt |
WA |
586 ms |
116568 KiB |
| test_45.txt |
AC |
428 ms |
85248 KiB |
| test_46.txt |
WA |
1397 ms |
124776 KiB |
| test_47.txt |
TLE |
2215 ms |
138352 KiB |
| test_48.txt |
WA |
1318 ms |
104500 KiB |
| test_49.txt |
TLE |
2215 ms |
139580 KiB |
| test_50.txt |
TLE |
2215 ms |
139748 KiB |
| test_51.txt |
AC |
1221 ms |
100428 KiB |
| test_52.txt |
TLE |
2214 ms |
128320 KiB |
| test_53.txt |
TLE |
2216 ms |
159300 KiB |
| test_54.txt |
WA |
1692 ms |
94480 KiB |
| test_55.txt |
TLE |
2215 ms |
151432 KiB |
| test_56.txt |
TLE |
2216 ms |
157300 KiB |
| test_57.txt |
TLE |
2214 ms |
129324 KiB |
| test_58.txt |
WA |
1548 ms |
118752 KiB |
| test_59.txt |
TLE |
2215 ms |
101876 KiB |
| test_60.txt |
WA |
1354 ms |
107856 KiB |
| test_61.txt |
AC |
993 ms |
149468 KiB |
| test_62.txt |
TLE |
2215 ms |
160172 KiB |
| test_63.txt |
AC |
1296 ms |
106880 KiB |
| test_64.txt |
AC |
22 ms |
38008 KiB |
| test_65.txt |
AC |
22 ms |
37980 KiB |
| test_66.txt |
AC |
22 ms |
38044 KiB |
| test_67.txt |
AC |
22 ms |
38044 KiB |
| test_68.txt |
AC |
22 ms |
37980 KiB |
| test_69.txt |
AC |
23 ms |
37936 KiB |
| test_70.txt |
AC |
22 ms |
37888 KiB |