Submission #742117

# Submission time Handle Problem Language Result Execution time Memory
742117 2023-05-15T16:05:01 Z Ahmed57 Kamenčići (COCI21_kamencici) C++17
70 / 70
173 ms 338892 KB
#include <bits/stdc++.h>

using namespace std;
int dp[351][351][351][2];
string s;int k,n;
int pref[351],suff[355];
long long solve(int i,int j,int took,int turn){
    if(took>=k)return 1;
    if((i==0?0:pref[i-1])+(suff[j+1])-took>=k)return 0;
    if(dp[i][j][took][turn]!=-1)return dp[i][j][took][turn];
    if(turn==0){
        return dp[i][j][took][turn] = min(solve(i+1,j,took+(s[i]=='C'?1:0),!turn),solve(i,j-1,took+(s[j]=='C'?1:0),!turn));
    }else{
        return dp[i][j][took][turn] = max(solve(i+1,j,took,!turn),solve(i,j-1,took,!turn));
    }
}
signed main(){
    memset(dp,-1,sizeof dp);
    cin>>n>>k;
    cin>>s;
    for(int i = 0;i<s.size();i++){
        pref[i] = (s[i]=='C'?1:0);
        if(i)pref[i]+=pref[i-1];
    }
    for(int i = s.size()-1;i>=0;i--){
        suff[i] = (s[i]=='C'?1:0);
        if(i<s.size()-1)suff[i]+=suff[i+1];
    }
    cout<<(solve(0,s.size()-1,0,0)==0?"DA":"NE")<<endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i = 0;i<s.size();i++){
      |                   ~^~~~~~~~~
Main.cpp:27:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if(i<s.size()-1)suff[i]+=suff[i+1];
      |            ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 140 ms 338732 KB Output is correct
2 Correct 135 ms 338780 KB Output is correct
3 Correct 164 ms 338708 KB Output is correct
4 Correct 140 ms 338756 KB Output is correct
5 Correct 146 ms 338684 KB Output is correct
6 Correct 140 ms 338732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 338732 KB Output is correct
2 Correct 135 ms 338780 KB Output is correct
3 Correct 164 ms 338708 KB Output is correct
4 Correct 140 ms 338756 KB Output is correct
5 Correct 146 ms 338684 KB Output is correct
6 Correct 140 ms 338732 KB Output is correct
7 Correct 135 ms 338780 KB Output is correct
8 Correct 139 ms 338788 KB Output is correct
9 Correct 133 ms 338680 KB Output is correct
10 Correct 136 ms 338724 KB Output is correct
11 Correct 133 ms 338740 KB Output is correct
12 Correct 135 ms 338708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 338732 KB Output is correct
2 Correct 135 ms 338780 KB Output is correct
3 Correct 164 ms 338708 KB Output is correct
4 Correct 140 ms 338756 KB Output is correct
5 Correct 146 ms 338684 KB Output is correct
6 Correct 140 ms 338732 KB Output is correct
7 Correct 135 ms 338780 KB Output is correct
8 Correct 139 ms 338788 KB Output is correct
9 Correct 133 ms 338680 KB Output is correct
10 Correct 136 ms 338724 KB Output is correct
11 Correct 133 ms 338740 KB Output is correct
12 Correct 135 ms 338708 KB Output is correct
13 Correct 138 ms 338704 KB Output is correct
14 Correct 173 ms 338712 KB Output is correct
15 Correct 144 ms 338688 KB Output is correct
16 Correct 166 ms 338892 KB Output is correct
17 Correct 157 ms 338820 KB Output is correct
18 Correct 148 ms 338800 KB Output is correct