답안 #552395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552395 2022-04-23T05:44:41 Z LeSonnn Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 596 KB
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
const int maxN=1e6+68;
long long dp[68][2][2][12][12];
string a,b;
long long Cal(long long x,bool kta,bool ktb,long long last,long long prelast,bool check)
{
    if(x>=a.size()) return 1;
    long long& tg=dp[x][kta][ktb][last][prelast];
    if(tg!=-1) return tg;
    tg=0;
    long long l=0,r=9;
    if(kta) l=a[x]-'0';
    if(ktb) r=b[x]-'0';
    FOR(i,l,r)
    {
        bool checka=kta&&(i==l);
        bool checkb=ktb&&(i==r);
        if(!check&&i==0)
        {
            tg+=Cal(x+1,checka,checkb,last,prelast,check);
        }
        else if(i!=last&&i!=prelast)
        {
            tg+=Cal(x+1,checka,checkb,i,last,true);
        }
    }
    return tg;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    if(fopen("PFNUM.inp","r"))
    {
        freopen("PFNUM.inp","r",stdin);
        freopen("PFNUM.out","w",stdout);
    }
    cin>>a>>b;
    while(a.size()<b.size()) a='0'+a;
    while(a.size()>b.size()) b='0'+b;
    memset(dp,-1,sizeof(dp));
    cout<<Cal(0,true,true,10,10,false);
}

Compilation message

numbers.cpp: In function 'long long int Cal(long long int, bool, bool, long long int, long long int, bool)':
numbers.cpp:9:9: 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]
    9 |     if(x>=a.size()) return 1;
      |        ~^~~~~~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("PFNUM.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("PFNUM.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 584 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 584 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 584 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 584 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 588 KB Output is correct