# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572234 |
2022-06-04T03:04:20 Z |
AGE |
Ispit (COCI19_ispit) |
C++14 |
|
956 ms |
60404 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=1e16+31,ppp=31;
int hashh[505][505],cnt[505][505][27],ans[505][505],hashh2[505][505];
string s[505];
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));
}
}
void compute_hash3(string s,int index){
const int pp=31;
int p_pow=1;
hashh2[index][s.size()-1]=(s[s.size()-1]-'a')+1;
for(int i=s.size()-2;i>=0;i--){
p_pow=mult(p_pow,pp);
hashh2[index][i]=summ(hashh2[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;i++){
for(int j=0;j<n;j++){
for(int k=i;k<min(n,i+m);k++){
cnt[i][j][s[j][k]-'a']++;
}
}
}
for(int i=0;i<n;i++){
compute_hash(s[i],i);
compute_hash3(s[i],i);
}
for(int i=0;i<n-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%mod;
}
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])&&(hashh2[j][i+m]==hashh2[k][i+m])&&(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:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
68 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
12020 KB |
Output is correct |
2 |
Correct |
29 ms |
11240 KB |
Output is correct |
3 |
Correct |
50 ms |
12036 KB |
Output is correct |
4 |
Correct |
38 ms |
11584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
11956 KB |
Output is correct |
2 |
Correct |
25 ms |
11244 KB |
Output is correct |
3 |
Correct |
62 ms |
12016 KB |
Output is correct |
4 |
Correct |
21 ms |
11220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
11916 KB |
Output is correct |
2 |
Correct |
22 ms |
11220 KB |
Output is correct |
3 |
Correct |
63 ms |
11988 KB |
Output is correct |
4 |
Correct |
21 ms |
11212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
11980 KB |
Output is correct |
2 |
Correct |
23 ms |
11220 KB |
Output is correct |
3 |
Correct |
55 ms |
11980 KB |
Output is correct |
4 |
Correct |
29 ms |
11348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
956 ms |
60300 KB |
Output is correct |
2 |
Correct |
295 ms |
58316 KB |
Output is correct |
3 |
Correct |
893 ms |
60404 KB |
Output is correct |
4 |
Correct |
288 ms |
58388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
946 ms |
60256 KB |
Output is correct |
2 |
Correct |
273 ms |
58368 KB |
Output is correct |
3 |
Correct |
410 ms |
60384 KB |
Output is correct |
4 |
Correct |
180 ms |
58740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
937 ms |
60336 KB |
Output is correct |
2 |
Correct |
306 ms |
58400 KB |
Output is correct |
3 |
Correct |
796 ms |
60288 KB |
Output is correct |
4 |
Correct |
265 ms |
58404 KB |
Output is correct |