제출 #63326

#제출 시각아이디문제언어결과실행 시간메모리
63326Bodo171Palindrome-Free Numbers (BOI13_numbers)C++14
1.25 / 100
4 ms740 KiB
#include <iostream> #include <fstream> using namespace std; long long cif[20]; long long dp[20][11][11][2]; int i,j,c1,c2,newc,eq,len; long long val,a,b; long long calc(long long x) { if(x<0) return 0; if(x==0) return 1; int nr=0; cif[0]=10; while(x!=0) cif[++nr]=x%10,x/=10;len=nr; for(i=1;i<=nr/2;i++) swap(cif[i],cif[nr-i+1]); for(i=1;i<cif[1];i++) dp[1][10][i][0]=1; dp[1][10][cif[1]][1]=1; for(i=2;i<=len;i++) for(j=1;j<10;j++) dp[i][10][j][0]=1; for(i=1;i<len;i++) for(c1=0;c1<=10;c1++) for(c2=0;c2<10;c2++) for(eq=0;eq<=1;eq++) { val=dp[i][c1][c2][eq]; if(val) { if(eq) { for(newc=0;newc<cif[i+1];newc++) if(newc!=c1&&newc!=c2) dp[i+1][c2][newc][0]+=val; if(cif[i+1]!=c1&&cif[i+1]!=c2) dp[i+1][c2][cif[i+1]][1]+=val; } else { for(newc=0;newc<10;newc++) if(newc!=c1&&newc!=c2) dp[i+1][c2][newc][0]+=val; } } } long long sum=0; for(i=0;i<=10;i++) for(j=0;j<10;j++) sum+=dp[len][i][j][0]; sum+=dp[len][cif[len-1]][cif[len]][1]; for(i=1;i<=len;i++) for(c1=0;c1<=10;c1++) for(c2=0;c2<=10;c2++) for(eq=0;eq<2;eq++) dp[i][c1][c2][eq]=0; return sum+1;//numaram si 0 } int main() { freopen("data.in","r",stdin); cin>>a>>b; cout<<calc(b)-calc(a-1)<<'\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

numbers.cpp: In function 'long long int calc(long long int)':
numbers.cpp:14:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
     while(x!=0)
     ^~~~~
numbers.cpp:15:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
         cif[++nr]=x%10,x/=10;len=nr;
                              ^~~
numbers.cpp: In function 'int main()':
numbers.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("data.in","r",stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...