Submission #238057

# Submission time Handle Problem Language Result Execution time Memory
238057 2020-06-09T20:43:47 Z Sorting Lucky Numbers (RMI19_lucky) C++14
28 / 100
17 ms 2432 KB
#include <bits/stdc++.h>

using namespace std;

const int k_Mod = 1e9 + 7;
const int k_N = 1e5 + 7;

int n, q;
string x;

pair<int, int> dp[k_N][10][2];
int iteration;

int solve(int digits_left, int previous_digit, bool equal, int end){
    if(digits_left == 0)
        return 1;

    auto &[answer, solved] = dp[digits_left][previous_digit][equal];
    if(solved == iteration)
        return answer;

    solved = iteration;
    answer = 0;

    int max_digit = 9;
    if(equal){
        int position = end - digits_left + 1;
        max_digit = x[position] - '0';
    }

    for(int digit = 0; digit <= max_digit; ++digit){
        if(previous_digit == 1 && digit == 3)
            continue;
        bool new_equal = equal ? (digit == max_digit) : false;

        answer += solve(digits_left - 1, digit, new_equal, end);
        answer = (answer >= k_Mod) ? (answer - k_Mod) : answer;
    }

    return answer;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> q;
    cin >> x;

    iteration = 1;
    cout << solve(n, 0, true, n - 1) << "\n";

    for(int i = 0; i < q; ++i){
        int t;
        cin >> t;

        if(t == 1){
            int l, r;
            cin >> l >> r;
            --l, --r;

            cout << solve(r - l + 1, 0, true,  r) << "\n";
        }
        else{
            int position;
            char value;
            cin >> position >> value;
            --position;

            x[position] = value;
            ++iteration;
        }
    }
}

Compilation message

lucky.cpp: In function 'int solve(int, int, bool, int)':
lucky.cpp:18:11: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     auto &[answer, solved] = dp[digits_left][previous_digit][equal];
           ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Incorrect 17 ms 2432 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Incorrect 17 ms 2432 KB Output isn't correct
8 Halted 0 ms 0 KB -