Submission #1120757

#TimeUsernameProblemLanguageResultExecution timeMemory
1120757vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
20.83 / 100
1084 ms512 KiB
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
const ll INF =1e18, mod = 1e9 + 7, N = 1e5 + 5;
bool check(const string &s){
    for(int i = 0; i < s.size() / 2; i++){
        if(s[i] != s[s.size() - i - 1]){
            return false;
        }
    }
    return true;
}
bool free(ll n){
    string s = to_string(n);
    for(int i = 2; i <=s.size(); i++){
        for(int j = 0; j + i <= s.size(); j++){
            if(check(s.substr(j,i))){
                return false;
            }
        }
    }
    return true;
}
void solve(){
    ll a,b;
    cin >> a >> b;
    ll cnt = 0;
    for(ll i = a; i <= b; i++){
        string w = to_string(i);
        if(w.size() == 1){
            continue;
        }
        if(w.size() == 2){
            if(w[0] != w[1]){
                cnt++;
            }
            continue;
        }
        if(free(i)){
            cnt++;
        }
    }
    cout << cnt << endl;
}
int main(){
    fast;
    solve();
    return 0;
}

Compilation message (stderr)

numbers.cpp: In function 'bool check(const string&)':
numbers.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < s.size() / 2; i++){
      |                    ~~^~~~~~~~~~~~~~
numbers.cpp: In function 'bool free(long long int)':
numbers.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 2; i <=s.size(); i++){
      |                    ~~^~~~~~~~~~
numbers.cpp:25:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j = 0; j + i <= s.size(); j++){
      |                        ~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...