답안 #854003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854003 2023-09-25T19:32:54 Z divad Lucky Numbers (RMI19_lucky) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define EQ 0
#define LE 1
using namespace std;
const int MOD = 1e9+7;
const int NMAX = 1e4+2;
const int SIGMA = 10;
int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
string str;

int countWays(int st, int dr){
    dp[EQ][0][0] = 1;
    for(int i = 1; i <= (dr-st+1); i++){
        int pos = i+st-1;
        for(int dig = 0; dig <= 9; dig++){
            dp[EQ][dig][i] = dp[LE][dig][i] = 0;
            for(int lst = 0; lst <= 9; lst++){
                if(lst == 1 && dig == 3){
                    continue;
                }
                if(dig == str[pos]-'0'){
                    dp[EQ][dig][i] += dp[EQ][lst][i-1];
                }
                if(dig <  str[pos]-'0'){
                    dp[LE][dig][i] += dp[EQ][lst][i-1];
                }
                dp[LE][dig][i] += dp[LE][lst][i-1];

                dp[EQ][dig][i] %= MOD;
                dp[LE][dig][i] %= MOD;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= 9; i++){
        ans += dp[LE][i][(dr-st+1)] + dp[EQ][i][(dr-st+1)];
        ans %= MOD;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> q;
    cin >> str;
    str = "$"+str;
    cout << countWays(1, n) << "\n";
    while(q--){
        cin >> t;
        if(t == 1){
            cin >> l >> r;
            cout << countWays(l, r) << "\n";
        }else{
            cin >> pos >> val;
            str[pos] = (val+'0');
        }
    }
    return 0;
}
#include <bits/stdc++.h>
#define EQ 0
#define LE 1
using namespace std;
const int MOD = 1e9+7;
const int NMAX = 1e4+2;
const int SIGMA = 10;
int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
string str;

int countWays(int st, int dr){
    dp[EQ][0][0] = 1;
    for(int i = 1; i <= (dr-st+1); i++){
        int pos = i+st-1;
        for(int dig = 0; dig <= 9; dig++){
            dp[EQ][dig][i] = dp[LE][dig][i] = 0;
            for(int lst = 0; lst <= 9; lst++){
                if(lst == 1 && dig == 3){
                    continue;
                }
                if(dig == str[pos]-'0'){
                    dp[EQ][dig][i] += dp[EQ][lst][i-1];
                }
                if(dig <  str[pos]-'0'){
                    dp[LE][dig][i] += dp[EQ][lst][i-1];
                }
                dp[LE][dig][i] += dp[LE][lst][i-1];

                dp[EQ][dig][i] %= MOD;
                dp[LE][dig][i] %= MOD;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= 9; i++){
        ans += dp[LE][i][(dr-st+1)] + dp[EQ][i][(dr-st+1)];
        ans %= MOD;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> q;
    cin >> str;
    str = "$"+str;
    cout << countWays(1, n) << "\n";
    while(q--){
        cin >> t;
        if(t == 1){
            cin >> l >> r;
            cout << countWays(l, r) << "\n";
        }else{
            cin >> pos >> val;
            str[pos] = (val+'0');
        }
    }
    return 0;
}

Compilation message

lucky.cpp:66:11: error: redefinition of 'const int MOD'
   66 | const int MOD = 1e9+7;
      |           ^~~
lucky.cpp:5:11: note: 'const int MOD' previously defined here
    5 | const int MOD = 1e9+7;
      |           ^~~
lucky.cpp:67:11: error: redefinition of 'const int NMAX'
   67 | const int NMAX = 1e4+2;
      |           ^~~~
lucky.cpp:6:11: note: 'const int NMAX' previously defined here
    6 | const int NMAX = 1e4+2;
      |           ^~~~
lucky.cpp:68:11: error: redefinition of 'const int SIGMA'
   68 | const int SIGMA = 10;
      |           ^~~~~
lucky.cpp:7:11: note: 'const int SIGMA' previously defined here
    7 | const int SIGMA = 10;
      |           ^~~~~
lucky.cpp:69:5: error: redefinition of 'int n'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |     ^
lucky.cpp:8:5: note: 'int n' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |     ^
lucky.cpp:69:7: error: redefinition of 'int q'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |       ^
lucky.cpp:8:7: note: 'int q' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |       ^
lucky.cpp:69:9: error: redefinition of 'int t'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |         ^
lucky.cpp:8:9: note: 'int t' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |         ^
lucky.cpp:69:11: error: redefinition of 'int l'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |           ^
lucky.cpp:8:11: note: 'int l' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |           ^
lucky.cpp:69:13: error: redefinition of 'int r'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |             ^
lucky.cpp:8:13: note: 'int r' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |             ^
lucky.cpp:69:15: error: redefinition of 'int pos'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |               ^~~
lucky.cpp:8:15: note: 'int pos' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |               ^~~
lucky.cpp:69:19: error: redefinition of 'int val'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |                   ^~~
lucky.cpp:8:19: note: 'int val' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |                   ^~~
lucky.cpp:69:23: error: redefinition of 'int dp [2][10][10002]'
   69 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |                       ^~
lucky.cpp:8:23: note: 'int dp [2][10][10002]' previously declared here
    8 | int n,q,t,l,r,pos,val,dp[2][SIGMA][NMAX];
      |                       ^~
lucky.cpp:70:8: error: redefinition of 'std::string str'
   70 | string str;
      |        ^~~
lucky.cpp:9:8: note: 'std::string str' previously declared here
    9 | string str;
      |        ^~~
lucky.cpp:72:5: error: redefinition of 'int countWays(int, int)'
   72 | int countWays(int st, int dr){
      |     ^~~~~~~~~
lucky.cpp:11:5: note: 'int countWays(int, int)' previously defined here
   11 | int countWays(int st, int dr){
      |     ^~~~~~~~~
lucky.cpp:103:5: error: redefinition of 'int main()'
  103 | int main()
      |     ^~~~
lucky.cpp:42:5: note: 'int main()' previously defined here
   42 | int main()
      |     ^~~~