Submission #861733

# Submission time Handle Problem Language Result Execution time Memory
861733 2023-10-16T20:59:50 Z Ahmed_Solyman Kamenčići (COCI21_kamencici) C++14
0 / 70
247 ms 508536 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"DA":"NE")<<endl;
}
const int N=400;
int dp[N][N][N];
int n,k,ps[N],ss[N];
string s;
bool solve(int i,int j,int cnt){
	if(cnt>=k){
		return 0;
	}
	if(ps[i]+ss[j]-cnt>=k){
		return 1;
	}
	int &ret=dp[i][j][cnt];
	if(~ret)return ret;
	int turn=((i+j)%2)==((n-1)%2);
	if(turn==1){
		return ret=(solve(i+1,j,cnt+(s[i]=='C'))|solve(i,j-1,cnt+(s[j]=='C')));
	}
	else{
		return ret=!(((!solve(i+1,j,cnt))|(!solve(i,j-1,cnt))));
	}
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
    fast
    fil(dp,-1);
    cin>>n>>k>>s;
    for(int i=1;i<n;i++)ps[i]=ps[i-1]+(s[i-1]=='C');
    for(int i=n-2;i;i--)ss[i]=ss[i+1]+(s[i+1]=='C');
    person_bool(solve(0,n-1,0));
    return 0;
}

Compilation message

Main.cpp: In function 'bool solve(int, int, int)':
Main.cpp:53:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   53 |   return ret=(solve(i+1,j,cnt+(s[i]=='C'))|solve(i,j-1,cnt+(s[j]=='C')));
      |          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:56:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   56 |   return ret=!(((!solve(i+1,j,cnt))|(!solve(i,j-1,cnt))));
      |          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 508536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 508536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 508536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -