제출 #579928

#제출 시각아이디문제언어결과실행 시간메모리
579928birthdaycakePalindrome-Free Numbers (BOI13_numbers)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #define int long long #define boost ios_base::sync_with_stdio(false), cin.tie(NULL); #define mod 1000000007 using namespace std; string a,b; int n; int dp[20][10][10][2][3]; // n1 -> i - 1, n2 -> i - 2 int solve(int i, int n1, int n2, int tag, int z){ if(i == n) return 1; if(dp[i][n1][n2][tag][z] != -1) return dp[i][n1][n2][tag][z]; dp[i][n1][n2][tag][z] = 0; if(tag){ if(z == 0){ for(int j = 0; j <= 9; j++){ if(j == 0){ dp[i][n1][n2][tag][z] += solve(i + 1, n2, n1, tag, 0); continue; } dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, tag, 1); } } else if(z == 1){ for(int j = 0; j <= 9; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, tag, 2); } }else{ for(int j = 0; j <= 9; j++){ if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, tag, 2); } } }else{ if(z == 0){ int x = b[i] - '0'; dp[i][n1][n2][tag][z] += solve(i + 1, n1, n2, 1, 0); for(int j = 1; j < x; j++){ dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, 1, 1); } dp[i][n1][n2][tag][z] += solve(i + 1, x, n1, tag, 1); } else if(z == 1){ int x = b[i] - '0'; for(int j = 0; j < x; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, 1, 2); } if(x != n1) dp[i][n1][n2][tag][z] += solve(i + 1, x, n1, tag, 2); }else{ int x = b[i] - '0'; for(int j = 0; j < x; j++){ //cout << n2 << ' ' << n1 << ' ' << j << endl; if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, 1, 2); } if(x != n1 && x != n2) dp[i][n1][n2][tag][z] += solve(i + 1, x, n1, tag, 2); } } return dp[i][n1][n2][tag][z]; } int solve2(int i, int n1, int n2, int tag, int z){ if(i == n) return 1; if(dp[i][n1][n2][tag][z] != -1) return dp[i][n1][n2][tag][z]; dp[i][n1][n2][tag][z] = 0; if(tag){ if(z == 0){ for(int j = 0; j <= 9; j++){ if(j == 0){ dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 0); continue; } dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 1); } } else if(z == 1){ for(int j = 0; j <= 9; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 2); } }else{ for(int j = 0; j <= 9; j++){ if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 2); } } }else{ if(z == 0){ int x = a[i] - '0'; dp[i][n1][n2][tag][z] += solve2(i + 1, n1, n2, 1, 0); for(int j = 1; j < x; j++){ dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, 1, 1); } dp[i][n1][n2][tag][z] += solve2(i + 1, x, n1, tag, 1); } else if(z == 1){ int x = a[i] - '0'; for(int j = 0; j < x; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, 1, 2); } if(x != n1) dp[i][n1][n2][tag][z] += solve2(i + 1, x, n1, tag, 2); }else{ int x = a[i] - '0'; for(int j = 0; j < x; j++){ if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, 1, 2); } if(x != n1 && x != n2) dp[i][n1][n2][tag][z] += solve2(i + 1, x, n1, tag, 2); } } return dp[i][n1][n2][tag][z]; } signed main(){ boost; cin >> a >> b; n = b.size(); for(int i = 0; i < 20; i++){ for(int j = 0; j <= 9; j++){ for(int k = 0; k <= 9; k++){ for(int l = 0; l < 2; l++){ for(int z = 0; z < 3; z++){ dp[i][j][k][l][z] = -1; } } } } } int ans = solve(0,0,0,0,0); n = a.size(); for(int i = 0; i < 20; i++){ for(int j = 0; j <= 9; j++){ for(int k = 0; k <= 9; k++){ for(int l = 0; l < 2; l++){ for(int z = 0; z < 3; z++){ dp[i][j][k][l][z] = -1; } } } } } ans -= solve2(0,0,0,0,0); int good = 1; for(int i = 0; i < n; i++){ if(i - 1 >= 0){ if(a[i] == a[i - 1]) good = 0; } if(i - 2 >= 0){ if(a[i] == a[i - 2]) good = 0; } } if(a == "0" && b == "0"){ cout << 1; return 0; } if(a == "0") good++; cout << ans + good; return 0; } #include<bits/stdc++.h> #define int long long #define boost ios_base::sync_with_stdio(false), cin.tie(NULL); #define mod 1000000007 using namespace std; string a,b; int n; int dp[20][10][10][2][3]; // n1 -> i - 1, n2 -> i - 2 int solve(int i, int n1, int n2, int tag, int z){ if(i == n) return 1; if(dp[i][n1][n2][tag][z] != -1) return dp[i][n1][n2][tag][z]; dp[i][n1][n2][tag][z] = 0; if(tag){ if(z == 0){ for(int j = 0; j <= 9; j++){ if(j == 0){ dp[i][n1][n2][tag][z] += solve(i + 1, n2, n1, tag, 0); continue; } dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, tag, 1); } } else if(z == 1){ for(int j = 0; j <= 9; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, tag, 2); } }else{ for(int j = 0; j <= 9; j++){ if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, tag, 2); } } }else{ if(z == 0){ int x = b[i] - '0'; dp[i][n1][n2][tag][z] += solve(i + 1, n1, n2, 1, 0); for(int j = 1; j < x; j++){ dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, 1, 1); } dp[i][n1][n2][tag][z] += solve(i + 1, x, n1, tag, 1); } else if(z == 1){ int x = b[i] - '0'; for(int j = 0; j < x; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, 1, 2); } if(x != n1) dp[i][n1][n2][tag][z] += solve(i + 1, x, n1, tag, 2); }else{ int x = b[i] - '0'; for(int j = 0; j < x; j++){ //cout << n2 << ' ' << n1 << ' ' << j << endl; if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve(i + 1, j, n1, 1, 2); } if(x != n1 && x != n2) dp[i][n1][n2][tag][z] += solve(i + 1, x, n1, tag, 2); } } return dp[i][n1][n2][tag][z]; } int solve2(int i, int n1, int n2, int tag, int z){ if(i == n) return 1; if(dp[i][n1][n2][tag][z] != -1) return dp[i][n1][n2][tag][z]; dp[i][n1][n2][tag][z] = 0; if(tag){ if(z == 0){ for(int j = 0; j <= 9; j++){ if(j == 0){ dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 0); continue; } dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 1); } } else if(z == 1){ for(int j = 0; j <= 9; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 2); } }else{ for(int j = 0; j <= 9; j++){ if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, tag, 2); } } }else{ if(z == 0){ int x = a[i] - '0'; dp[i][n1][n2][tag][z] += solve2(i + 1, n1, n2, 1, 0); for(int j = 1; j < x; j++){ dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, 1, 1); } dp[i][n1][n2][tag][z] += solve2(i + 1, x, n1, tag, 1); } else if(z == 1){ int x = a[i] - '0'; for(int j = 0; j < x; j++){ if(j != n1) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, 1, 2); } if(x != n1) dp[i][n1][n2][tag][z] += solve2(i + 1, x, n1, tag, 2); }else{ int x = a[i] - '0'; for(int j = 0; j < x; j++){ if(j != n1 && j != n2) dp[i][n1][n2][tag][z] += solve2(i + 1, j, n1, 1, 2); } if(x != n1 && x != n2) dp[i][n1][n2][tag][z] += solve2(i + 1, x, n1, tag, 2); } } return dp[i][n1][n2][tag][z]; } signed main(){ boost; cin >> a >> b; n = b.size(); for(int i = 0; i < 20; i++){ for(int j = 0; j <= 9; j++){ for(int k = 0; k <= 9; k++){ for(int l = 0; l < 2; l++){ for(int z = 0; z < 3; z++){ dp[i][j][k][l][z] = -1; } } } } } int ans = solve(0,0,0,0,0); n = a.size(); for(int i = 0; i < 20; i++){ for(int j = 0; j <= 9; j++){ for(int k = 0; k <= 9; k++){ for(int l = 0; l < 2; l++){ for(int z = 0; z < 3; z++){ dp[i][j][k][l][z] = -1; } } } } } ans -= solve2(0,0,0,0,0); int good = 1; for(int i = 0; i < n; i++){ if(i - 1 >= 0){ if(a[i] == a[i - 1]) good = 0; } if(i - 2 >= 0){ if(a[i] == a[i - 2]) good = 0; } } if(a == "0" && b == "0"){ cout << 1; return 0; } if(a == "0") good++; cout << ans + good; return 0; }

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

numbers.cpp:173:8: error: redefinition of 'std::string a'
  173 | string a,b;
      |        ^
numbers.cpp:7:8: note: 'std::string a' previously declared here
    7 | string a,b;
      |        ^
numbers.cpp:173:10: error: redefinition of 'std::string b'
  173 | string a,b;
      |          ^
numbers.cpp:7:10: note: 'std::string b' previously declared here
    7 | string a,b;
      |          ^
numbers.cpp:174:5: error: redefinition of 'long long int n'
  174 | int n;
      |     ^
numbers.cpp:8:5: note: 'long long int n' previously declared here
    8 | int n;
      |     ^
numbers.cpp:175:5: error: redefinition of 'long long int dp [20][10][10][2][3]'
  175 | int dp[20][10][10][2][3];
      |     ^~
numbers.cpp:9:5: note: 'long long int dp [20][10][10][2][3]' previously declared here
    9 | int dp[20][10][10][2][3];
      |     ^~
numbers.cpp:178:5: error: redefinition of 'long long int solve(long long int, long long int, long long int, long long int, long long int)'
  178 | int solve(int i, int n1, int n2, int tag, int z){
      |     ^~~~~
numbers.cpp:12:5: note: 'long long int solve(long long int, long long int, long long int, long long int, long long int)' previously defined here
   12 | int solve(int i, int n1, int n2, int tag, int z){
      |     ^~~~~
numbers.cpp:229:5: error: redefinition of 'long long int solve2(long long int, long long int, long long int, long long int, long long int)'
  229 | int solve2(int i, int n1, int n2, int tag, int z){
      |     ^~~~~~
numbers.cpp:63:5: note: 'long long int solve2(long long int, long long int, long long int, long long int, long long int)' previously defined here
   63 | int solve2(int i, int n1, int n2, int tag, int z){
      |     ^~~~~~
numbers.cpp:282:8: error: redefinition of 'int main()'
  282 | signed main(){
      |        ^~~~
numbers.cpp:116:8: note: 'int main()' previously defined here
  116 | signed main(){
      |        ^~~~