Submission #845430

#TimeUsernameProblemLanguageResultExecution timeMemory
845430vjudge1Trener (COCI20_trener)C++17
22 / 110
9 ms600 KiB
#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; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> distrib(10000,1000000007); const int B = distrib(gen); 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 hsh(string& s) { if (s.size()==1) return s.back(); char c = s.back(); s.pop_back(); return (add(mult(B,hsh(s)),c)); } void solve() { int n,k; cin >> n >> k; int fhash[n+1][k+1],phash[n+1][k+1],shash[n+1][k+1]; F(i,n) { F(j,k) { string s; cin >> s; string t,t2; for (int x=0;x<i;x++) { if(x) t2+=s[x]; if(x<i-1)t+=s[x]; } fhash[i][j] = hsh(s); if (i>1) { shash[i][j] = hsh(t2); phash[i][j] = hsh(t); } } } 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++) { if (phash[i+1][j2] == fhash[i][j] || shash[i+1][j2] == fhash[i][j]) { 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 (stderr)

trener.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize "DostSeferoğlu"
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...