?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
96348998 |
Practice: ashishnnnnn |
1315B - 16 | C++14 (GCC 6-32) | Memory limit exceeded on test 5 | 280 ms | 262144 KB | 2020-10-22 13:00:47 | 2020-10-22 13:00:47 |
#include <bits/stdc++.h> #define ll long long using namespace std; #define inf 1000000000000000005 int solve(int arr[],int a,int b,int i,int n,string s){ if(i==n-2){ if(s[i]=='A'){ return arr[i] = a; } else{ return arr[i] = b; } } if(s[i]==s[i+1]){ return arr[i]=solve(arr,a,b,i+1,n,s); } else{ if(s[i]=='A'){ return arr[i] = a+solve(arr,a,b,i+1,n,s); } else{ return arr[i] = b+solve(arr,a,b,i+1,n,s); } } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t; cin >> t; while(t--){ int a,b,p; cin >> a>>b>>p; string s; cin >> s; int n = s.size(); int arr[n]; memset(arr,0,sizeof arr); int lol = solve(arr,a,b,0,n,s); int f = 0; int ret ; for(int i=0;i<n-1;i++){ //cout<<arr[i]<<" "; if(arr[i]<=p){ f = 1; ret = i+1; break; } } //cout<<"\n"; if(f==1){ cout<<ret<<"\n"; } else{ cout<<n<<"\n"; } } }
?
?
?
?