제출 #1351519

#제출 시각아이디문제언어결과실행 시간메모리
1351519thnhannKamenčići (COCI21_kamencici)C++20
70 / 70
154 ms350616 KiB
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define el cout<<'\n'
#define int long long
#define miuu ""

const ll mod=1e9+7;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const int nmax=5e5;
const int inf =2e9;

void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}

using namespace std;

mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r)
{
    return uniform_int_distribution<int>(l, r) (rd);
}

int n,k;
int dp[355][355][355];
int pre[355];
string s;


int can_win(int l, int r, int uk){
    int& res = dp[l][r][uk];
    if(res == -1){
        int total_red = pre[n];
        int red_left = pre[r];
        if(l) red_left -= pre[l-1];
        int other_red = total_red - red_left - uk;
        if(uk>=k){
            res = 0;
        }else if(other_red>=k){
            res = 1;
        }else{
            if(!can_win(l+1, r, other_red) || !can_win(l, r-1, other_red)){
                res = 1;
            }else{
                res = 0;
            }
        }
    }
    return res;
}
signed main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);

   if(fopen(miuu".inp","r"))
    {
       freopen(miuu".inp","r",stdin);
       freopen(miuu".out","w",stdout);
    }

    cin >> n >> k;
    cin >> s;
    s = " " + s;
    for(int i=1;i<=n;i++)
        pre[i] = pre[i - 1] + (s[i] == 'C');
    memset(dp,-1,sizeof dp);
    int ans = can_win(1,n,0);
    if(ans)
        cout << "DA";
    else cout << "NE";
}
//  "Can i get a kiss? And can u make it last forever?"

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:69:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |        freopen(miuu".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:70:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |        freopen(miuu".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...