Submission #1084608

#TimeUsernameProblemLanguageResultExecution timeMemory
1084608lamlamlamRima (COCI17_rima)C++17
28 / 140
1103 ms132984 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int MN = 5e5+5,mod0 = 1e9+7,mod1 = 1e9+9,base0 = 331,base1 = 293,base2 = 269; struct HASH { int Hash[3] = {0,0,0}; bool operator < (const HASH &o) const { if(Hash[0]!=o.Hash[0]) return Hash[0] < o.Hash[0]; if(Hash[1]!=o.Hash[1]) return Hash[1] < o.Hash[1]; if(Hash[2]!=o.Hash[2]) return Hash[2] < o.Hash[2]; return false; } HASH operator + (const char o) const { HASH res; res.Hash[0] = (Hash[0]*base0 + o)%mod0; res.Hash[1] = (Hash[1]*base1 + o)%mod1; res.Hash[2] = Hash[2]*base2 + o; return res; } }; int n,dp[MN]; vector<int> v; string s[MN],a[MN]; map<HASH,int> best,cnt; bool cmp(int x,int y) { return s[x].size() < s[y].size(); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #define task "COCI17_rima" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n; for(int i=1; i<=n; i++) cin >> s[i],v.push_back(i); sort(v.begin(),v.end(),cmp); int ans = 1; for(int i=1; i<=n; i++) { dp[i] = 1; a[i] = s[v[i-1]]; HASH hash_string[2]; for(int j=a[i].size()-1; j>0; j--) hash_string[1] = hash_string[1] + a[i][j]; hash_string[0] = hash_string[1] + a[i][0]; //cout << hash_string[0].Hash[1] << ' ' << hash_string[1].Hash[1] << ' ' << a[i] << endl; if(cnt[hash_string[0]]) dp[i] = max(dp[i],1 + best[hash_string[0]]); if(cnt[hash_string[1]]) dp[i] = max(dp[i],1 + best[hash_string[1]]); //cout << endl; best[hash_string[0]] = max(best[hash_string[0]],dp[i]); best[hash_string[1]] = max(best[hash_string[1]],dp[i]); cnt[hash_string[0]]++; cnt[hash_string[1]]++; ans = max(ans,dp[i]); } //for(int i=1; i<=n; i++) cout << dp[i] << ' '; cout << ans; cerr << "\nTime: " << clock() << endl; }

Compilation message (stderr)

rima.cpp: In function 'int main()':
rima.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
rima.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...