Submission #643945

#TimeUsernameProblemLanguageResultExecution timeMemory
643945mychecksedadNecklace (Subtask 1-3) (BOI19_necklace1)C++17
25 / 85
1581 ms320 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " is " << x << '\n'; const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20; int n, m; string a, b; bool is_equal(string x, string y){ for(int c = 0; c < x.length(); ++c){ bool o = 1; for(int i = 0; i < x.length(); ++i){ if(x[i] != y[(i+c)%int(x.length())]){ o = 0; break; } } if(o){ return o; } } reverse(all(y)); for(int c = 0; c < x.length(); ++c){ bool o = 1; for(int i = 0; i < x.length(); ++i){ if(x[i] != y[(i+c)%int(x.length())]){ o = 0; break; } } if(o){ return o; } } return 0; } void solve(){ cin >> a >> b; n = a.length(); m = b.length(); int len = 0, i1 = 0, i2 = 0; for(int i = 0; i < n; ++i){ for(int j = i; j < n; ++j){ int l = j - i; for(int k = 0; k < m - l; ++k){ if(is_equal(a.substr(i, l + 1), b.substr(k, l + 1))){ if(len<l+1){ len=l+1, i1=i, i2=k; } } } } } cout << len << '\n' << i1 << ' ' << i2 ; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

necklace.cpp: In function 'bool is_equal(std::string, std::string)':
necklace.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int c = 0; c < x.length(); ++c){
      |                    ~~^~~~~~~~~~~~
necklace.cpp:23:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int i = 0; i < x.length(); ++i){
      |                        ~~^~~~~~~~~~~~
necklace.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int c = 0; c < x.length(); ++c){
      |                    ~~^~~~~~~~~~~~
necklace.cpp:38:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int i = 0; i < x.length(); ++i){
      |                        ~~^~~~~~~~~~~~
necklace.cpp: In function 'int main()':
necklace.cpp:78:16: warning: unused variable 'aa' [-Wunused-variable]
   78 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...