답안 #63326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63326 2018-08-01T12:30:35 Z Bodo171 Palindrome-Free Numbers (BOI13_numbers) C++14
1.25 / 100
4 ms 740 KB
#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;
}

Compilation message

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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Incorrect 3 ms 356 KB Output isn't correct
3 Incorrect 4 ms 520 KB Output isn't correct
4 Incorrect 3 ms 520 KB Output isn't correct
5 Incorrect 2 ms 520 KB Output isn't correct
6 Incorrect 3 ms 556 KB Output isn't correct
7 Incorrect 2 ms 556 KB Output isn't correct
8 Incorrect 2 ms 556 KB Output isn't correct
9 Incorrect 3 ms 608 KB Output isn't correct
10 Incorrect 2 ms 616 KB Output isn't correct
11 Incorrect 3 ms 624 KB Output isn't correct
12 Incorrect 2 ms 636 KB Output isn't correct
13 Incorrect 3 ms 648 KB Output isn't correct
14 Incorrect 3 ms 648 KB Output isn't correct
15 Incorrect 2 ms 648 KB Output isn't correct
16 Incorrect 3 ms 664 KB Output isn't correct
17 Incorrect 2 ms 664 KB Output isn't correct
18 Correct 3 ms 664 KB Output is correct
19 Incorrect 3 ms 664 KB Output isn't correct
20 Incorrect 3 ms 664 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 664 KB Output isn't correct
2 Incorrect 2 ms 664 KB Output isn't correct
3 Incorrect 4 ms 664 KB Output isn't correct
4 Incorrect 3 ms 664 KB Output isn't correct
5 Incorrect 3 ms 664 KB Output isn't correct
6 Incorrect 3 ms 664 KB Output isn't correct
7 Incorrect 3 ms 664 KB Output isn't correct
8 Incorrect 3 ms 664 KB Output isn't correct
9 Incorrect 3 ms 664 KB Output isn't correct
10 Incorrect 2 ms 684 KB Output isn't correct
11 Incorrect 2 ms 684 KB Output isn't correct
12 Incorrect 2 ms 684 KB Output isn't correct
13 Incorrect 3 ms 684 KB Output isn't correct
14 Incorrect 3 ms 728 KB Output isn't correct
15 Incorrect 2 ms 728 KB Output isn't correct
16 Incorrect 2 ms 728 KB Output isn't correct
17 Incorrect 2 ms 728 KB Output isn't correct
18 Incorrect 2 ms 728 KB Output isn't correct
19 Incorrect 2 ms 728 KB Output isn't correct
20 Incorrect 2 ms 728 KB Output isn't correct
21 Incorrect 3 ms 728 KB Output isn't correct
22 Incorrect 3 ms 728 KB Output isn't correct
23 Incorrect 2 ms 728 KB Output isn't correct
24 Incorrect 2 ms 728 KB Output isn't correct
25 Incorrect 2 ms 728 KB Output isn't correct
26 Incorrect 2 ms 728 KB Output isn't correct
27 Incorrect 3 ms 728 KB Output isn't correct
28 Incorrect 2 ms 728 KB Output isn't correct
29 Incorrect 3 ms 728 KB Output isn't correct
30 Incorrect 2 ms 728 KB Output isn't correct
31 Incorrect 3 ms 728 KB Output isn't correct
32 Incorrect 2 ms 728 KB Output isn't correct
33 Incorrect 2 ms 728 KB Output isn't correct
34 Incorrect 2 ms 728 KB Output isn't correct
35 Incorrect 3 ms 728 KB Output isn't correct
36 Incorrect 2 ms 728 KB Output isn't correct
37 Incorrect 3 ms 728 KB Output isn't correct
38 Incorrect 2 ms 728 KB Output isn't correct
39 Incorrect 3 ms 728 KB Output isn't correct
40 Incorrect 3 ms 728 KB Output isn't correct
41 Incorrect 2 ms 728 KB Output isn't correct
42 Incorrect 2 ms 728 KB Output isn't correct
43 Incorrect 2 ms 740 KB Output isn't correct
44 Incorrect 2 ms 740 KB Output isn't correct
45 Incorrect 2 ms 740 KB Output isn't correct