답안 #653990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653990 2022-10-29T08:59:14 Z keitherrrr Palindrome-Free Numbers (BOI13_numbers) C++17
0 / 100
1 ms 352 KB
   #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();    
    cout<<n<<'\n'; 
    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

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:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | 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++)
......
   54 |     FOR(i,2,a.size()) if(a[i]==a[i-2]||a[i]==a[i-1]) {g=1; break;}
      |         ~~~~~~~~~~~~                                 
numbers.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(i,2,a.size()) if(a[i]==a[i-2]||a[i]==a[i-1]) {g=1; break;}
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Incorrect 1 ms 352 KB Output isn't correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Incorrect 0 ms 340 KB Output isn't correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 0 ms 352 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
21 Incorrect 1 ms 240 KB Output isn't correct
22 Incorrect 1 ms 340 KB Output isn't correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Incorrect 1 ms 340 KB Output isn't correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 1 ms 340 KB Output isn't correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Incorrect 1 ms 340 KB Output isn't correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Incorrect 1 ms 340 KB Output isn't correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Incorrect 1 ms 340 KB Output isn't correct
35 Incorrect 1 ms 340 KB Output isn't correct
36 Incorrect 1 ms 340 KB Output isn't correct
37 Incorrect 1 ms 340 KB Output isn't correct
38 Incorrect 1 ms 340 KB Output isn't correct
39 Incorrect 1 ms 340 KB Output isn't correct
40 Incorrect 1 ms 340 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Incorrect 1 ms 340 KB Output isn't correct
43 Incorrect 1 ms 340 KB Output isn't correct
44 Incorrect 1 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct