ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1575. Yekaterinburg Subway 2

good idea to avoid mistake
Posted by Celebrate 8 Oct 2021 04:45
I have some mistake in the staion name which I can't find it in my code.
Then I search all the string my write and calculate LCS.
The string has maximal LCS is what we want to find.
Like that:
int __(string ss){
  if(f.find(ss)==f.end()){
    int ans=0,pos=0;
    rep(ki,1,cnt){
      mst(dp,0);
      for(int i=1;i<=ss.length();i++){
        for(int j=1;j<=s[ki].length();j++){
          if(ss[i-1]==s[ki][j-1])dp[i][j]=dp[i-1][j-1]+1;
          else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
      }
      if(dp[ss.length()][s[ki].length()]>ans)ans=dp[ss.length()][s[ki].length()],pos=ki;
    }
    return pos;
  }
  return f[ss];
}

Then I got AC from wa2

Edited by author 08.10.2021 04:46