#include <bits/stdc++.h>
#pragma optimize "DostSeferoğlu"
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx2,tune=native")
using namespace std;
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define endl '\n'
#define vvi vector<vi>
#define pc __builtin_popcountll
#define vp vector<pii>
#define sp << " " <<
#define all(x) x.bg()+1,x.end()
#define ff first
#define ss second
#define brake {cout << "OK\n";return;}
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << endl;}
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define F(xx,yy) for (int xx=1;xx<=yy;++xx)
#define pb push_back
const int inf = 1e18;
const int MOD = 1e9+7;
const int N = 2e5+1;
const int A = 2131924;
const int B = 3215515;
const int C = 1631662;
int add(int x,int y) {
return ((x%MOD)+(y%MOD))%MOD;
}
int mult(int x,int y) {
return ((x%MOD)*(y%MOD))%MOD;
}
int hsha(string& s,int l,int r) {
int ret = 0;
for (int k=l;k<=r;k++) {
ret = add(mult(ret,A),s[k-1]);
}
return ret;
}
int hshb(string& s,int l,int r) {
int ret = 0;
for (int k=l;k<=r;k++) {
ret = add(mult(ret,B),s[k-1]);
}
return ret;
}
int hshc(string& s,int l,int r) {
int ret = 0;
for (int k=l;k<=r;k++) {
ret = add(mult(ret,C),s[k-1]);
}
return ret;
}
void solve() {
int n,k;
cin >> n >> k;
int fhasha[n+1][k+1],phasha[n+1][k+1],shasha[n+1][k+1];
int fhashb[n+1][k+1],phashb[n+1][k+1],shashb[n+1][k+1];
int fhashc[n+1][k+1],phashc[n+1][k+1],shashc[n+1][k+1];
F(i,n) {
F(j,k) {
string s;
cin >> s;
fhasha[i][j] = hsha(s,1,i);
fhashb[i][j] = hshb(s,1,i);
fhashc[i][j] = hshc(s,1,i);
if (i > 1) {
shasha[i][j] = hsha(s,2,i);
shashb[i][j] = hshb(s,2,i);
shashc[i][j] = hshc(s,2,i);
phasha[i][j] = hsha(s,1,i-1);
phashb[i][j] = hshb(s,1,i-1);
phashc[i][j] = hshc(s,1,i-1);
}
}
}
int ans[n+1][k+1];
memset(ans,0,sizeof ans);
F(i,k) ans[1][i] = 1;
for (int i=1;i<n;i++) {
for (int j=1;j<=k;j++) {
for (int j2=1;j2<=k;j2++) {
int th = fhasha[i][j];
int th2 = fhashb[i][j];
int th3 = fhashc[i][j];
int fl = (phasha[i+1][j2] == th && phashb[i+1][j2] == th2 && phashc[i+1][j2] == th3);
int fl2 = (shasha[i+1][j2] == th && shashb[i+1][j2] == th2 && shashc[i+1][j2] == th3);
if (fl || fl2) {
ans[i+1][j2]=add(ans[i+1][j2],ans[i][j]);
}
}
}
}
int sm = 0;
F(i,k) {
sm = add(sm,ans[n][i]);
}
cout << sm << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef Local
freopen("input.in", "r", stdin);
freopen("input.out", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message
trener.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize "DostSeferoğlu"
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
604 KB |
Output is correct |
2 |
Correct |
18 ms |
860 KB |
Output is correct |
3 |
Correct |
18 ms |
860 KB |
Output is correct |
4 |
Correct |
20 ms |
604 KB |
Output is correct |
5 |
Correct |
17 ms |
604 KB |
Output is correct |
6 |
Correct |
17 ms |
1112 KB |
Output is correct |
7 |
Correct |
18 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
18 ms |
604 KB |
Output is correct |
6 |
Correct |
18 ms |
860 KB |
Output is correct |
7 |
Correct |
18 ms |
860 KB |
Output is correct |
8 |
Correct |
20 ms |
604 KB |
Output is correct |
9 |
Correct |
17 ms |
604 KB |
Output is correct |
10 |
Correct |
17 ms |
1112 KB |
Output is correct |
11 |
Correct |
18 ms |
604 KB |
Output is correct |
12 |
Correct |
299 ms |
6336 KB |
Output is correct |
13 |
Correct |
302 ms |
6332 KB |
Output is correct |
14 |
Correct |
306 ms |
6332 KB |
Output is correct |
15 |
Correct |
300 ms |
6224 KB |
Output is correct |
16 |
Correct |
696 ms |
6424 KB |
Output is correct |
17 |
Correct |
312 ms |
6416 KB |
Output is correct |
18 |
Correct |
310 ms |
6332 KB |
Output is correct |
19 |
Correct |
327 ms |
6228 KB |
Output is correct |
20 |
Correct |
324 ms |
6332 KB |
Output is correct |
21 |
Correct |
322 ms |
6336 KB |
Output is correct |
22 |
Correct |
694 ms |
6428 KB |
Output is correct |