| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 445089 | Tahmid690 | Trener (COCI20_trener) | C++14 | 1302 ms | 34180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29]
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef map<int,int> mpi;
typedef map<ll,ll> mpl;
typedef unordered_map<int,int> umpi;
typedef unordered_map<ll,ll> umpl;
#define ump unordered_map
#define mod 1000000007
#define inf 1000000000000000006
#define infi 1000000009
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define pi acos(-1.0)
#define dec(n) fixed << setprecision(n)
#define N 200005
//#define int long long
struct ss{
ll hash[55];
};
ll bigmod(ll a,ll b){
if(b==0) return 1;
ll ret=bigmod(a,b/2);
ret*=ret;
ret%=mod;
if(b%2==1) ret*=a;
return ret%mod;
}
vector<ss> v[55];
string s;
int n,k;
ll dp[1505][55],inv;
ll DP(int p,int x){
if(x==n) return 1;
if(dp[p][x]!=-1) return dp[p][x];
ll ret=0;
for(int i=0;i<k;i++){
if(v[x][i].hash[x]==v[x-1][p].hash[x] || ((((v[x][i].hash[x+1]-v[x][i].hash[1])*inv)+mod)%mod)==v[x-1][p].hash[x]) ret+=DP(i,x+1);
ret%=mod;
}
return dp[p][x]=ret;
}
void solve(){
cin >> n >> k;
for(int i=0;i<n;i++){
v[i].resize(k);
for(int j=0;j<k;j++){
cin >> s;
ss tmp;
ll p=31,hashval=0,pw=1;
for(int k=0;k<s.size();k++){
hashval=(hashval+(s[k]-'a'+1)*pw)%mod;
pw=(pw*p)%mod;
tmp.hash[k+1]=hashval;
}
v[i][j]=tmp;
}
}
inv=bigmod(31,mod-2);
memset(dp,-1,sizeof dp);
ll ans=0;
for(int i=0;i<k;i++){
ans+=DP(i,1);
ans%=mod;
}
cout << ans << endl;
}
signed main(){
fastio;
//srand(chrono::steady_clock::now().time_since_epoch().count());
int T=1,cs=0;
//cin >> T;
while(T--){
//cout << "Case " << ++cs << ":" << " " ;
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
