File tree Expand file tree Collapse file tree 3 files changed +130
-0
lines changed
Codeforces/After Placement Expand file tree Collapse file tree 3 files changed +130
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ #include < bits/stdc++.h>
6+ using namespace std ;
7+ typedef long long ll;
8+
9+
10+ int solve (){
11+ string s;
12+ cin>>s;
13+ int n=s.size ();
14+ int ans=1 ;
15+ if (s[0 ]==' ?' ){
16+ ans=9 ;
17+ }
18+ else if (s[0 ]==' 0' ){
19+ cout<<0 <<endl;
20+ return 0 ;
21+ }
22+ for (int i=1 ;i<n;i++){
23+ if (s[i]==' ?' ){
24+ ans*=10 ;
25+ }
26+ }
27+ cout<<ans<<endl;
28+ return 0 ;
29+ }
30+ int main ()
31+ {
32+ int testCase=1 ;
33+ cin>>testCase;
34+ while (testCase--){
35+ solve ();
36+ }
37+ return 0 ;
38+ }
Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ #include < bits/stdc++.h>
6+ using namespace std ;
7+ typedef long long ll;
8+
9+
10+ int solve (){
11+ int n;
12+ cin >> n;
13+ vector<int > a (n), b (n);
14+ for (auto &i : a){
15+ cin >> i;
16+ }
17+ for (auto &i : b){
18+ cin >> i;
19+ }
20+ int l = 0 , r = n - 1 ;
21+
22+ while (a[l] == b[l]){
23+ l++;
24+ }
25+ while (a[r] == b[r]){
26+ r--;
27+ }
28+ while (l > 0 && b[l] >= b[l - 1 ]){
29+ l--;
30+ }
31+ while (r < n - 1 && b[r] <= b[r + 1 ]){
32+ r++;
33+ }
34+
35+ cout << l + 1 << " " << r + 1 << endl;
36+ return 0 ;
37+ }
38+ int main ()
39+ {
40+ int testCase=1 ;
41+ cin>>testCase;
42+ while (testCase--){
43+ solve ();
44+ }
45+ return 0 ;
46+ }
Original file line number Diff line number Diff line change 1+ class Solution
2+ {
3+ public:
4+ long long stringToLongLong (string s)
5+ {
6+ long long num;
7+ istringstream iss (s); // create a stringstream object from string s
8+ iss >> num; // extract the integer from the stringstream
9+ return num;
10+ }
11+
12+ int numberOfArrays (string s, int k)
13+ {
14+ int mod = 1e9 + 7 ;
15+ int n = s.size ();
16+
17+ // dp[i] stores the number of ways to split the substring s[0:i-1] into valid arrays
18+ vector<long long > dp (n + 1 ,0 );
19+
20+ // base case: dp[0] = 1 (empty string)
21+ dp[0 ] = 1 ;
22+
23+ for (int i = 1 ; i <= n; i++)
24+ {
25+ long long num = 0 ;
26+ for (int size=1 ;size<=i && size<=10 ;size++){
27+ string temp=s.substr (i-size,size);
28+ // cout<<"temp is "<<temp<<endl;
29+ num=stringToLongLong (temp);
30+ // cout<<"covering "<<i-1<<" to "<<i-size<<endl;
31+ // cout<<"num is "<<num<<endl;
32+ if (s[i-size]==' 0' ){
33+ continue ;
34+ }
35+ if (num<=k){
36+ dp[i]=(dp[i]+dp[i-size])%mod;
37+ }
38+ else {
39+ break ;
40+ }
41+ }
42+ }
43+
44+ return dp[n];
45+ }
46+ };
You can’t perform that action at this time.
0 commit comments