Submission #1082829

#TimeUsernameProblemLanguageResultExecution timeMemory
1082829lamlamlamPalindrome-Free Numbers (BOI13_numbers)C++17
72.50 / 100
1 ms456 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' int a,b,dp[20][2][11][11][2],n; string s; int f(int pos,int tight,int prev1,int prev2,int started) { if(pos==n) return started; if(dp[pos][tight][prev1][prev2][started]!=-1) return dp[pos][tight][prev1][prev2][started]; int res = 0, ub = 9; if(tight) ub = s[pos] - '0'; for(int i=0; i<=ub; i++){ if(i==prev1 or i==prev2) continue; int is_tight = (tight && i==ub); int has_started = (started or i!=0); res += f(pos+1,is_tight,i,prev1,has_started); } return dp[pos][tight][prev1][prev2][started] = res; } int sol(int x) { for(int i=0; i<20; i++) for(int j=0; j<11; j++) for(int k=0; k<11; k++) dp[i][0][j][k][0] = dp[i][0][j][k][1] = dp[i][1][j][k][0] = dp[i][1][j][k][1] = -1; s = to_string(x); n = s.size(); return f(0,1,10,10,0); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #define task "troll" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> a >> b; cout << sol(b) - sol(a-1); cerr << "\nTime: " << clock(); }

Compilation message (stderr)

numbers.cpp: In function 'int main()':
numbers.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...