Submission #653991

#TimeUsernameProblemLanguageResultExecution timeMemory
653991keitherrrrPalindrome-Free Numbers (BOI13_numbers)C++17
72.50 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define ll long long #define mp make_pair #define pb push_back #define pii pair <int, int> #define vi vector<int> #define FOR(i, a, b) for (int i=a; i<b; i++) #define FORd(i, a, b) for (int i=a-1; i>=b; i--) #define F0R(i, a) for (int i=0; i<a; i++) #define fi first #define se second #define be begin #define e end #define lb lower_bound #define ub upper_bound #define db long double #define mid ((r+l)>>1) #define tl (id<<1) #define tr (id<<1|1) const int N=20; vi v; int f[20][11][11][2], n; int dp(int i,int val,int oldval,bool tight){ if(i>=n) return 1; int &res=f[i][val][oldval][tight]; if(res!=-1) return res; res=0; int limit=(tight)?v[i]:9; for(int d=0;d<=limit;d++) if(d!=oldval&&d!=val){ res+= dp(i+1,d,val,tight&&d==limit); } return res; } int solve(string a){ v.clear(); memset(f,-1,sizeof(f)); FOR(i,0,a.size()) v.pb(a[i]-'0'); n=v.size(); return dp(0,10,10,1); } main(){ ios_base::sync_with_stdio(0);cin.tie(0); string a,b; cin >>a>>b; int ans=solve(b)-solve(a); bool g=0; FOR(i,2,a.size()) if(a[i]==a[i-2]||a[i]==a[i-1]) {g=1; break;} if(!g) ans++; cout<<ans; }

Compilation message (stderr)

numbers.cpp: In function 'long long int solve(std::string)':
numbers.cpp:12:53: 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]
   12 |                 #define FOR(i, a, b) for (int i=a; i<b; i++)
......
   44 |     FOR(i,0,a.size()) v.pb(a[i]-'0');
      |         ~~~~~~~~~~~~                                 
numbers.cpp:44:5: note: in expansion of macro 'FOR'
   44 |     FOR(i,0,a.size()) v.pb(a[i]-'0');
      |     ^~~
numbers.cpp: At global scope:
numbers.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      | ^~~~
numbers.cpp: In function 'int main()':
numbers.cpp:12:53: 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]
   12 |                 #define FOR(i, a, b) for (int i=a; i<b; i++)
......
   53 |     FOR(i,2,a.size()) if(a[i]==a[i-2]||a[i]==a[i-1]) {g=1; break;}
      |         ~~~~~~~~~~~~                                 
numbers.cpp:53:5: note: in expansion of macro 'FOR'
   53 |     FOR(i,2,a.size()) if(a[i]==a[i-2]||a[i]==a[i-1]) {g=1; break;}
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...