Submission #232481

#TimeUsernameProblemLanguageResultExecution timeMemory
232481kartelIspit (COCI19_ispit)C++14
90 / 90
66 ms6728 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define N +2005 //#define N1 +1001000 #define M ll(998244353) #define sz(x) (int)x.size() #define re return #define oo ll(1e18) #define el '\n' using namespace std; //using namespace __gnu_pbds; //typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef long double ld; int i, j, k, n, hp[N][N], hs[N][N], p[N], can, hsh; string s[N]; map <int, int> mp; int sum(int x, int y) {return (x + y) % M;} int mult(int x, int y) {return (x * 1ll * y) % M;} int main() { srand(time(0)); ios_base::sync_with_stdio(0); iostream::sync_with_stdio(0); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // in("input.txt"); // out("output.txt"); // getline(cin, st); cin >> n >> k; p[0] = 1; for (i = 1; i <= n; i++) p[i] = mult(p[i - 1], 31); for (i = 1; i <= n; i++) { cin >> s[i]; s[i] = " " + s[i]; hp[i][0] = 0; for (j = 1; j <= n; j++) hp[i][j] = sum(hp[i][j - 1], mult(s[i][j] - 'a' + 1, p[j - 1])); hs[i][n + 1] = 0; for (j = n; j >= 1; j--) hs[i][j] = sum(mult(hs[i][j + 1], 31), s[i][j] - 'a' + 1); } for (j = 1; j <= n - k + 1; j++) { bool found = 0; mp.clear(); for (i = 1; i <= n; i++) { hsh = hp[i][j - 1]; hsh = sum(hsh, mult(hs[i][j + k], p[j - 1])); mp[hsh]++; if (mp[hsh] >= 2) found = 1; } if (!found) continue; mp.clear(); for (i = 1; i <= n; i++) { string ns = ""; for (int nj = j; nj <= j + k - 1; nj++) ns += s[i][nj]; sort(ns.begin(), ns.end()); hsh = 0; for (int nj = 0; nj < k; nj++) hsh = sum(hsh, mult(ns[nj] - 'a' + 1, p[nj])); mp[hsh]++; if (mp[hsh] > 1) can = 1; } } cout << (can ? "DA" : "NE"); } //3 - 4 //4 - 5 //y < z + x < y + 2 * x
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...