Salesforce Workflow ConfigurationGiven a Salesforc...

생성일: 2026년 1월 23일

답변에 사용된 모델 GPT-5.2 Thinking by Chat01

질문

Salesforce Workflow ConfigurationGiven a Salesforce workflow configuration string config consisting of digits (0-9) and placeholders (?), determine the number of ways the placeholders can be replaced with digits (0-9) such that no two adjacent workflow steps (digits) are the same.Note: Since the answer can be very large, return the answer modulo (109+7)(10^9 + 7).ExampleGiven the workflow configuration string config = "1?3?":The first placeholder (?) can be replaced with 8 possible digits: {2, 4, 5, 6, 7, 8, 9, 0} (all digits except 1 and 3).The second placeholder can be replaced with 9 possible digits: {1, 2, 4, 5, 6, 7, 8, 9, 0} (all digits except 3).This results in a total of 72 possible configurations.Since the total number of configurations may be very large, return the result modulo (109+7)(10^9 + 7).Function DescriptionComplete the function getWorkflowReplacements in the editor below.getWorkflowReplacements has the following parameter(s):string config: The workflow configuration string consisting of digits (0-9) and placeholders (?).Returnint: The total number of valid configurations modulo (109+7)(10^9 + 7).Constraints1config1051 \le |config| \le 10^5The string config consists of digits from '0' to '9' and '?' only.Code Editor (C++14)C++#include <bits/stdc++.h>

/*

  • Complete the 'getWorkflowReplacements' function below.
  • The function is expected to return an INTEGER.
  • The function accepts STRING config as parameter.
    */

int getWorkflowReplacements(string config) {

}

int main() ... give me cpp code

사고

Designing a DP solution for digit assignment with constraints

I need to provide a dynamic programming approach where we count the number of assignments to '?' digits while keeping adjacent digits different. The problem is constrained by n up to 100,000, and I’ll calculate the result modulo 1e9+7. I'll use aggregated formulas to reduce the complexity to O(n). Each position depends on the previous one, and I’ll precompute totals to ensure efficiency. The result will be found by summing up the last state's possibilities.

Finalizing edge cases and C++ function design

For the edge case with n=1, I need to count the possible digits, considering constraints. If the digit is fixed, it matches, otherwise, it can be anything from 0-9. The DP should handle the adjacent constraint without needing to compare fixed digits. I'll craft the function and minimal C++ program, ensuring modular arithmetic safety. The solution will handle up to 1e5 digits efficiently, and I’ll use long long for large values to avoid overflow in the calculations.

Thought for 24s

답변

cpp
#include <bits/stdc++.h> using namespace std; static const long long MOD = 1000000007LL; int getWorkflowReplacements(string config) { const int DIG = 10; int n = (int)config.size(); vector<long long> prev(DIG, 0), cur(DIG, 0); // Initialize for position 0 if (config[0] == '?') { for (int d = 0; d < DIG; d++) prev[d] = 1; } else { prev[config[0] - '0'] = 1; } for (int i = 1; i < n; i++) { fill(cur.begin(), cur.end(), 0); long long total = 0; for (int d = 0; d < DIG; d++) { total += prev[d]; if (total >= MOD) total -= MOD; } if (config[i] == '?') { for (int d = 0; d < DIG; d++) { long long val = total - prev[d]; if (val < 0) val += MOD; cur[d] = val; } } else { int k = config[i] - '0'; long long val = total - prev[k]; if (val < 0) val += MOD; cur[k] = val; } prev.swap(cur); } long long ans = 0; for (int d = 0; d < DIG; d++) { ans += prev[d]; if (ans >= MOD) ans -= MOD; } return (int)ans; } // If you need a runnable program: int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string config; cin >> config; cout << getWorkflowReplacements(config) << "\n"; return 0; }

이 Q&A 공유하기