Submission #992285

#TimeUsernameProblemLanguageResultExecution timeMemory
992285todorokishotoua1Necklace (Subtask 4) (BOI19_necklace4)C++17
0 / 15
30 ms65536 KiB
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // #pragma GCC optimize("O3,unroll-loops") #include<bits/stdc++.h> using namespace std; #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; // typedef tree< // int, // null_type, // less_equal<int>, // rb_tree_tag, // tree_order_statistics_node_update // > // ordered_set; namespace __gnu_pbds{ typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; } using namespace __gnu_pbds; #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; void __print32_t(int32_t x) {cerr << x;} void __print32_t(long x) {cerr << x;} void __print32_t(long long x) {cerr << x;} void __print32_t(unsigned x) {cerr << x;} void __print32_t(unsigned long x) {cerr << x;} void __print32_t(unsigned long long x) {cerr << x;} void __print32_t(float x) {cerr << x;} void __print32_t(double x) {cerr << x;} void __print32_t(long double x) {cerr << x;} void __print32_t(char x) {cerr << '\'' << x << '\'';} void __print32_t(const char *x) {cerr << '\"' << x << '\"';} void __print32_t(const string &x) {cerr << '\"' << x << '\"';} void __print32_t(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print32_t(const pair<T, V> &x) {cerr << '{'; __print32_t(x.first); cerr << ','; __print32_t(x.second); cerr << '}';} template<typename T> void __print32_t(const T &x) {int32_t f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print32_t(i); cerr << "}";} void _print32_t() {cerr << "]\n";} template <typename T, typename... V> void _print32_t(T t, V... v) {__print32_t(t); if (sizeof...(v)) cerr << ", "; _print32_t(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print32_t(x) #else #define debug(x...) #endif template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; #define rep(i,a,b) for(int32_t i = a; i < b; i ++) #define ill long long int32_t #define ll long long #define int int64_t #define nl "\n" #define el endl #define pb push_back #define FOR(a,b,c) for (int32_t a = b; a < c; a++) using namespace std; // const int32_t N = 3e5+1; const ll neg_inf = -2e7 + 2; const ll inf = 1e18 + 1; // const int32_t mod = 998244353; // const int32_t MOD = 1e9+7; const int32_t MAXN = 4e6+1; const int32_t eps = 1e-6; const int N = 2e5+1; array<int,3> solve (string s, string t) { string fin = s; fin += '#'; fin += t; int n = fin.size(); vector<vector<int>> d1(s.size(),vector<int>(t.size(),0)); for (int l = 0; l < s.size(); l++) { vector<int> pi(n,0); for (int i = 1; i < fin.size(); i++) { int j = pi[i-1]; while (j > 0 && fin[j]!=fin[i]) j=pi[j-1]; pi[i] = j+(fin[i]==fin[j]); } for (int i = s.size()+1; i < n; i++) { d1[l][i-s.size()-1] = pi[i-l]; } // debug(l,pi,fin); fin.erase(fin.begin()); } // debug(d1); string fin2 = t; fin2 += '#'; fin2 += s; n = fin2.size(); vector<vector<int>> d2(s.size(),vector<int>(t.size(),0)); for (int l = 0; l < t.size(); l++) { vector<int> pi(n,0); for (int i = 1; i < fin2.size(); i++) { int j = pi[i-1]; while (j > 0 && fin2[i]!=fin2[j]) j=pi[j-1]; pi[i] = (j)+(fin2[i]==fin2[j]); } for (int i = t.size()+1; i < n; i++) { d2[i-t.size()-1][l] = pi[i-l]; } // debug(l,pi,fin2); fin2.erase(fin2.begin()); } // debug(d2); int ans = 0; int st1 = 0, st2 = 0; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < t.size(); j++) { int currans = d1[i][j]; if (i-1 >= 0 && j+1 < t.size()) { currans += d2[i-1][j+1]; } if (currans > ans) { ans = currans; int torem1 = i; int torem2 = j+1-d1[i][j]; if (i-1 >= 0 && j+1 < t.size()) { torem1 -= d2[i-1][j+1]; } st1 = torem1; st2 = torem2; } } } return {ans,st1,st2}; } ll runcases() { string s,t; cin >> s >> t; // debug(s,t); auto ans1 = solve(s,t); // debug(s,t,ans1); reverse(t.begin(),t.end()); auto ans2 = solve(s,t); // debug(ans2); if (ans1[0] > ans2[0]) { cout << ans1[0] << nl << ans1[1] << " " << ans1[2]; } else { cout << ans2[0] << nl << ans2[1] << " " << t.size()-(ans2[0]+ans2[2]); } return 0; } signed main() { //..........Fast I/O.........// // ios_base::sync_with_stdio(false); // cin.tie(0);cout.tie(0); //..........................// ll t ; t = 1; // debug(t); for (int32_t i = 1; i <= t; i ++) { runcases(); } return 0; }

Compilation message (stderr)

necklace.cpp: In function 'std::array<long int, 3> solve(std::string, std::string)':
necklace.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for (int l = 0; l < s.size(); l++) {
      |                     ~~^~~~~~~~~~
necklace.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for (int i = 1; i < fin.size(); i++) {
      |                         ~~^~~~~~~~~~~~
necklace.cpp:110:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for (int l = 0; l < t.size(); l++) {
      |                     ~~^~~~~~~~~~
necklace.cpp:112:27: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         for (int i = 1; i < fin2.size(); i++) {
      |                         ~~^~~~~~~~~~~~~
necklace.cpp:129:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
necklace.cpp:130:27: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |         for (int j = 0; j < t.size(); j++) {
      |                         ~~^~~~~~~~~~
necklace.cpp:132:33: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |             if (i-1 >= 0 && j+1 < t.size()) {
      |                             ~~~~^~~~~~~~~~
necklace.cpp:139:37: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |                 if (i-1 >= 0 && j+1 < t.size()) {
      |                                 ~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...