Submission #1120569

#TimeUsernameProblemLanguageResultExecution timeMemory
1120569vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
24.17 / 100
1071 ms508 KiB
#include <bits/stdc++.h>
using namespace std;

bool pol(string s)
{
  for(int i = 0; i < s.size() / 2; i++)
  {
    if(s[i] != s[s.size() - i - 1])
      return false;
  }
  return true;
}

bool ok(string s)
{
  string scc;
  for(int i = 0; i < s.size() - 1; i++)
  {
    for(int j = i + 1; j < s.size(); j++)
    {
      string sc = "";
      for(int z = i; z <= j; z++) 
        sc += s[z];
      scc = sc;
      reverse(scc.begin(), scc.end());
      if(sc == scc){
        return 1;
      }
    }
  }
  return 0;
}

void solve()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s, sc;
  int a, b, cnt = 0, k;
  cin >> a >> b;
  int N = b - a + 1;
  for(int i = a; i <= b; i++)
  {
    s = to_string(i);
    if(pol(s) && s.size() != 1)
    {
      N--;
      continue ;
    }
    else if(ok(s))
    {
      N--;
    }
  }
  cout << N;
}

signed main()
{
  int tt = 1;
  // cin >> tt;
  while(tt--)
    solve();
}

Compilation message (stderr)

numbers.cpp: In function 'bool pol(std::string)':
numbers.cpp:6:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |   for(int i = 0; i < s.size() / 2; i++)
      |                  ~~^~~~~~~~~~~~~~
numbers.cpp: In function 'bool ok(std::string)':
numbers.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for(int i = 0; i < s.size() - 1; i++)
      |                  ~~^~~~~~~~~~~~~~
numbers.cpp:19:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int j = i + 1; j < s.size(); j++)
      |                        ~~^~~~~~~~~~
numbers.cpp: In function 'void solve()':
numbers.cpp:40:13: warning: unused variable 'cnt' [-Wunused-variable]
   40 |   int a, b, cnt = 0, k;
      |             ^~~
numbers.cpp:40:22: warning: unused variable 'k' [-Wunused-variable]
   40 |   int a, b, cnt = 0, k;
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...