Submission #1120865

#TimeUsernameProblemLanguageResultExecution timeMemory
1120865vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
28.33 / 100
1087 ms512 KiB
#include <bits/stdc++.h>
using namespace std;
# define int long long
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(int n)
{
  string s = to_string(n);
  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];
      if(pol(sc)){
        return 1;
      }
    }
  }
  return 0;
}

void solve()
{
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int a, b, cnt = 0;
  scanf("%lld%lld", &a, &b);
  for(int i = a; i <= b; i++)
  {
    if(ok(i))
    {
      cnt++;
      continue ;
    }
  }
  cout << (b - a + 1) - cnt << endl;
}

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: 'long long 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(long long int)':
numbers.cpp:18:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for(int i = 0; i < s.size() - 1; i++)
      |                  ~~^~~~~~~~~~~~~~
numbers.cpp:20:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int j = i + 1; j < s.size(); j++)
      |                        ~~^~~~~~~~~~
numbers.cpp: In function 'void solve()':
numbers.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%lld%lld", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...