답안 #523245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523245 2022-02-07T09:13:51 Z levsog2004 원형 문자열 (IZhO13_rowords) C++14
0 / 100
26 ms 21776 KB
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int 
#define forr(n) for(ll i=0;i<n;i++) 
#define um unordered_map<int,int>  
#define vec vector<int> 
#define vecl vector<ll> 
#define pb push_back 
#define bg begin()
#define en end()
   
 
void solve(){
   
 string s,t;
  cin>>s>>t;
  int tt=s.size();
  for(int i=0;i<tt;++i)
  {
    s.push_back(s[i]);
  }
   tt=t.size();
  for(int i=0;i<tt;++i)
  {
    t.push_back(t[i]);
  }
  int dp[s.size()+1][t.size()+1] ; 
  
  memset(dp,0,sizeof(dp)) ; 
  for(int i=1;i<=s.size();i++){
       for(int j=1;j<=t.size();j++){
           if(s[i-1]==t[j-1]) 
             dp[i][j]=1+dp[i-1][j-1] ;
             else
             dp[i][j] = max(dp[i-1][j],dp[i][j-1]) ;
       }
  } 
  string ans;
   int i=s.size(),j=t.size();
   while(i>0 && j>0){
       if(s[i-1]==t[j-1])
       {
           ans+=s[i-1];
           i--;j--;
       }
       else{
           if(dp[i-1][j] > dp[i][j-1]) 
             i--;
             else
             j--;
       }
   } 
   reverse(ans.bg,ans.en);
   cout<<ans<<" ";
  
 
   
   
   
      
   
 
}
 
int main(){ 
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    
    return 0;
}

Compilation message

rowords.cpp: In function 'void solve()':
rowords.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i=1;i<=s.size();i++){
      |               ~^~~~~~~~~~
rowords.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |        for(int j=1;j<=t.size();j++){
      |                    ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Incorrect 2 ms 1868 KB Output isn't correct
7 Incorrect 22 ms 15884 KB Output isn't correct
8 Incorrect 15 ms 15904 KB Output isn't correct
9 Incorrect 16 ms 15948 KB Output isn't correct
10 Incorrect 18 ms 15948 KB Output isn't correct
11 Incorrect 25 ms 17536 KB Output isn't correct
12 Incorrect 17 ms 20428 KB Output isn't correct
13 Incorrect 22 ms 20444 KB Output isn't correct
14 Incorrect 21 ms 18252 KB Output isn't correct
15 Incorrect 26 ms 21776 KB Output isn't correct
16 Incorrect 16 ms 17484 KB Output isn't correct
17 Incorrect 16 ms 13268 KB Output isn't correct
18 Incorrect 25 ms 20684 KB Output isn't correct
19 Incorrect 24 ms 15916 KB Output isn't correct
20 Incorrect 24 ms 18508 KB Output isn't correct
21 Incorrect 5 ms 4300 KB Output isn't correct
22 Incorrect 8 ms 7372 KB Output isn't correct
23 Incorrect 12 ms 10188 KB Output isn't correct
24 Incorrect 13 ms 10664 KB Output isn't correct
25 Incorrect 17 ms 14428 KB Output isn't correct