답안 #874570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874570 2023-11-17T10:05:07 Z ngjabach Kamenčići (COCI21_kamencici) C++14
70 / 70
55 ms 175476 KB
// NgJaBach: Forever Meadow <3

#include<bits/stdc++.h>

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef unsigned long long ull;
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define bend(a) a.begin(),a.end()
#define rev(x) reverse(bend(x))
#define mset(a) memset(a, 0, sizeof(a))
#define fi first
#define se second
#define gcd __gcd
#define getl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define endl '\n'
const int N=355,M=1000000007;
const ll INF=1e18+7;
int dp[N][N][N],pref[N],n,k;
string s;
int can_win(int L,int R,int reds){
    int &res=dp[L][R][reds];
//    cout<<L<<" "<<R<<" "<<reds<<endl;
    if(res==-1){
        int other_reds=pref[n]-pref[R]+pref[L-1]-reds;
        if(reds>=k) res=0;
        else if(other_reds>=k) res=1;
        else{
            if(!can_win(L+1,R,other_reds) or !can_win(L,R-1,other_reds)) res=1;
            else res=0;
        }
    }
        
    return res;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
//    freopen(".inp","r",stdin);
//    freopen(".out","w",stdout);
    cin>>n>>k;
    cin>>s; s="$"+s;
    pref[0]=0;
    for(int i=1;i<=n;++i) pref[i]=pref[i-1]+(s[i]=='C');
    for(int i=0;i<N;++i) for(int j=0;j<N;++j) for(int d=0;d<N;++d) dp[i][j][d]=-1;
    if(can_win(1,n,0)) cout<<"DA";
    else cout<<"NE";
    return 0;
}
/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 175440 KB Output is correct
2 Correct 50 ms 175440 KB Output is correct
3 Correct 40 ms 175392 KB Output is correct
4 Correct 37 ms 175312 KB Output is correct
5 Correct 36 ms 175440 KB Output is correct
6 Correct 37 ms 175440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 175440 KB Output is correct
2 Correct 50 ms 175440 KB Output is correct
3 Correct 40 ms 175392 KB Output is correct
4 Correct 37 ms 175312 KB Output is correct
5 Correct 36 ms 175440 KB Output is correct
6 Correct 37 ms 175440 KB Output is correct
7 Correct 37 ms 175476 KB Output is correct
8 Correct 35 ms 175444 KB Output is correct
9 Correct 31 ms 175444 KB Output is correct
10 Correct 26 ms 175448 KB Output is correct
11 Correct 28 ms 175448 KB Output is correct
12 Correct 26 ms 175440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 175440 KB Output is correct
2 Correct 50 ms 175440 KB Output is correct
3 Correct 40 ms 175392 KB Output is correct
4 Correct 37 ms 175312 KB Output is correct
5 Correct 36 ms 175440 KB Output is correct
6 Correct 37 ms 175440 KB Output is correct
7 Correct 37 ms 175476 KB Output is correct
8 Correct 35 ms 175444 KB Output is correct
9 Correct 31 ms 175444 KB Output is correct
10 Correct 26 ms 175448 KB Output is correct
11 Correct 28 ms 175448 KB Output is correct
12 Correct 26 ms 175440 KB Output is correct
13 Correct 25 ms 175440 KB Output is correct
14 Correct 34 ms 175444 KB Output is correct
15 Correct 27 ms 175440 KB Output is correct
16 Correct 34 ms 175440 KB Output is correct
17 Correct 30 ms 175444 KB Output is correct
18 Correct 27 ms 175440 KB Output is correct