답안 #780028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780028 2023-07-12T05:49:44 Z cig32 Kamenčići (COCI21_kamencici) C++17
70 / 70
18 ms 27480 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 1e6 + 10;
const int MOD = 998244353;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }

bool dp[351][351][351];
bool vis[351][351][351];
int n,k;
char c[351];
int ps[351];
bool dpf(int l, int r, int x) {
  if(x >= k) return dp[l][r][x] = 0;
  if(vis[l][r][x]) return dp[l][r][x];
  vis[l][r][x] = 1;
  int y = ps[n] - ps[r] + ps[l-1] - x;
  if(x+(c[l]=='C') < k && dpf(l+1,r,y) == 0) return dp[l][r][x] = 1;
  if(x+(c[r]=='C') < k && dpf(l,r-1,y) == 0) return dp[l][r][x] = 1;
  return dp[l][r][x] = 0;
}
void solve(int tc){
  cin >> n >> k;
  for(int i=1; i<=n; i++) cin >> c[i];
  for(int i=1; i<=n; i++) ps[i] = ps[i-1] + (c[i] == 'C');
  cout << (dpf(1, n, 0) ? "DA\n" : "NE\n");
}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 18 ms 27480 KB Output is correct
15 Correct 7 ms 10452 KB Output is correct
16 Correct 17 ms 25300 KB Output is correct
17 Correct 16 ms 26700 KB Output is correct
18 Correct 7 ms 12500 KB Output is correct