답안 #1120114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1120114 2024-11-28T03:24:09 Z ntdaccode Kamenčići (COCI21_kamencici) C++17
70 / 70
36 ms 27788 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define pb push_back

using namespace std;

typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;

const int M = 1e6 + 10;
const int N = 355;
const int mod = 1e9 + 7;

int n, k;
char ch[N];

bool f[N][N][N], dd[N][N][N];
bool dp(int l,int r,int tt,int a,int b)
{
  if(a == k) return 0;
  if(b == k) return 1;
  if(l > r) return 0;
  bool &ret = f[l][r][a];
  if(dd[l][r][a]) return ret;
  dd[l][r][a] = true;
  if(tt) {
    ret = dp(l + 1,r,1 - tt,a,b + (ch[l] == 'C'));
    if(ret == 1) {
      ret = dp(l,r - 1,1 - tt,a,b + (ch[r] == 'C'));
    }
  }
  else {
    ret = dp(l + 1,r,1 - tt,a + (ch[l] == 'C'),b);
    if(ret == 0) {
      ret = dp(l,r - 1,1 - tt,a + (ch[r] == 'C'),b);
    }
  }
  return ret;

}


int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

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

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

  cin >> n >> k;
  for(int i = 1;i <= n; i++) cin >> ch[i];

  if(dp(1,n,0,0,0) == 1) cout << "DA";
  else cout << "NE";


}


Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 352 KB Output is correct
2 Correct 1 ms 608 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 1 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 352 KB Output is correct
2 Correct 1 ms 608 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 1 ms 608 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 864 KB Output is correct
10 Correct 1 ms 608 KB Output is correct
11 Correct 2 ms 864 KB Output is correct
12 Correct 2 ms 1120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 352 KB Output is correct
2 Correct 1 ms 608 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 1 ms 608 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 864 KB Output is correct
10 Correct 1 ms 608 KB Output is correct
11 Correct 2 ms 864 KB Output is correct
12 Correct 2 ms 1120 KB Output is correct
13 Correct 3 ms 1376 KB Output is correct
14 Correct 36 ms 27788 KB Output is correct
15 Correct 12 ms 10592 KB Output is correct
16 Correct 33 ms 25696 KB Output is correct
17 Correct 25 ms 26976 KB Output is correct
18 Correct 14 ms 12768 KB Output is correct