# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
570608 |
2022-05-30T17:02:50 Z |
AGE |
Ispit (COCI19_ispit) |
C++14 |
|
486 ms |
65536 KB |
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7,ppp=31;
int hashh[505][505],cnt[505][505][27],sorted[505][505],ans[505][505];
string s[N];
int mult(int x,int y){
return ((x%mod)*(y%mod))%mod;
}
int minuss(int x,int y){
return ((x%mod)-(y%mod)+mod)%mod;
}
int summ(int x,int y){
return((x%mod)+(y%mod))%mod;
}
void compute_hash(string s,int index){
const int pp=31;
int p_pow=1;
hashh[index][0]=s[0]-'a'+1;
for(int i=1;i<s.size();i++){
p_pow=mult(p_pow,pp);
hashh[index][i]=summ(hashh[index][i-1],mult(s[i]-'a'+1,p_pow));
}
}
pair<int,int> compute_hash2(int start,int num,int anss,int intial){
for(int i=0;i<num;i++){
start=mult(start,ppp);
anss=summ(anss,mult(intial,start));
}
return {anss,start};
}
main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<=n-m+1;i++){
for(int j=0;j<n;j++){
for(int k=i;k<i+m;k++){
cnt[i][j][s[j][k]-'a']++;
}
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<26;k++)
cout<<i<<" "<<j<<" "<<k+'a'<<" "<<cnt[i][j][k]<<endl;
}
}*/
for(int i=0;i<n;i++){
compute_hash(s[i],i);
}
for(int i=0;i<=n-m+1;i++){
for(int k=0;k<n;k++){
int anss=0,start=1;
for(int j=0;j<26;j++){
pair<int,int> p;
p=compute_hash2(start,cnt[i][k][j],anss,j+1);
anss=p.F;
start=p.S;
}
ans[i][k]=anss;
}
for(int j=0;j<n;j++){
for(int k=j+1;k<n;k++){
if((i==0||hashh[j][i-1]==hashh[k][i-1])&&(hashh[j][n-1]-hashh[j][i+m-1]==hashh[j][n-1]-hashh[j][i+m-1])&&(ans[i][j]==ans[i][k])){
cout<<"DA"<<endl;
exit(0);
}
}
}
}
cout<<"NE"<<endl;
return 0;
}
/*
4 2
abcd
acbd
unee
asds
*/
Compilation message
ispit.cpp: In function 'void compute_hash(std::string, long long int)':
ispit.cpp:36:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
ispit.cpp: At global scope:
ispit.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main()
| ^~~~
ispit.cpp: In function 'int main()':
ispit.cpp:105:88: warning: self-comparison always evaluates to true [-Wtautological-compare]
105 | if((i==0||hashh[j][i-1]==hashh[k][i-1])&&(hashh[j][n-1]-hashh[j][i+m-1]==hashh[j][n-1]-hashh[j][i+m-1])&&(ans[i][j]==ans[i][k])){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31676 KB |
Output is correct |
2 |
Correct |
16 ms |
31704 KB |
Output is correct |
3 |
Incorrect |
16 ms |
31624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31720 KB |
Output is correct |
2 |
Correct |
18 ms |
31672 KB |
Output is correct |
3 |
Correct |
17 ms |
31624 KB |
Output is correct |
4 |
Correct |
16 ms |
31684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
31696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
32892 KB |
Output is correct |
2 |
Correct |
28 ms |
33432 KB |
Output is correct |
3 |
Correct |
49 ms |
38604 KB |
Output is correct |
4 |
Correct |
30 ms |
38160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
32616 KB |
Output is correct |
2 |
Correct |
24 ms |
33320 KB |
Output is correct |
3 |
Correct |
51 ms |
36552 KB |
Output is correct |
4 |
Correct |
31 ms |
36244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
32976 KB |
Output is correct |
2 |
Correct |
21 ms |
32756 KB |
Output is correct |
3 |
Correct |
44 ms |
35076 KB |
Output is correct |
4 |
Correct |
26 ms |
34900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
32724 KB |
Output is correct |
2 |
Correct |
21 ms |
33048 KB |
Output is correct |
3 |
Correct |
49 ms |
37644 KB |
Output is correct |
4 |
Correct |
40 ms |
37332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
35416 KB |
Output is correct |
2 |
Correct |
74 ms |
36272 KB |
Output is correct |
3 |
Correct |
187 ms |
40036 KB |
Output is correct |
4 |
Correct |
75 ms |
39760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
35380 KB |
Output is correct |
2 |
Correct |
38 ms |
34752 KB |
Output is correct |
3 |
Runtime error |
96 ms |
65536 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
35056 KB |
Output is correct |
2 |
Correct |
80 ms |
36504 KB |
Output is correct |
3 |
Correct |
486 ms |
56628 KB |
Output is correct |
4 |
Correct |
153 ms |
55768 KB |
Output is correct |