| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1290910 | nnhzzz | Kamenčići (COCI21_kamencici) | C++20 | 40 ms | 50436 KiB |
#include <bits/stdc++.h>
using namespace std;
#define BIT(i,j) (((i)>>(j))&1LL)
#define MASK(i) (1LL<<(i))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define ull unsigned long long
#define ll long long
#define ld long double
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define endl "\n"
#define MP make_pair
// #define int ll
//------------------------------------------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
//-----------------------------------------------------------------------------------------------//
const ll LINF = 1e18;
const int INF = 1e9;
const int LOG = 20;
const int MAXN = 352;
const int N = 1e2+3;
const int MOD = 1e9+7;
const int BASE = 1e5;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int OFFSET = 1e3;
//------------------------------------------------------------------------------------------------//
int dp[MAXN][MAXN][MAXN],c[MAXN],pre[MAXN],suf[MAXN];
int k;
int cost(int l, int r){
return pre[l]+suf[r];
}
int calc(int l, int r, int cnt){
if(l>r || cnt>=k) return 2;
if(dp[l][r][cnt]) return dp[l][r][cnt];
int &res = dp[l][r][cnt];
res = 2;
if(cnt+c[l]<k){
int now = cnt+c[l];
if(calc(l+1,r,cost(l,r+1)-now)==2) return res = 1;
}
if(cnt+c[r]<k){
int now = cnt+c[r];
if(calc(l,r-1,cost(l-1,r)-now)==2) return res = 1;
}
return res;
}
void solve(){
int n; cin >> n >> k;
for(int i = 1; i<=n; i++){
char ch; cin >> ch;
c[i] = (ch=='C');
pre[i] = pre[i-1]+c[i];
}
for(int i = n; i>0; i--) suf[i] = suf[i+1]+c[i];
if(calc(1,n,0)==1) cout << "DA";
else cout << "NE";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "test"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
#define task1 "nothing"
if(fopen(task1".inp","r")){
freopen(task1".inp","r",stdin);
freopen(task1".out","w",stdout);
}
int test = 1;
while(test--){
solve();
}
cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
