Submission #314668

#TimeUsernameProblemLanguageResultExecution timeMemory
314668ronnithIspit (COCI19_ispit)C++14
72 / 90
2066 ms54392 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define int long long #define num(a) a-'0' #define charr(a) (a - 'A' + 1) #define rep(i,a,b) for(int i=a;i<b;i++) #define maxs(a,b) if(b>a)a=b #define mins(a,b) if(b<a)a=b #define bin1(a) __builtin_popcount(a) #define debug(x) cerr<<"["<<#x<<":"<<x<<"] " #define debug2(a,b) debug(a);debug(b) #define debug3(a,b,c) debug2(a,b);debug(c) #define de cerr #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/(__gcd(a,b)) #define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(a) (a).begin(), (a).end() #define vi vector<long long> #define v vector #define p pair #define pii p<int,int> #define pb push_back #define mk make_pair #define f first #define s second #define ln "\n" typedef long double ld; typedef double d; using namespace std; using namespace __gnu_pbds; int modF=1e9+7; /*OUTPUT */ void solve(){ int n,k; cin >> n >> k; v<v<char>> a(n,v<char>(n)); for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ cin >> a[i][j]; } } v<v<vi>> pre(26,v<vi>(n,vi(n))); for(int ch = 0;ch < 26;ch ++) for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ char chr = (char)(ch + 97); if(a[i][j] == chr) pre[ch][i][j] = 1; else pre[ch][i][j] = 0; if(j != 0){ pre[ch][i][j] += pre[ch][i][j - 1]; } } } // v<v<bool>> pre(n,v<bool>(n)); // v<v<bool>> suff(n,v<bool>(n)); // for(int i = 0;i < n;i ++){ // for(int j = 0;j < n;j ++){ // } // } for(int j = 0;j < n;j ++){ for(int l = j + 1;l < n;l ++){ v<bool> h(n); v<bool> h2(n); for(int i = 0;i < n;i ++){ bool fl = true; if(i != 0) fl = h[i - 1]; if(a[j][i] == a[l][i] and fl){ h[i] = true; } } for(int i = n - 1;i >= 0;i --){ bool fl = true; if(i != n - 1) fl = h2[i + 1]; if(a[j][i] == a[l][i] and fl){ h2[i] = true; } } for(int i = 0;i <= n - k;i ++){ bool pos = true; // for(int it = 0;it < i;it ++){ // if(a[j][it] != a[l][it]){ // pos = false; // } // } if(i != 0 and h[i - 1] == false)pos = false; if(i + k != n and h2[i + k] == false)pos = false; for(int it = i + k;it < n;it ++){ if(a[j][it] != a[l][it]){ pos = false; } } for(int ch = 0;ch < 26;ch ++){ int h1 = pre[ch][j][i + k - 1]; if(i - 1 >= 0){ h1 -= pre[ch][j][i - 1]; } int h2 = pre[ch][l][i + k - 1]; if(i - 1 >= 0) h2 -= pre[ch][l][i - 1]; if(h1 != h2)pos = false; } if(pos){ cout << "DA\n"; return; } } } } cout << "NE\n"; } signed main(){ boost_io; int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#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...