Submission #523248

#TimeUsernameProblemLanguageResultExecution timeMemory
523248levsog2004Round words (IZhO13_rowords)C++14
0 / 100
36 ms32364 KiB
#include <iostream> #include <iomanip> #include <fstream> #include <algorithm> #include <cstring> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <cmath> #include <list> #include <set> #include <map> 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[2005][2005]; 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 (stderr)

rowords.cpp: In function 'void solve()':
rowords.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 1; i <= s.size(); i++) {
      |                     ~~^~~~~~~~~~~
rowords.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int j = 1; j <= t.size(); j++) {
      |                         ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...